From 2bd9a61e995ea2780ed055e172f6e31e06967c9a Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Wed, 31 Jan 2024 14:52:23 +0000 Subject: [PATCH] Fix stale merge commit issue in private CI --- .github/workflows/private-ci.yml | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/.github/workflows/private-ci.yml b/.github/workflows/private-ci.yml index 1703463086..0a8ad754a9 100644 --- a/.github/workflows/private-ci.yml +++ b/.github/workflows/private-ci.yml @@ -23,6 +23,35 @@ jobs: name: Trigger Private CI runs-on: ubuntu-latest steps: + # Find a merge commit. We cannot use merge_commit_sha from context directly because + # mergeability check is asynchronous to pull_request_target trigger.. + - name: Find the merge commit + id: merge + if: github.event_name == 'pull_request_target' + uses: actions/github-script@v7 + with: + script: | + for (let i = 0; i <= 5; i++) { + const { data: pr } = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number, + }); + + if (i != 5 && pr.mergeable == null) { + console.log("Mergeability check in progress"); + await new Promise(r => setTimeout(r, 2000)); + continue; + } + + if (pr.mergeable) { + core.setOutput('merge_sha', pr.merge_commit_sha); + } else { + core.setFailed('Pull request is not mergeable'); + } + break; + } + # Create pending statuses to block merge group and give indication before jobs are picked up. - name: Create pending statuses run: | @@ -40,6 +69,6 @@ jobs: run: | gh workflow run ibex-private-ci.yml --repo lowRISC/lowrisc-private-ci \ -f ref="${{ github.event.pull_request.head.sha || github.sha }}" \ - -f sha="${{ github.event.pull_request.merge_commit_sha || github.sha }}" + -f sha="${{ steps.merge.outputs.merge_sha || github.sha }}" env: GITHUB_TOKEN: ${{ secrets.LOWRISC_PRIVATE_CI_PAT }}