Skip to content

trigger build-test in all supported branches #12

trigger build-test in all supported branches

trigger build-test in all supported branches #12

name: trigger build-test in all supported branches
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
jobs:
trigger-branch-workflows:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check workflow file
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
for branch in "scarthgap-next" "kirkstone-next" "styhead-next"; do
echo "Checking build-test-recipe.yml in $branch:"
gh api repos/${{ github.repository }}/contents/.github/workflows/build-test-recipe.yml?ref=$branch | jq -r '.content' | base64 -d
echo "-----------------------------------"
done
- name: Trigger workflows in other branches
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -x # Enable command echo for debugging
branches=("scarthgap-next" "kirkstone-next" "styhead-next")
run_ids=()
for branch in "${branches[@]}"; do
echo "Attempting to trigger workflow for branch: $branch"
# Trigger the workflow using the GitHub API directly
response=$(curl -sS -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/actions/workflows/build-test-recipe.yml/dispatches" \
-d "{\"ref\":\"$branch\"}")
echo "API Response: $response"
# Check if the workflow was triggered successfully
if [ -z "$response" ]; then
echo "Workflow triggered successfully for $branch"
# Get the run ID of the newly triggered workflow
sleep 5 # Wait a bit for the workflow to start
run_id=$(gh run list --workflow=build-test-recipe.yml --branch=$branch --limit 1 --json databaseId --jq '.[0].databaseId')
if [ -n "$run_id" ]; then
run_ids+=("$run_id")
echo "Triggered workflow for $branch with run ID: $run_id"
else
echo "Failed to get run ID for $branch"
fi
else
echo "Error triggering workflow for $branch"
echo "API Response: $response"
fi
done
if [ ${#run_ids[@]} -eq 0 ]; then
echo "No workflows were successfully triggered"
exit 1
fi
echo "run_ids=${run_ids[*]}" >> $GITHUB_ENV
- name: Wait for branch workflows to complete
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
IFS=' ' read -ra run_ids <<< "${{ env.run_ids }}"
max_attempts=90 # Maximum 90 min exec time
for attempt in $(seq 1 $max_attempts); do
all_completed=true
for run_id in "${run_ids[@]}"; do
status=$(gh run view $run_id --json status --jq '.status')
if [ "$status" != "completed" ]; then
all_completed=false
break
fi
done
if $all_completed; then
echo "All branch workflows have completed."
break
fi
if [ $attempt -eq $max_attempts ]; then
echo "Timeout waiting for workflows to complete."
exit 1
fi
echo "Waiting for workflows to complete... (Attempt $attempt/$max_attempts)"
sleep 60
done
- name: Report status
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "All branch workflows have completed."
IFS=' ' read -ra run_ids <<< "${{ env.run_ids }}"
for run_id in "${run_ids[@]}"; do
run_info=$(gh run view $run_id --json headBranch,conclusion)
branch=$(echo "$run_info" | jq -r '.headBranch')
conclusion=$(echo "$run_info" | jq -r '.conclusion')
echo "Branch $branch workflow conclusion: $conclusion"
done