Skip to content

Commit

Permalink
add check if workflow run exists
Browse files Browse the repository at this point in the history
  • Loading branch information
yuunlimm committed Oct 8, 2024
1 parent 2c61b56 commit 0bc93b4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/indexer-processor-testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ jobs:
- name: Handle New Files and Differences
run: |
echo "Checking outputs from diff_check step..."
echo "New file found: ${{ steps.diff_check.outputs.new_file_found }}"
echo "Diff found: ${{ steps.diff_check.outputs.diff_found }}"
if [ "${{ steps.diff_check.outputs.new_file_found }}" == "true" ]; then
echo "New JSON files detected:"
echo "${{ steps.diff_check.outputs.new_files }}" # Print all new files with paths
Expand Down Expand Up @@ -121,7 +125,7 @@ jobs:
# Conditionally Dispatch Event to Processor Repo if Differences Found
- name: Dispatch Event to Processor Repo
if: steps.diff_check.outputs.diff_found == 'true'
if: steps.diff_check.outputs.diff_found == 'true' && steps.diff_check.outputs.new_file_found == 'false'
uses: peter-evans/[email protected]
with:
TOKEN: '${{ steps.secrets.outputs.token }}'
Expand All @@ -131,7 +135,10 @@ jobs:

# Poll Processor Repo for Workflow Run Status and Memorize Run ID to check the job status
- name: Poll for Workflow Run and Wait for Job Completion
if: steps.diff_check.outputs.diff_found == 'true'
if: steps.diff_check.outputs.diff_found == 'true' && steps.diff_check.outputs.new_file_found == 'false'
id: poll_status
run: |
. scripts/indexer_processor_tests_status_poll.sh
. scripts/indexer_processor_tests_status_poll.sh
env:
GITHUB_TOKEN: ${{ steps.secrets.outputs.token }} # Pass the correct GitHub token
GITHUB_SHA: ${{ github.sha }}
23 changes: 21 additions & 2 deletions scripts/indexer_processor_tests_status_poll.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,19 @@ else
response=$(curl -s -H "Authorization: Bearer ${GITHUB_TOKEN}" \
"https://api.github.com/repos/aptos-labs/aptos-indexer-processors/actions/runs?event=repository_dispatch&branch=main")

# Check if the workflow_runs array exists
workflow_runs=$(echo "$response" | jq -r '.workflow_runs')
if [ "$workflow_runs" == "null" ] || [ -z "$workflow_runs" ]; then
echo "No workflow runs found. Response from GitHub API:"
echo "$response" # Output the raw response for debugging
echo "Retrying in $sleep_interval seconds..."
attempts=$((attempts + 1))
sleep $sleep_interval
continue
fi

# Filter the workflow run by the unique run-name commit hash
run_id=$(echo "$response" | jq -r ".workflow_runs[] | select(.name | test(\"$UUID\")) | .id")
run_id=$(echo "$workflow_runs" | jq -r ".[] | select(.name | test(\"$UUID\")) | .id")

if [ -n "$run_id" ]; then
echo "Found workflow run with ID: $run_id"
Expand Down Expand Up @@ -57,8 +68,16 @@ while [ "$job_completed" == false ] && [ $job_attempts -lt $max_job_attempts ];
echo "Polling for job status. Attempt $((job_attempts+1)) of $max_job_attempts..."
jobs_response=$(curl -s -H "Authorization: Bearer ${GITHUB_TOKEN}" "$jobs_url")

# Check if the jobs array exists
jobs=$(echo "$jobs_response" | jq -r '.jobs')
if [ "$jobs" == "null" ] || [ -z "$jobs" ]; then
echo "No jobs found in the workflow run. Response from GitHub API:"
echo "$jobs_response" # Output the raw response for debugging
exit 1
fi

# Loop through the jobs and check their status
for job in $(echo "$jobs_response" | jq -r '.jobs[] | @base64'); do
for job in $(echo "$jobs" | jq -r '.[] | @base64'); do
_jq() {
echo "${job}" | base64 --decode | jq -r "${1}"
}
Expand Down
9 changes: 7 additions & 2 deletions scripts/indexer_test_txns_compare_and_diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ compare_and_diff() {
diff_output=$(diff -u /dev/null "$generated_file" || true)
if [ -n "$diff_output" ]; then
echo "New file with diff found in $generated_file"
diff_found=true
echo "Diff output for new file:"
echo "$diff_output"
fi
Expand Down Expand Up @@ -103,7 +102,13 @@ else
echo "No modified files detected."
fi

# Set output flags (if integrated in a larger workflow, e.g., GitHub Actions)
# Debugging logs before setting outputs
echo "diff_found=$diff_found"
echo "new_file_found=$new_file_found"
echo "new_files=$new_files"
echo "modified_files=$modified_files"

# Set output flags
echo "diff_found=$diff_found" >> $GITHUB_OUTPUT
echo "new_file_found=$new_file_found" >> $GITHUB_OUTPUT
echo "new_files=$new_files" >> $GITHUB_OUTPUT # Store new files as output
Expand Down

0 comments on commit 0bc93b4

Please sign in to comment.