benjlevesque/short-sha

if action is triggered by pr event short-sha returns main shortened sha instead of branch

SergiiShapoval opened this issue · 6 comments

we are using the checkout command with ref input:

      - name: Checkout
        uses: actions/checkout@v3
        with:
          ref: branch_name # PR source branch name

but after such checkout, current action uses SHA from main instead of the last commit SHA

it looks like we need to use context.event.pull_request.head.sha instead of context.sha in https://github.com/benjlevesque/short-sha/blob/v2.2/src/main.ts

WDYT?

I'm using this action with PR events and did not encounter this behaviour; the only difference I see is the use of ref; do you need it? actions/checkout will already checkout the PR's branch.

yes, for some reason I see that actions/checkout checked out branch, but this action return short sha of main commit

image

794a85d1799fa2aa0f41ad86ba7c2d15e4ade5ee - branch SHA
a61a3d9 is result of short sha that corresponds to main SHA

did you try removing the ref parameter in the checkout action?

this is an issue, without ref it works

but your workflow requires the ref?

yes,
fyi, we have replaced our action steps to use input, and

 - name: Generate short Git SHA
      id: short-sha
      shell: bash
      run: |
        echo "input sha: ${{ inputs.sha }}"
        full_sha=${{ inputs.sha }}
        echo "sha=${full_sha:0:7}" >> $GITHUB_OUTPUT