Skip to content

Commit

Permalink
ci: Improve accuracy of wait-for-circleci-workflow-status
Browse files Browse the repository at this point in the history
The GitHub Actions workflow `wait-for-circleci-workflow-status` has
been updated to ensure that it waits for the correct workflow.
Previously it always chose the most recent workflow for the given
branch, but it may have chosen a workflow corresponding to the wrong
commit. It has been updated to find one matching the same commit that
triggered the GitHub Actions workflow.
  • Loading branch information
Gudahtt committed Dec 18, 2024
1 parent 9020abf commit d97b1b0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .github/workflows/wait-for-circleci-workflow-status.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ jobs:
OWNER: ${{ github.repository_owner }}
REPOSITORY: ${{ github.event.repository.name }}
BRANCH: ${{ github.head_ref || github.ref_name }}
# For a `push` event, the HEAD commit hash is `github.sha`.
# For a `pull_request` event, `github.sha` is instead the base branch commit hash. The
# HEAD commit hash is `pull_request.head.sha`.
HEAD_COMMIT_HASH: ${{ github.event.pull_request.head.sha || github.sha }}
run: |
pipeline_id=$(curl --silent "https://circleci.com/api/v2/project/gh/$OWNER/$REPOSITORY/pipeline?branch=$BRANCH" | jq -r ".items[0].id")
pipeline_id=$(curl --silent "https://circleci.com/api/v2/project/gh/$OWNER/$REPOSITORY/pipeline?branch=$BRANCH" | jq -r ".items[] | select(.vcs.revision == \"${HEAD_COMMIT_HASH}\" ) | .id")
workflow_status=$(curl --silent "https://circleci.com/api/v2/pipeline/$pipeline_id/workflow" | jq -r ".items[0].status")
if [ "$workflow_status" == "running" ]; then
Expand Down

0 comments on commit d97b1b0

Please sign in to comment.