From e9f2c64322c878b4abdc3ef0da4c23858875737b Mon Sep 17 00:00:00 2001 From: Alexander Bayandin Date: Fri, 1 Sep 2023 12:59:19 +0100 Subject: [PATCH] Wait for custom extensions build before deploy (#5170) ## Problem Currently, the `deploy` job doesn't wait for the custom extension job (in another repo) and can be started even with failed extensions build. This PR adds another job that polls the status of the extension build job and fails if the extension build fails. ## Summary of changes - Add `wait-for-extensions-build` job, which waits for a custom extension build in another repo. --- .github/workflows/build_and_test.yml | 50 +++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 1ec2a65a89..144a96910e 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -899,7 +899,7 @@ jobs: - name: Cleanup ECR folder run: rm -rf ~/.ecr - build-private-extensions: + trigger-custom-extensions-build: runs-on: [ self-hosted, gen3, small ] container: image: 369495373322.dkr.ecr.eu-central-1.amazonaws.com/base:pinned @@ -908,8 +908,7 @@ jobs: steps: - name: Set PR's status to pending and request a remote CI test run: | - COMMIT_SHA=${{ github.event.pull_request.head.sha }} - COMMIT_SHA=${COMMIT_SHA:-${{ github.sha }}} + COMMIT_SHA=${{ github.event.pull_request.head.sha || github.sha }} REMOTE_REPO="${{ github.repository_owner }}/build-custom-extensions" curl -f -X POST \ @@ -939,10 +938,53 @@ jobs: } }" + wait-for-extensions-build: + runs-on: ubuntu-latest + needs: [ trigger-custom-extensions-build ] + + steps: + - name: Wait for extension build to finish + env: + GH_TOKEN: ${{ secrets.CI_ACCESS_TOKEN }} + run: | + TIMEOUT=600 # 10 minutes, currently it takes ~2-3 minutes + INTERVAL=15 # try each N seconds + + last_status="" # a variable to carry the last status of the "build-and-upload-extensions" context + + for ((i=0; i <= $TIMEOUT; i+=$INTERVAL)); do + sleep $INTERVAL + + # Get statuses for the latest commit in the PR / branch + gh api \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "/repos/${{ github.repository }}/statuses/${{ github.event.pull_request.head.sha || github.sha }}" > statuses.json + + # Get the latest status for the "build-and-upload-extensions" context + last_status=$(jq --raw-output '[.[] | select(.context == "build-and-upload-extensions")] | sort_by(.created_at)[-1].state' statuses.json) + if [ "${last_status}" = "pending" ]; then + # Extension build is still in progress. + continue + elif [ "${last_status}" = "success" ]; then + # Extension build is successful. + exit 0 + else + # Status is neither "pending" nor "success", exit the loop and fail the job. + break + fi + done + + # Extension build failed, print `statuses.json` for debugging and fail the job. + jq '.' statuses.json + + echo >&2 "Status of extension build is '${last_status}' != 'success'" + exit 1 + deploy: runs-on: [ self-hosted, gen3, small ] container: 369495373322.dkr.ecr.eu-central-1.amazonaws.com/ansible:latest - needs: [ promote-images, tag, regress-tests ] + needs: [ promote-images, tag, regress-tests, wait-for-extensions-build ] if: ( github.ref_name == 'main' || github.ref_name == 'release' ) && github.event_name != 'workflow_dispatch' steps: - name: Fix git ownership