Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/test_format_check.yml
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions .github/workflows/test_make_docs.yml
Original file line number Diff line number Diff line change
@@ -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
151 changes: 151 additions & 0 deletions .github/workflows/test_reusable_workflow.yml
Original file line number Diff line number Diff line change
@@ -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<WAIT_ITER; i++)); do
set +e

RESPONSE=$(curl -s -H "Authorization: Bearer $GH_TOKEN" \
"https://api.github.com/repos/$OWNER/$REPO/actions/workflows/$WORKFLOW_FILE/runs?branch=$REF&event=workflow_dispatch")

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
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<RUN_ITER; i++)); do
# Temporarily disable exit-on-error
set +e

RESPONSE=$(curl -s -H "Authorization: Bearer $GH_TOKEN" \
"https://api.github.com/repos/$OWNER/$REPO/actions/runs/$RUN_ID")

STATUS=$(echo "$RESPONSE" | jq -r '.status' 2>/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
39 changes: 39 additions & 0 deletions .github/workflows/test_test.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions samples/format_check.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Format Check

on:
workflow_dispatch: # Manually trigger
push:
branches: ["master", "dev"]
paths:
Expand Down
1 change: 1 addition & 0 deletions samples/make_docs.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Make Docs
on:
workflow_dispatch: # Manually trigger
push:
branches: ["master", "dev"]
paths:
Expand Down
1 change: 1 addition & 0 deletions samples/release_data.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Release Data

on:
workflow_dispatch: # Manually trigger
push:
branches: ["master"]

Expand Down
1 change: 1 addition & 0 deletions samples/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Test

on:
workflow_dispatch: # Manually trigger
push:
branches: ["master", "dev"]
paths:
Expand Down