Skip to content

Commit 6f8dc5e

Browse files
committed
Use github-script to get ref and sha instead of shell (strimzi#11975)
Signed-off-by: Jakub Stejskal <xstejs24@gmail.com>
1 parent 31e9241 commit 6f8dc5e

File tree

1 file changed

+40
-30
lines changed

1 file changed

+40
-30
lines changed

.github/actions/utils/determine-ref/action.yml

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,44 @@ outputs:
1212
runs:
1313
using: "composite"
1414
steps:
15-
- name: Determine ref
15+
- name: Determine ref and SHA
1616
id: determine
17-
shell: bash
18-
run: |
19-
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
20-
# For PR events, use merge ref to test the merged state
21-
REF="refs/pull/${{ github.event.pull_request.number }}/merge"
22-
SHA="${{ github.event.pull_request.merge_commit_sha }}"
23-
if [[ "$SHA" == "" || "$SHA" == "null" ]]; then
24-
SHA="HEAD"
25-
fi
26-
echo "PR event detected: Using merge ref for PR #${{ github.event.pull_request.number }}"
27-
elif [[ "${{ github.event_name }}" == "issue_comment" ]] && [[ "${{ github.event.issue.pull_request }}" != "" && "${{ github.event.issue.pull_request }}" != "null" ]]; then
28-
# For PR comments, use merge ref to test against merge commit
29-
REF="refs/pull/${{ github.event.issue.number }}/merge"
30-
SHA="HEAD"
31-
echo "PR comment detected: Using merge ref for PR #${{ github.event.issue.number }}"
32-
else
33-
# For workflow_dispatch and other events, use the current branch
34-
REF="${{ github.ref }}"
35-
SHA="${{ github.sha }}"
36-
echo "Standard event: Using current ref $REF"
37-
fi
38-
39-
echo "ref=$REF" >> $GITHUB_OUTPUT
40-
echo "sha=$SHA" >> $GITHUB_OUTPUT
41-
echo "REF=$REF" >> $GITHUB_ENV
42-
echo "SHA=$SHA" >> $GITHUB_ENV
43-
44-
echo "Determined ref: $REF"
45-
echo "Determined SHA: $SHA"
17+
uses: actions/github-script@v7
18+
with:
19+
script: |
20+
const {owner, repo} = context.repo;
21+
let ref, sha;
22+
23+
if (context.eventName === 'pull_request') {
24+
// For PR events, use merge ref to test the merged state
25+
const prNumber = context.payload.pull_request.number;
26+
ref = `refs/pull/${prNumber}/merge`;
27+
sha = context.payload.pull_request.head.sha;
28+
core.info(`PR event detected: Using merge ref for PR #${prNumber}`);
29+
core.info(`Head SHA: ${sha}`);
30+
} else if (context.eventName === 'issue_comment' && context.payload.issue?.pull_request) {
31+
// For PR comments, fetch the PR to get head SHA
32+
const prNumber = context.payload.issue.number;
33+
ref = `refs/pull/${prNumber}/merge`;
34+
35+
const pr = await github.rest.pulls.get({
36+
owner,
37+
repo,
38+
pull_number: prNumber
39+
});
40+
sha = pr.data.head.sha;
41+
42+
core.info(`PR comment detected: Using merge ref for PR #${prNumber}`);
43+
core.info(`Head SHA: ${sha}`);
44+
} else {
45+
// For workflow_dispatch and other events, use the current branch
46+
ref = context.ref;
47+
sha = context.sha;
48+
core.info(`Standard event: Using current ref ${ref}`);
49+
core.info(`SHA: ${sha}`);
50+
}
51+
52+
core.setOutput('ref', ref);
53+
core.setOutput('sha', sha);
54+
core.exportVariable('REF', ref);
55+
core.exportVariable('SHA', sha);

0 commit comments

Comments
 (0)