action-create-tag icon indicating copy to clipboard operation
action-create-tag copied to clipboard

Ref to tag should be sha of workflow, not commit_sha

Open bakoontz2 opened this issue 11 months ago • 0 comments

Describe the bug If a workflow is triggered from one branch, and then actions/checkout is invoked to check out a different branch, action-create-tag attempts to tag the wrong commit, generating a "fatal: bad object type" error.

To Reproduce Steps to reproduce the behavior:

  1. Create an action that does a checkout from a branch different from the commit that triggered the workflow.
  2. In the yaml, call actions/checkout followed by action-create-tag.
  3. An error will result due to a mismatch between the expected commit of the workflow and commit_sha, which still reflects the triggering workflow commit.

Expected behavior It's not clear to my why the GH folks think it's a good idea to leave commit_sha set to the triggering workflow. But when a checkout on a different branch is done, commit_sha is no longer accurate, and action_create_tag should be using as the default the commit sha of the checkout.

Workaround The only workaround I've found is to add an extra step to get the workspace commit, and override the action default:

    - uses: actions/checkout@v4
      with:
        progress: false
        ref: ${{ inputs.build-branch }}

    - name: Get workspace sha
      run: |
        echo "WORKSPACE_SHA=$(/usr/bin/git log -1 --format='%H')" >> $GITHUB_ENV

    - name: Tag the commit with the version
      uses: rickstaa/action-create-tag@v1
      with:
        tag: ${{env.TAG}}
        commit_sha: ${{ env.WORKSPACE_SHA }}

bakoontz2 avatar Mar 08 '24 19:03 bakoontz2