Github action file change not passed to next runner

I am using Github Actions to push my website to Azure Blob Storage. My website talks to an API endpoint whose URI is referenced in a file ‘environment.json’.

In my DEV environment, I talk to a local API, and when the site is deployed, i want it to talk to the PROD API.

To accomplish this, I am using two jobs in my workflow:

JOB 1 (Windows Runner)

  1. Check out the Repository
  2. Use a Powershell script to update mu json file
  3. Commit the change

JOB 2 (Ubuntu)

  1. Check out the Repository
  2. Log in to Azure, upload the files, then logout

The problem is that my Azure blob storage receives the unedited json file.

Every individual step seems to work, but there seems to be an issue with the timing. I have managed to work around the issue by adding a 5 minute Sleep command at the end of JOB 1, but this is a little unsatisfying because I still think I’m missing something.

      - name: Sleep for 300 seconds
        run: Start-Sleep -s 300
        shell: powershell

Given that JOB 2 is supposed to await completion of JOB1, why would it not see the Commit?

Also, I’d be interest to hear if my overall approach is on the right track. I’d actually prefer JOB 1 not to commit the change and just alter the file on the fly, so that my Repository always holds the DEV values.

Any help will be greatly appreciated!

YML without the Sleep command:

name: Blob storage website CI

on:
    push:
        branches: [ main ]

jobs:
  environment:
    runs-on: windows-2019
    steps:
      - name: Check out the repository
        uses: actions/checkout@v2
      - name: Edit the variables for production
        run: |
          $env = Get-Content -Path "environment.json" | ConvertFrom-Json; $env.Environment = "PROD"; $env | ConvertTo-Json | set-content "environment.json"; Get-Content -Path "environment.json"
      - uses: EndBug/add-and-commit@v7
        with:
          default_author: github_actions

  build:
    needs: environment
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: azure/login@v1
      with:
          creds: ${{ secrets.AZURE_CREDENTIALS }}

    - name: Upload to blob storage
      uses: azure/CLI@v1
      with:
        azcliversion: 2.0.72
        inlineScript: |
            az storage blob upload-batch --account-name mailinglistpoc --auth-mode key -d '$web' -s .

  # Azure logout
    - name: logout
      run: |
            az logout
      if: always()

Because actions/checkout without any other parameters retrieves the commit that triggered the workflow run. Theoretically you could pass the commit ID from job 1 to job 2 as an output, but:

In that case you could edit the file and create an archive file that includes the updated version. Upload that as an artifact in job 1. Then job 2 can download the artifact instead of checking out the repository and upload. See also: Storing workflow data as artifacts - GitHub Docs