if action is triggered by pr event short-sha returns main shortened sha instead of branch
SergiiShapoval opened this issue · 6 comments
SergiiShapoval commented
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?
benjlevesque commented
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.
SergiiShapoval commented
benjlevesque commented
did you try removing the ref
parameter in the checkout action?
SergiiShapoval commented
this is an issue, without ref it works
benjlevesque commented
but your workflow requires the ref
?
SergiiShapoval commented
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