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_reusable_workflow.yml b/.github/workflows/test_reusable_workflow.yml new file mode 100644 index 0000000..241b898 --- /dev/null +++ b/.github/workflows/test_reusable_workflow.yml @@ -0,0 +1,151 @@ +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 }}..." + 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" \ + -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 3 # Sleep for a while to get the new workflow started + for ((i=0; i $trigger_time)) + | sort_by(.created_at) + | last + | .id + else empty end') + 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..9ffa104 --- /dev/null +++ b/.github/workflows/test_test.yml @@ -0,0 +1,39 @@ +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: + name: Testing test.yml on IMASggd + uses: ProjectTorreyPines/GitHubActionsWorkflows/.github/workflows/test_reusable_workflow.yml + secrets: inherit + with: + target_repo: ProjectTorreyPines/IMASggd.jl + workflow_file: test.yml + ref: master + test_on_SOLPS2imas: + name: Testing test.yml on SOLPS2imas + uses: ProjectTorreyPines/GitHubActionsWorkflows/.github/workflows/test_reusable_workflow.yml + 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 + secrets: inherit + with: + target_repo: ProjectTorreyPines/FusionSyntheticDiagnostics.jl + workflow_file: test.yml + ref: master 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: