-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
61 lines (48 loc) · 2.05 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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:
- 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 -r ${{ github.ref_name }} --json
else
gh workflow run $workflowFile -r ${{ github.ref_name }}
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 file=$workflowFile,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,title=The Dispatched workflow:: Completed successfully"
break
fi
fi
sleep 60
done