From 586040287502a05e29a565e15bdb8898896d2072 Mon Sep 17 00:00:00 2001 From: Larry Liu Date: Wed, 22 Jan 2025 11:32:46 -0800 Subject: [PATCH] Add workflow that monitors the downstream test result. --- .../workflows/indexer-protos-sdk-update.yaml | 6 +++ scripts/indexer_proto_update_status_poll.sh | 42 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 scripts/indexer_proto_update_status_poll.sh diff --git a/.github/workflows/indexer-protos-sdk-update.yaml b/.github/workflows/indexer-protos-sdk-update.yaml index 852e6a994f308..a1b960822046b 100644 --- a/.github/workflows/indexer-protos-sdk-update.yaml +++ b/.github/workflows/indexer-protos-sdk-update.yaml @@ -92,6 +92,12 @@ jobs: repository: 'aptos-labs/aptos-indexer-processor-sdk' event-type: 'proto-dependency-update' client-payload: '{"commit_hash": "${{ github.sha }}", "branch_name": "${{ steps.commit_hash.outputs.branch_name }}"}' + - name: Poll for Workflow Run and Wait for Job Completion + run: | + . scripts/indexer_proto_update_status_poll.sh + env: + PAT_TOKEN: ${{ steps.secrets.outputs.token }} + TARGET_BRANCH: ${{ steps.commit_hash.outputs.branch_name }}-update-aptos-protos-update-sdk # TOOD: enable this once the forge test is stable. # - name: Run Forge Tests # uses: ./.github/workflows/workflow-run-forge diff --git a/scripts/indexer_proto_update_status_poll.sh b/scripts/indexer_proto_update_status_poll.sh new file mode 100755 index 0000000000000..d547dd7f8bfd8 --- /dev/null +++ b/scripts/indexer_proto_update_status_poll.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# PAT_TOKEN and TARGET_BRANCH are passed in as environment variables. + +TARGET_REPO="aptos-labs/aptos-indexer-processors" +WORKFLOW_NAME="sdk-dependency-update" +MAX_RETRIES=30 +RETRY_INTERVAL=60 # seconds + +echo "Monitoring workflow $WORKFLOW_NAME for branch $TARGET_BRANCH in $TARGET_REPO" + +for ((i=1; i<=MAX_RETRIES; i++)); do + # Get the latest run of the workflow for the target branch + response=$(curl -s -H "Authorization: token $PAT_TOKEN" \ + "https://api.github.com/repos/$TARGET_REPO/actions/workflows/$WORKFLOW_NAME/runs?branch=$TARGET_BRANCH&status=in_progress") + + # Check if there is an in-progress run + if echo "$response" | grep -q '"in_progress"'; then + echo "Workflow still in progress... waiting." + sleep $RETRY_INTERVAL + else + # Check the latest completed run for the branch + response=$(curl -s -H "Authorization: token $PAT_TOKEN" \ + "https://api.github.com/repos/$TARGET_REPO/actions/workflows/$WORKFLOW_NAME/runs?branch=$TARGET_BRANCH&status=completed") + total_count=$(echo "$response" | jq -r '.total_count') + if [ "$total_count" -gt 0 ]; then + conclusion=$(echo "$response" | jq -r '.workflow_runs[0].conclusion') + else + echo "No workflow runs found for branch $TARGET_BRANCH" + continue + fi + # If the workflow succeeds, exit with a zero status + if [ "$conclusion" == "success" ]; then + echo "Workflow completed successfully!" + exit 0 + fi + # Otherwise, we retry. + fi +done + +echo "Workflow did not complete within the timeout period." +exit 1 \ No newline at end of file