From 29c46809c5ef0263b062f5ee97c247fed68248d6 Mon Sep 17 00:00:00 2001 From: Anchal Gupta Date: Fri, 13 Jun 2025 15:20:54 -0700 Subject: [PATCH 1/5] Adding testing of reusable workflows --- .github/workflows/test_reusable_workflow.yml | 143 +++++++++++++++++++ .github/workflows/test_test.yml | 23 +++ 2 files changed, 166 insertions(+) create mode 100644 .github/workflows/test_reusable_workflow.yml create mode 100644 .github/workflows/test_test.yml diff --git a/.github/workflows/test_reusable_workflow.yml b/.github/workflows/test_reusable_workflow.yml new file mode 100644 index 0000000..e9a4f96 --- /dev/null +++ b/.github/workflows/test_reusable_workflow.yml @@ -0,0 +1,143 @@ +name: Test Reusable Workflow + +on: + workflow_call: + inputs: + target_repo: + description: 'Target repository in owner/repo format (e.g., octocat/hello-world)' + required: true + type: string + + workflow_file: + description: 'Workflow file name in the target repo (e.g., deploy.yml)' + required: true + type: string + + ref: + description: 'Git ref (branch, tag, or commit SHA) to run the workflow on' + required: true + type: string + + use_pat: + description: 'Whether to use PAT instead of GITHUB_TOKEN' + required: false + default: false + type: boolean + + wait_timeout_seconds: + description: 'Max seconds to wait for the workflow run to start' + required: false + default: '300' + type: string + + run_timeout_seconds: + description: 'Max seconds to wait for the workflow run to complete' + required: false + default: '3600' + type: string + + poll_frequency_seconds: + description: 'How often (in seconds) to poll for workflow status' + required: false + default: '10' + type: string + + secrets: + PAT: + description: 'Personal Access Token for cross-repo workflow dispatch (optional)' + required: false + +jobs: + trigger: + runs-on: ubuntu-latest + + steps: + - name: Trigger Target Workflow + + run: | + echo "Triggering ${{ inputs.workflow_file }} in ${{ inputs.target_repo }} on ref ${{ inputs.ref }}..." + + curl -s -o /dev/null -w "%{http_code}" -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${{ secrets.PAT }}" \ + https://api.github.com/repos/${{ inputs.target_repo }}/actions/workflows/${{ inputs.workflow_file }}/dispatches \ + -d "{\"ref\":\"${{ inputs.ref }}\"}" | grep -q 204 + + - name: Wait for Workflow Run + env: + GH_TOKEN: ${{ secrets.PAT }} + WAIT_TIMEOUT: ${{ inputs.wait_timeout_seconds }} + RUN_TIMEOUT: ${{ inputs.run_timeout_seconds }} + POLL_FREQ: ${{ inputs.poll_frequency_seconds }} + TARGET_REPO: ${{ inputs.target_repo }} + WORKFLOW_FILE: ${{ inputs.workflow_file }} + REF: ${{ inputs.ref }} + run: | + OWNER=$(echo "$TARGET_REPO" | cut -d'/' -f1) + REPO=$(echo "$TARGET_REPO" | cut -d'/' -f2) + + echo "Waiting up to $WAIT_TIMEOUT seconds for workflow run to appear..." + + WAIT_ITER=$((WAIT_TIMEOUT / POLL_FREQ)) + sleep 10 # Sleep for a while to get the new workflow started + for ((i=0; i/dev/null) + + set -e + + if [[ "$RUN_ID" != "null" && -n "$RUN_ID" ]]; then + echo "✅ Found workflow run ID: $RUN_ID" + break + fi + + TOTAL_WAIT=$((i * POLL_FREQ)) + + echo "⏳ Waiting for workflow run... (${TOTAL_WAIT}s)" + sleep $POLL_FREQ + done + + if [[ -z "$RUN_ID" || "$RUN_ID" == "null" ]]; then + echo "❌ Workflow run did not start in time" + exit 1 + fi + + echo "Polling workflow run status for up to $RUN_TIMEOUT seconds..." + + # Poll until run completes + RUN_ITER=$((RUN_TIMEOUT / POLL_FREQ)) + for ((i=0; i/dev/null) + CONCLUSION=$(echo "$RESPONSE" | jq -r '.conclusion' 2>/dev/null) + + set -e + + if [[ "$STATUS" == "completed" ]]; then + echo "🎯 Workflow completed with conclusion: $CONCLUSION" + + if [[ "$CONCLUSION" == "success" ]]; then + exit 0 + else + exit 1 + fi + elif [[ -z "$STATUS" || "$STATUS" == "null" ]]; then + echo "⚠️ Warning: Could not get workflow status. Retry in $POLL_FREQ sec..." + else + echo "⏳ Still running ($STATUS)..." + fi + + sleep $POLL_FREQ + done + + echo "❌ Workflow run did not complete in allotted time." + exit 1 \ No newline at end of file diff --git a/.github/workflows/test_test.yml b/.github/workflows/test_test.yml new file mode 100644 index 0000000..f1cd3f1 --- /dev/null +++ b/.github/workflows/test_test.yml @@ -0,0 +1,23 @@ +name: Test Reusable Workflow Test +on: + workflow_dispatch: # Manually trigger + push: + branches: master + paths: + - '.github/workflows/test.yml' + - '.github/workflows/test_test.yml' + pull_request: + branches: master + paths: + - '.github/workflows/test.yml' + - '.github/workflows/test_test.yml' + +jobs: + test_on_IMASggd: + uses: ProjectTorreyPines/GitHubActionsWorkflows/.github/workflows/test_reusable_workflow.yml@test_workflows + secrets: inherit + with: + target_repo: ProjectTorreyPines/IMASggd.jl + workflow_file: test.yml + ref: master + use_pat: true From 4615f8df254772f0e64d9d49d0c4680547d008ad Mon Sep 17 00:00:00 2001 From: Anchal Gupta Date: Fri, 13 Jun 2025 17:49:58 -0700 Subject: [PATCH 2/5] Filter for workflows that have started after the trigger time --- .github/workflows/test_reusable_workflow.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test_reusable_workflow.yml b/.github/workflows/test_reusable_workflow.yml index e9a4f96..241b898 100644 --- a/.github/workflows/test_reusable_workflow.yml +++ b/.github/workflows/test_reusable_workflow.yml @@ -56,6 +56,8 @@ jobs: run: | echo "Triggering ${{ inputs.workflow_file }} in ${{ inputs.target_repo }} on ref ${{ inputs.ref }}..." + export TRIGGER_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") + echo "TRIGGER_TIME=$TRIGGER_TIME" >> $GITHUB_ENV curl -s -o /dev/null -w "%{http_code}" -X POST \ -H "Accept: application/vnd.github+json" \ @@ -79,15 +81,21 @@ jobs: echo "Waiting up to $WAIT_TIMEOUT seconds for workflow run to appear..." WAIT_ITER=$((WAIT_TIMEOUT / POLL_FREQ)) - sleep 10 # Sleep for a while to get the new workflow started + sleep 3 # Sleep for a while to get the new workflow started for ((i=0; i/dev/null) - + RUN_ID=$(echo "$RESPONSE" | jq -r --arg trigger_time "$TRIGGER_TIME" ' + if (.workflow_runs | type == "array") then + .workflow_runs + | map(select(.created_at > $trigger_time)) + | sort_by(.created_at) + | last + | .id + else empty end') set -e if [[ "$RUN_ID" != "null" && -n "$RUN_ID" ]]; then From cacc90b748d4c1d1a4f8add6ee24013156bdd1f9 Mon Sep 17 00:00:00 2001 From: Anchal Gupta Date: Fri, 13 Jun 2025 18:01:16 -0700 Subject: [PATCH 3/5] Adding manual trigger in all samples --- samples/format_check.yml | 1 + samples/make_docs.yml | 1 + samples/release_data.yml | 1 + samples/test.yml | 1 + 4 files changed, 4 insertions(+) diff --git a/samples/format_check.yml b/samples/format_check.yml index 1a08cb3..8c03c88 100644 --- a/samples/format_check.yml +++ b/samples/format_check.yml @@ -1,6 +1,7 @@ name: Format Check on: + workflow_dispatch: # Manually trigger push: branches: ["master", "dev"] paths: diff --git a/samples/make_docs.yml b/samples/make_docs.yml index 123304b..e0b338a 100644 --- a/samples/make_docs.yml +++ b/samples/make_docs.yml @@ -1,5 +1,6 @@ name: Make Docs on: + workflow_dispatch: # Manually trigger push: branches: ["master", "dev"] paths: diff --git a/samples/release_data.yml b/samples/release_data.yml index b1498c7..d5f1fab 100644 --- a/samples/release_data.yml +++ b/samples/release_data.yml @@ -1,6 +1,7 @@ name: Release Data on: + workflow_dispatch: # Manually trigger push: branches: ["master"] diff --git a/samples/test.yml b/samples/test.yml index 490a7a4..df0f240 100644 --- a/samples/test.yml +++ b/samples/test.yml @@ -1,6 +1,7 @@ name: Test on: + workflow_dispatch: # Manually trigger push: branches: ["master", "dev"] paths: From e8c2e173e70ba4a8706ea1a1899f8232f0a373db Mon Sep 17 00:00:00 2001 From: Anchal Gupta Date: Fri, 13 Jun 2025 18:01:40 -0700 Subject: [PATCH 4/5] Adding test on SOLPS2imas and FusionSyntheticDiagnostics --- .github/workflows/test_test.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_test.yml b/.github/workflows/test_test.yml index f1cd3f1..a129cd0 100644 --- a/.github/workflows/test_test.yml +++ b/.github/workflows/test_test.yml @@ -14,10 +14,26 @@ on: jobs: test_on_IMASggd: + name: Testing test.yml on IMASggd uses: ProjectTorreyPines/GitHubActionsWorkflows/.github/workflows/test_reusable_workflow.yml@test_workflows secrets: inherit with: target_repo: ProjectTorreyPines/IMASggd.jl workflow_file: test.yml ref: master - use_pat: true + test_on_SOLPS2imas: + name: Testing test.yml on SOLPS2imas + uses: ProjectTorreyPines/GitHubActionsWorkflows/.github/workflows/test_reusable_workflow.yml@test_workflows + secrets: inherit + with: + target_repo: ProjectTorreyPines/SOLPS2imas.jl + workflow_file: test.yml + ref: master + test_on_FusionSyntheticDiagnostics: + name: Testing test.yml on FusionSyntheticDiagnostics + uses: ProjectTorreyPines/GitHubActionsWorkflows/.github/workflows/test_reusable_workflow.yml@test_workflows + secrets: inherit + with: + target_repo: ProjectTorreyPines/FusionSyntheticDiagnostics.jl + workflow_file: test.yml + ref: master From 898045fc24db3453fb34cff7f9a8ba2da284b9b7 Mon Sep 17 00:00:00 2001 From: Anchal Gupta Date: Fri, 13 Jun 2025 18:19:01 -0700 Subject: [PATCH 5/5] Removed test_workflows tag and added tests for other workflows --- .github/workflows/test_format_check.yml | 39 +++++++++++++++++++++++++ .github/workflows/test_make_docs.yml | 39 +++++++++++++++++++++++++ .github/workflows/test_test.yml | 6 ++-- 3 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/test_format_check.yml create mode 100644 .github/workflows/test_make_docs.yml diff --git a/.github/workflows/test_format_check.yml b/.github/workflows/test_format_check.yml new file mode 100644 index 0000000..a952132 --- /dev/null +++ b/.github/workflows/test_format_check.yml @@ -0,0 +1,39 @@ +name: Test Reusable Workflow Format Check +on: + workflow_dispatch: # Manually trigger + push: + branches: master + paths: + - '.github/workflows/format_check.yml' + - '.github/workflows/test_format_check.yml' + pull_request: + branches: master + paths: + - '.github/workflows/format_check.yml' + - '.github/workflows/test_format_check.yml' + +jobs: + test_on_IMASggd: + name: Testing format_check.yml on IMASggd + uses: ProjectTorreyPines/GitHubActionsWorkflows/.github/workflows/test_reusable_workflow.yml + secrets: inherit + with: + target_repo: ProjectTorreyPines/IMASggd.jl + workflow_file: format_check.yml + ref: master + test_on_SOLPS2imas: + name: Testing format_check.yml on SOLPS2imas + uses: ProjectTorreyPines/GitHubActionsWorkflows/.github/workflows/test_reusable_workflow.yml + secrets: inherit + with: + target_repo: ProjectTorreyPines/SOLPS2imas.jl + workflow_file: format_check.yml + ref: master + test_on_FusionSyntheticDiagnostics: + name: Testing format_check.yml on FusionSyntheticDiagnostics + uses: ProjectTorreyPines/GitHubActionsWorkflows/.github/workflows/test_reusable_workflow.yml + secrets: inherit + with: + target_repo: ProjectTorreyPines/FusionSyntheticDiagnostics.jl + workflow_file: format_check.yml + ref: master diff --git a/.github/workflows/test_make_docs.yml b/.github/workflows/test_make_docs.yml new file mode 100644 index 0000000..e54cb48 --- /dev/null +++ b/.github/workflows/test_make_docs.yml @@ -0,0 +1,39 @@ +name: Test Reusable Workflow Make Docs +on: + workflow_dispatch: # Manually trigger + push: + branches: master + paths: + - '.github/workflows/make_docs.yml' + - '.github/workflows/test_make_docs.yml' + pull_request: + branches: master + paths: + - '.github/workflows/make_docs.yml' + - '.github/workflows/test_make_docs.yml' + +jobs: + test_on_IMASggd: + name: Testing make_docs.yml on IMASggd + uses: ProjectTorreyPines/GitHubActionsWorkflows/.github/workflows/test_reusable_workflow.yml + secrets: inherit + with: + target_repo: ProjectTorreyPines/IMASggd.jl + workflow_file: make_docs.yml + ref: master + test_on_SOLPS2imas: + name: Testing make_docs.yml on SOLPS2imas + uses: ProjectTorreyPines/GitHubActionsWorkflows/.github/workflows/test_reusable_workflow.yml + secrets: inherit + with: + target_repo: ProjectTorreyPines/SOLPS2imas.jl + workflow_file: make_docs.yml + ref: master + test_on_FusionSyntheticDiagnostics: + name: Testing make_docs.yml on FusionSyntheticDiagnostics + uses: ProjectTorreyPines/GitHubActionsWorkflows/.github/workflows/test_reusable_workflow.yml + secrets: inherit + with: + target_repo: ProjectTorreyPines/FusionSyntheticDiagnostics.jl + workflow_file: make_docs.yml + ref: master diff --git a/.github/workflows/test_test.yml b/.github/workflows/test_test.yml index a129cd0..9ffa104 100644 --- a/.github/workflows/test_test.yml +++ b/.github/workflows/test_test.yml @@ -15,7 +15,7 @@ on: jobs: test_on_IMASggd: name: Testing test.yml on IMASggd - uses: ProjectTorreyPines/GitHubActionsWorkflows/.github/workflows/test_reusable_workflow.yml@test_workflows + uses: ProjectTorreyPines/GitHubActionsWorkflows/.github/workflows/test_reusable_workflow.yml secrets: inherit with: target_repo: ProjectTorreyPines/IMASggd.jl @@ -23,7 +23,7 @@ jobs: ref: master test_on_SOLPS2imas: name: Testing test.yml on SOLPS2imas - uses: ProjectTorreyPines/GitHubActionsWorkflows/.github/workflows/test_reusable_workflow.yml@test_workflows + uses: ProjectTorreyPines/GitHubActionsWorkflows/.github/workflows/test_reusable_workflow.yml secrets: inherit with: target_repo: ProjectTorreyPines/SOLPS2imas.jl @@ -31,7 +31,7 @@ jobs: ref: master test_on_FusionSyntheticDiagnostics: name: Testing test.yml on FusionSyntheticDiagnostics - uses: ProjectTorreyPines/GitHubActionsWorkflows/.github/workflows/test_reusable_workflow.yml@test_workflows + uses: ProjectTorreyPines/GitHubActionsWorkflows/.github/workflows/test_reusable_workflow.yml secrets: inherit with: target_repo: ProjectTorreyPines/FusionSyntheticDiagnostics.jl