From 8badf68b6a9596335d6562ef7eca6109f68c887b Mon Sep 17 00:00:00 2001 From: Remco Vermeulen Date: Thu, 23 Nov 2023 19:10:02 -0800 Subject: [PATCH 1/5] Remove check run trigger This event is not triggered by worfklows to prevent recursive workflow calls. Therefore we only trigger on a dispatch generated by an Azure function that listens to check-run status changes. --- .github/workflows/update-release-status.yml | 39 ++++++--------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/.github/workflows/update-release-status.yml b/.github/workflows/update-release-status.yml index 15e212f369..9b1eb4bb61 100644 --- a/.github/workflows/update-release-status.yml +++ b/.github/workflows/update-release-status.yml @@ -1,12 +1,5 @@ name: "Update Release Status" on: - check_run: - types: - - completed - - rerequested - branches: - - "rc/**" - workflow_dispatch: inputs: head-sha: @@ -20,32 +13,22 @@ permissions: checks: write contents: write +env: + HEAD_SHA: ${{ inputs.head-sha }} + jobs: validate-check-runs: runs-on: ubuntu-22.04 outputs: status: ${{ steps.set-output.outputs.status }} - check-run-head-sha: ${{ steps.set-output.outputs.check-run-head-sha }} steps: - - name: Determine check run head SHA - env: - HEAD_SHA_FROM_EVENT: ${{ github.event.check_run.head_sha }} - HEAD_SHA_FROM_INPUTS: ${{ inputs.head-sha }} - run: | - if [[ $GITHUB_EVENT_NAME == "workflow_dispatch" ]]; then - echo "CHECK_RUN_HEAD_SHA=$HEAD_SHA_FROM_INPUTS" >> "$GITHUB_ENV" - else - echo "CHECK_RUN_HEAD_SHA=$HEAD_SHA_FROM_EVENT" >> "$GITHUB_ENV" - fi - - name: Checkout uses: actions/checkout@v4 with: - ref: ${{ env.CHECK_RUN_HEAD_SHA }} + ref: ${{ inputs.head-sha }} - name: Get release status check run id: get-check-run - if: (github.event_name == 'check_run' && github.event.check_run.conclusion == 'success' && github.event.check_run.name != github.workflow) || github.event_name == 'workflow_dispatch' env: GITHUB_TOKEN: ${{ github.token }} run: | @@ -53,7 +36,7 @@ jobs: --header "Accept: application/vnd.github+json" \ --header "X-GitHub-Api-Version: 2022-11-28" \ --jq '.check_runs[] | select(.name == "release-status") | {id: .id, status: .status, conclusion: .conclusion}' \ - /repos/$GITHUB_REPOSITORY/commits/$CHECK_RUN_HEAD_SHA/check-runs) + /repos/$GITHUB_REPOSITORY/commits/$HEAD_SHA/check-runs) check_run_id=$(echo "$check_run_info" | jq -r '.id') check_run_status=$(echo "$check_run_info" | jq -r '.status') @@ -64,7 +47,7 @@ jobs: echo "CHECK_RUN_CONCLUSION=$check_run_conclusion" >> "$GITHUB_ENV" - name: Reset release status - if: env.CHECK_RUN_STATUS == 'completed' && ((github.event_name == 'check_run' && github.event.action == 'rerequested') || github.event_name == 'workflow_dispatch') + if: env.CHECK_RUN_STATUS == 'completed' env: GITHUB_TOKEN: ${{ github.token }} run: | @@ -72,11 +55,13 @@ jobs: --header "Accept: application/vnd.github+json" \ --header "X-GitHub-Api-Version: 2022-11-28" \ --field name="release-status" \ - --field head_sha="$CHECK_RUN_HEAD_SHA" \ + --field head_sha="$HEAD_SHA" \ --jq ".id" \ /repos/$GITHUB_REPOSITORY/check-runs) echo "Created release status check run with id $CHECK_RUN_ID" + // Reset the status to in progress. + echo "CHECK_RUN_STATUS=in_progress" >> "$GITHUB_ENV" - name: Check all runs completed if: env.CHECK_RUN_STATUS != 'completed' @@ -87,7 +72,7 @@ jobs: --header "Accept: application/vnd.github+json" \ --header "X-GitHub-Api-Version: 2022-11-28" \ --jq '.check_runs | map(select(.name != "release-status"))' \ - /repos/$GITHUB_REPOSITORY/commits/$CHECK_RUN_HEAD_SHA/check-runs) + /repos/$GITHUB_REPOSITORY/commits/$HEAD_SHA/check-runs) status_stats=$(echo "$check_runs" | jq -r '. | {failed: (map(select(.conclusion == "failure")) | length), pending: (map(select(.status != "completed")) | length) }') @@ -132,13 +117,11 @@ jobs: echo "status=in_progress" >> "$GITHUB_OUTPUT" fi - echo "check-run-head-sha=$CHECK_RUN_HEAD_SHA" >> "$GITHUB_OUTPUT" - update-release: needs: validate-check-runs if: needs.validate-check-runs.outputs.status == 'completed' uses: ./.github/workflows/update-release.yml with: - head-sha: ${{ needs.validate-check-runs.outputs.check-run-head-sha }} + head-sha: ${{ inputs.head-sha }} secrets: AUTOMATION_PRIVATE_KEY: ${{ secrets.AUTOMATION_PRIVATE_KEY }} From 5e4bb2ad152051d67dfa237e6643c2b164ff02e3 Mon Sep 17 00:00:00 2001 From: Remco Vermeulen Date: Tue, 28 Nov 2023 18:48:13 -0800 Subject: [PATCH 2/5] Use correct comment syntax --- .github/workflows/update-release-status.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-release-status.yml b/.github/workflows/update-release-status.yml index 9b1eb4bb61..3256dff852 100644 --- a/.github/workflows/update-release-status.yml +++ b/.github/workflows/update-release-status.yml @@ -60,7 +60,7 @@ jobs: /repos/$GITHUB_REPOSITORY/check-runs) echo "Created release status check run with id $CHECK_RUN_ID" - // Reset the status to in progress. + # Reset the status to in progress. echo "CHECK_RUN_STATUS=in_progress" >> "$GITHUB_ENV" - name: Check all runs completed From 87b64e7352152ffd34a7f6f553a553303be98d5a Mon Sep 17 00:00:00 2001 From: Remco Vermeulen Date: Wed, 29 Nov 2023 09:21:34 -0800 Subject: [PATCH 3/5] Add check if release-status checkrun was found --- .github/workflows/update-release-status.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/update-release-status.yml b/.github/workflows/update-release-status.yml index 3256dff852..3589ed8d17 100644 --- a/.github/workflows/update-release-status.yml +++ b/.github/workflows/update-release-status.yml @@ -38,6 +38,11 @@ jobs: --jq '.check_runs[] | select(.name == "release-status") | {id: .id, status: .status, conclusion: .conclusion}' \ /repos/$GITHUB_REPOSITORY/commits/$HEAD_SHA/check-runs) + if [[ -z "$check_run_info" ]]; then + echo "No release status check run found" + exit 1 + fi + check_run_id=$(echo "$check_run_info" | jq -r '.id') check_run_status=$(echo "$check_run_info" | jq -r '.status') check_run_conclusion=$(echo "$check_run_info" | jq -r '.conclusion') From ab143ef788854555838554301cd6ebf54e0bd88f Mon Sep 17 00:00:00 2001 From: Remco Vermeulen Date: Wed, 29 Nov 2023 09:28:51 -0800 Subject: [PATCH 4/5] Only update release on success --- .github/workflows/update-release-status.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/update-release-status.yml b/.github/workflows/update-release-status.yml index 3589ed8d17..980764c924 100644 --- a/.github/workflows/update-release-status.yml +++ b/.github/workflows/update-release-status.yml @@ -21,6 +21,7 @@ jobs: runs-on: ubuntu-22.04 outputs: status: ${{ steps.set-output.outputs.status }} + conclusion: ${{ steps.set-output.outputs.conclusion }} steps: - name: Checkout uses: actions/checkout@v4 @@ -113,6 +114,8 @@ jobs: --input - \ /repos/$GITHUB_REPOSITORY/check-runs/$CHECK_RUN_ID + echo "conclusion=$conclusion" >> "$GITHUB_OUTPUT + - name: Set output id: set-output run: | @@ -124,7 +127,7 @@ jobs: update-release: needs: validate-check-runs - if: needs.validate-check-runs.outputs.status == 'completed' + if: needs.validate-check-runs.outputs.status == 'completed' && needs.validate-check-runs.outputs.conclusion == 'success' uses: ./.github/workflows/update-release.yml with: head-sha: ${{ inputs.head-sha }} From ae8b7cb8f1e774a27296cc732398b4605698f6eb Mon Sep 17 00:00:00 2001 From: Remco Vermeulen Date: Wed, 29 Nov 2023 09:40:08 -0800 Subject: [PATCH 5/5] Print status stats for debugging purposes --- .github/workflows/update-release-status.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/update-release-status.yml b/.github/workflows/update-release-status.yml index 980764c924..8b00bf49a7 100644 --- a/.github/workflows/update-release-status.yml +++ b/.github/workflows/update-release-status.yml @@ -82,6 +82,8 @@ jobs: status_stats=$(echo "$check_runs" | jq -r '. | {failed: (map(select(.conclusion == "failure")) | length), pending: (map(select(.status != "completed")) | length) }') + echo "status_stats=$status_stats" + failed=$(echo "$status_stats" | jq -r '.failed') pending=$(echo "$status_stats" | jq -r '.pending')