-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This should build, test all branches on request or nightly. (cherry picked from commit f208c16)
- Loading branch information
1 parent
edd84f6
commit 09b6e30
Showing
1 changed file
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
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: Trigger workflows in other branches | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
set -x # Enable command echo for debugging | ||
branches=("master" "master-next" "scarthgap" "scarthgap-next" "kirkstone" "kirkstone-next" "styhead" "styhead-next") | ||
declare -A run_ids | ||
declare -A run_urls | ||
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 and URL of the newly triggered workflow | ||
sleep 5 # Wait a bit for the workflow to start | ||
run_info=$(gh run list --workflow=build-test-recipe.yml --branch=$branch --limit 1 --json databaseId,url) | ||
run_id=$(echo "$run_info" | jq -r '.[0].databaseId') | ||
run_url=$(echo "$run_info" | jq -r '.[0].url') | ||
if [ -n "$run_id" ]; then | ||
run_ids["$branch"]="$run_id" | ||
run_urls["$branch"]="$run_url" | ||
echo "Triggered workflow for $branch with run ID: $run_id" | ||
else | ||
echo "Failed to get run info for $branch" | ||
fi | ||
else | ||
echo "Error triggering workflow for $branch" | ||
echo "API Response: $response" | ||
fi | ||
done | ||
# Save run IDs and URLs to files for the next steps | ||
echo "$(declare -p run_ids)" > run_ids.txt | ||
echo "$(declare -p run_urls)" > run_urls.txt | ||
echo "run_ids=${run_ids[*]}" >> $GITHUB_ENV | ||
- name: Display triggered workflows | ||
run: | | ||
source run_ids.txt | ||
source run_urls.txt | ||
echo "# Triggered Build Test Workflows" > report.md | ||
echo "" >> report.md | ||
echo "| Branch | Run ID | Workflow Run |" >> report.md | ||
echo "|--------|--------|--------------|" >> report.md | ||
for branch in "${!run_ids[@]}"; do | ||
id="${run_ids[$branch]}" | ||
url="${run_urls[$branch]}" | ||
echo "| $branch | $id | [View Run]($url) |" >> report.md | ||
done | ||
echo "## Triggered Workflows" >> $GITHUB_STEP_SUMMARY | ||
cat report.md >> $GITHUB_STEP_SUMMARY | ||
echo "Triggered workflows:" | ||
cat report.md | ||
- name: Wait for branch workflows to complete | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
IFS=' ' read -ra run_ids <<< "${{ env.run_ids }}" | ||
max_attempts=120 # Maximum 120 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 |