Checkout commit pushed by previous job

Essentially, I have a workflow configuration where there are three jobs - test, beautify and release. The problem is that the beautify job commits and pushes changes, but the release job is checking out the previous commit since that is the SHA the workflow is running for.

beautify:
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@v2
    - name: Format code
      ...
    - name: Commit and push changes
      uses: github-actions-x/commit@v2.5
      with:
        github-token: ${{ secrets.GITHUB_TOKEN }}
        commit-message: 'style: improve code formatting'
        name: github-actions
        email: action@github.com

release:
  runs-on: ubuntu-latest
  needs: beautify
  steps:
  - uses: actions/checkout@v2
    with:
      fetch-depth: 0
  - name: Release
    ...

I’d like the release job to check out the new commit created by the beautify job, if any. We have temporarily patched this up by checking out master in the release job, however this is less than ideal since it can result in untested code being released if someone pushes to master while the workflow is running.

How can I get the SHA of the commit created in the beautify job, and check it out in the release job?

Hi @alphamycelium , 

To get the SHA of the commit created in the beautify job, you could use " git rev-parse HEAD" to get the head commit SHA, and then set its value as step output value using set-output command. 

In order to get the SHA in release job, you need to set the step level output variable value to the job level output. There is the official document for jobs.<jobs_id>.outputs

Please see my workflow as an example: 

jobs:
  beautify:
    name: push
    outputs:
      new_sha: ${{ steps.sha.outputs.SHA }}
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
      with:
        persist-credentials: false
    - name: Create local changes
      run: |
       .....
    - name: Commit and push changes
      uses: github-actions-x/commit@v2.5
      with:
        github-token: ${{ secrets.GITHUB_TOKEN }}
        commit-message: 'style: improve code formatting'
        name: github-actions
        email: action@github.com
    - name: get sha
      id: sha
      run: |
        sha_new=$(git rev-parse HEAD)
        echo $sha_new
        echo "::set-output name=SHA::$sha_new"
    - run:
          echo ${{ steps.sha.outputs.SHA }}

  release:
    needs: [beautify]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          ref: ${{ needs.beautify.outputs.new_sha }}
          fetch-depth: 0
      - run:
          git log -5