-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
actions\spring-dispatch-workflow-and-wait
* Modify `test-call-workflow-and-wait.yml` to test this action * Add an optional input for the `test-other-workflow-to-call.yml`
- Loading branch information
1 parent
2fba991
commit a01a65d
Showing
3 changed files
with
93 additions
and
36 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
.github/actions/spring-dispatch-workflow-and-wait/action.yml
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,66 @@ | ||
name: Dispatch another workflow and wait for its completion | ||
|
||
description: 'Dispatch another workflow and wait for its completion' | ||
|
||
inputs: | ||
workflow: | ||
description: 'The workflow YAML file name to call' | ||
required: true | ||
token: | ||
description: 'A GitHub token for gh api calls' | ||
required: true | ||
inputs: | ||
description: 'The target workflow input in JSON format' | ||
required: false | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
|
||
- uses: actions/checkout@v4 | ||
with: | ||
show-progress: false | ||
|
||
- name: Dispatch workflow and wait | ||
shell: bash | ||
env: | ||
GH_TOKEN: ${{ inputs.token }} | ||
run: | | ||
dispatchDate=$(date -Iseconds) | ||
workflowFile=${{ inputs.workflow }} | ||
if [ '${{ inputs.inputs }}' ]; then | ||
echo '${{ inputs.inputs }}' | gh workflow run $workflowFile --json | ||
else | ||
gh workflow run $workflowFile | ||
fi | ||
sleep 60 | ||
run_data=$(gh api repos/$GITHUB_REPOSITORY/actions/workflows/$workflowFile/runs?event=workflow_dispatch&created=>=$dispatchDate) | ||
currentWorkflowRunId=$(echo "$run_data" | jq -r '.workflow_runs[0].id') | ||
run_data=$(gh api repos/$GITHUB_REPOSITORY/actions/runs/$currentWorkflowRunId) | ||
currentWorkflowRunUrl=$(echo "$run_data" | jq -r '.html_url') | ||
echo "::notice title=Dispatched workflow run::$currentWorkflowRunUrl" | ||
while true; do | ||
run_data=$(gh api repos/$GITHUB_REPOSITORY/actions/runs/$currentWorkflowRunId) | ||
status=$(echo "$run_data" | jq -r '.status') | ||
if [ $status = "completed" ]; then | ||
conclusion=$(echo "$run_data" | jq -r '.conclusion') | ||
if [ $conclusion != "success" ]; then | ||
echo "::error file=$workflowFile::The Dispatched workflow has not completed successfully" | ||
exit 1 | ||
else | ||
echo "::notice file=$workflowFile::The Dispatched workflow completed successfully" | ||
break | ||
fi | ||
fi | ||
sleep 60 | ||
done |
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
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