-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathaction.yml
More file actions
51 lines (43 loc) · 1.87 KB
/
Copy pathaction.yml
File metadata and controls
51 lines (43 loc) · 1.87 KB
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
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
runUrl=$(echo '${{ inputs.inputs }}' | gh workflow run $workflowFile -r ${{ github.ref_name }} --json)
else
runUrl=$(gh workflow run $workflowFile -r ${{ github.ref_name }})
fi
# `gh workflow run` (gh CLI >= 2.87.0) prints the created run URL when the host returns it.
# Older gh/GHES hosts return nothing here, so fall back to locating the run by dispatch time.
if [ -z "$runUrl" ]; then
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')
runUrl=$(gh api repos/$GITHUB_REPOSITORY/actions/runs/$currentWorkflowRunId --jq '.html_url')
else
currentWorkflowRunId=${runUrl##*/}
fi
echo "::notice file=$workflowFile,title=Dispatched workflow run::$runUrl"
if ! gh run watch $currentWorkflowRunId --exit-status; then
echo "::error file=$workflowFile::The Dispatched workflow has not completed successfully"
exit 1
fi
echo "::notice file=$workflowFile,title=The Dispatched workflow:: Completed successfully"