Skip to content

Commit

Permalink
Add workflow that monitors the downstream test result.
Browse files Browse the repository at this point in the history
  • Loading branch information
larry-aptos committed Jan 23, 2025
1 parent 622e2ec commit 5860402
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/indexer-protos-sdk-update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions scripts/indexer_proto_update_status_poll.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5860402

Please sign in to comment.