Skip to content

Commit 4f96e54

Browse files
nbdd0121GregAC
authored andcommitted
Fix stale merge commit issue in private CI
1 parent 7049d4d commit 4f96e54

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

.github/workflows/private-ci.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,35 @@ jobs:
2323
name: Trigger Private CI
2424
runs-on: ubuntu-latest
2525
steps:
26+
# Find a merge commit. We cannot use merge_commit_sha from context directly because
27+
# mergeability check is asynchronous to pull_request_target trigger..
28+
- name: Find the merge commit
29+
id: merge
30+
if: github.event_name == 'pull_request_target'
31+
uses: actions/github-script@v7
32+
with:
33+
script: |
34+
for (let i = 0; i <= 5; i++) {
35+
const { data: pr } = await github.rest.pulls.get({
36+
owner: context.repo.owner,
37+
repo: context.repo.repo,
38+
pull_number: context.issue.number,
39+
});
40+
41+
if (i != 5 && pr.mergeable == null) {
42+
console.log("Mergeability check in progress");
43+
await new Promise(r => setTimeout(r, 2000));
44+
continue;
45+
}
46+
47+
if (pr.mergeable) {
48+
core.setOutput('merge_sha', pr.merge_commit_sha);
49+
} else {
50+
core.setFailed('Pull request is not mergeable');
51+
}
52+
break;
53+
}
54+
2655
# Create pending statuses to block merge group and give indication before jobs are picked up.
2756
- name: Create pending statuses
2857
run: |
@@ -40,6 +69,6 @@ jobs:
4069
run: |
4170
gh workflow run ibex-private-ci.yml --repo lowRISC/lowrisc-private-ci \
4271
-f ref="${{ github.event.pull_request.head.sha || github.sha }}" \
43-
-f sha="${{ github.event.pull_request.merge_commit_sha || github.sha }}"
72+
-f sha="${{ steps.merge.outputs.merge_sha || github.sha }}"
4473
env:
4574
GITHUB_TOKEN: ${{ secrets.LOWRISC_PRIVATE_CI_PAT }}

0 commit comments

Comments
 (0)