Skip to content

Commit 3f9f45b

Browse files
feat(wait) Wait for completion
1 parent 827565b commit 3f9f45b

File tree

15 files changed

+12498
-7987
lines changed

15 files changed

+12498
-7987
lines changed

.github/workflows/build-test.yaml

Lines changed: 150 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,157 @@ jobs:
1111
steps:
1212
- name: Check out repository
1313
uses: actions/checkout@v2
14-
14+
- uses: actions/setup-node@v2
15+
with:
16+
node-version: '12'
1517
- name: Build with ncc
1618
run: |
17-
npm install
18-
npm run build
19+
npm install -g yarn
20+
yarn install
21+
yarn run build
22+
- name: Archive dist
23+
uses: actions/upload-artifact@v2
24+
with:
25+
name: build
26+
path: dist
1927

20-
- name: Invoke echo 1 workflow using this action
28+
echo-1-test:
29+
needs: [build]
30+
runs-on: ubuntu-latest
31+
name: "echo-1-test [trigger|by workflow name]"
32+
steps:
33+
- name: Check out repository
34+
uses: actions/checkout@v2
35+
- name: Download dist
36+
uses: actions/download-artifact@v2
37+
with:
38+
name: build
39+
path: dist
40+
- name: Invoke echo 1 workflow using this action (do not wait for completion)
2141
uses: ./
2242
with:
2343
workflow: Message Echo 1
2444
token: ${{ secrets.PERSONAL_TOKEN }}
2545
inputs: '{"message": "blah blah"}'
46+
wait-for-completion: false
2647

48+
echo-2-test:
49+
needs: [build]
50+
runs-on: ubuntu-latest
51+
name: "echo-2-test [trigger|by workflow filename]"
52+
steps:
53+
- name: Check out repository
54+
uses: actions/checkout@v2
55+
- name: Download dist
56+
uses: actions/download-artifact@v2
57+
with:
58+
name: build
59+
path: dist
2760
- name: Invoke echo 2 workflow using this action
2861
uses: ./
2962
with:
30-
workflow: Message Echo 2
63+
workflow: echo-2.yaml
3164
token: ${{ secrets.PERSONAL_TOKEN }}
65+
wait-for-completion: false
66+
67+
# - name: Invoke echo 1 workflow by id
68+
# uses: ./
69+
# with:
70+
# workflow: '1854247'
71+
# token: ${{ secrets.PERSONAL_TOKEN }}
72+
# inputs: '{"message": "Mango jam"}'
73+
# wait-for-completion: false
3274

33-
- name: Invoke echo 1 workflow by id
75+
long-running-test:
76+
needs: [build]
77+
runs-on: ubuntu-latest
78+
name: "long-running-test [trigger+wait|by workflow filename|shoud succeed]"
79+
steps:
80+
- name: Check out repository
81+
uses: actions/checkout@v2
82+
- name: Download dist
83+
uses: actions/download-artifact@v2
84+
with:
85+
name: build
86+
path: dist
87+
- name: Invoke 'long-running' workflow and wait for result using this action
88+
id: long-running-workflow
3489
uses: ./
3590
with:
36-
workflow: '1854247'
91+
workflow: long-running.yml
3792
token: ${{ secrets.PERSONAL_TOKEN }}
38-
inputs: '{"message": "Mango jam"}'
93+
wait-for-completion-interval: 10s
94+
wait-for-completion-timeout: 5m
95+
continue-on-error: true
96+
- uses: nick-invision/assert-action@v1
97+
with:
98+
expected: success
99+
actual: ${{ steps.long-running-workflow.outputs.workflow-conclusion }}
100+
- uses: nick-invision/assert-action@v1
101+
with:
102+
expected: success
103+
actual: ${{ steps.long-running-workflow.outcome }}
39104

40-
- name: Update repo with build
41-
uses: mikeal/publish-to-github-action@master
42-
env:
43-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
105+
failing-test:
106+
needs: [build]
107+
runs-on: ubuntu-latest
108+
name: "failing-test [trigger+wait|by workflow filename|shoud report failure]"
109+
steps:
110+
- name: Check out repository
111+
uses: actions/checkout@v2
112+
- name: Download dist
113+
uses: actions/download-artifact@v2
114+
with:
115+
name: build
116+
path: dist
117+
- name: Invoke 'failing' workflow and wait for result using this action
118+
id: failing-workflow
119+
uses: ./
120+
with:
121+
workflow: failing.yml
122+
token: ${{ secrets.PERSONAL_TOKEN }}
123+
wait-for-completion-interval: 10s
124+
wait-for-completion-timeout: 5m
125+
continue-on-error: true
126+
- run: echo "worflow-conclusion=${{ steps.failing-workflow.outputs.workflow-conclusion }}"
127+
- uses: nick-invision/assert-action@v1
128+
with:
129+
expected: failure
130+
actual: ${{ steps.failing-workflow.outputs.workflow-conclusion }}
131+
- uses: nick-invision/assert-action@v1
132+
with:
133+
expected: failure
134+
actual: ${{ steps.failing-workflow.outcome }}
135+
136+
timeout-test:
137+
needs: [build]
138+
runs-on: ubuntu-latest
139+
name: "timeout-test [trigger+wait|by workflow filename|shoud report timed_out]"
140+
steps:
141+
- name: Check out repository
142+
uses: actions/checkout@v2
143+
- name: Download dist
144+
uses: actions/download-artifact@v2
145+
with:
146+
name: build
147+
path: dist
148+
- name: Invoke 'timeout' workflow and wait for result using this action
149+
id: timeout-workflow
150+
uses: ./
151+
with:
152+
workflow: timeout.yml
153+
token: ${{ secrets.PERSONAL_TOKEN }}
154+
wait-for-completion-interval: 10s
155+
wait-for-completion-timeout: 30s
156+
continue-on-error: true
157+
- uses: nick-invision/assert-action@v1
158+
with:
159+
expected: timed_out
160+
actual: ${{ steps.timeout-workflow.outputs.workflow-conclusion }}
161+
- uses: nick-invision/assert-action@v1
162+
with:
163+
expected: failure
164+
actual: ${{ steps.timeout-workflow.outcome }}
44165

45166
# - name: Invoke external workflow using this action
46167
# uses: ./
@@ -49,4 +170,20 @@ jobs:
49170
# repo: benc-uk/dapr-store
50171
# token: ${{ secrets.PERSONAL_TOKEN }}
51172
# ref: master
52-
173+
174+
deploy:
175+
needs: [echo-1-test, echo-2-test, long-running-test, failing-test, timeout-test]
176+
runs-on: ubuntu-latest
177+
steps:
178+
- name: Check out repository
179+
uses: actions/checkout@v2
180+
- name: Download dist
181+
uses: actions/download-artifact@v2
182+
with:
183+
name: build
184+
path: dist
185+
- name: Update repo with build
186+
uses: mikeal/publish-to-github-action@master
187+
env:
188+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
189+

.github/workflows/failing.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Failing
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
echo:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Fail
11+
run: exit 1

.github/workflows/long-running.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Long running
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
echo:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Sleep
11+
run: sleep 10s

.github/workflows/timeout.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Timeout
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
wait:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Sleep
11+
run: sleep 1200s

README.md

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ For details of the `workflow_dispatch` even see [this blog post introducing this
1111

1212
*Note 2.* If you want to reference the target workflow by ID, you will need to list them with the following REST API call `curl https://api.github.com/repos/{{owner}}/{{repo}}/actions/workflows -H "Authorization: token {{pat-token}}"`
1313

14+
_This action is a fork of `benc-uk/workflow-dispatch` to add support for waiting for workflow completion._
15+
1416
## Inputs
1517
### `workflow`
16-
**Required.** The name or ID of the workflow to trigger and run. This is the name declared in the YAML, not the filename
18+
**Required.** The name or the filename or ID of the workflow to trigger and run.
1719

1820
### `token`
1921

@@ -30,23 +32,43 @@ The solution is to manually create a PAT and store it as a secret e.g. `${{ secr
3032
### `repo`
3133
**Optional.** The default behavior is to trigger workflows in the same repo as the triggering workflow, if you wish to trigger in another GitHub repo "externally", then provide the owner + repo name with slash between them e.g. `microsoft/vscode`
3234

35+
### `wait-for-completion`
36+
**Optional.** If `true`, this action will actively poll the workflow run to get the result of the triggered workflow. It is enabled by default. If the triggered workflow fails due to either `failure`, `timed_out` or `cancelled` then the step that has triggered the other workflow will be marked as failed too.
37+
38+
### `wait-for-completion-timeout`
39+
**Optional.** The time to wait to mark triggered workflow has timed out. The time must be suffixed by the time unit e.g. `10m`. Time unit can be `s` for seconds, `m` for minutes and `h` for hours. It has no effect if `wait-for-completion` is `false`. Default is `1h`
40+
41+
### `wait-for-completion-interval`
42+
**Optional.** The time to wait between two polls for getting run status. The time must be suffixed by the time unit e.g. `10m`. Time unit can be `s` for seconds, `m` for minutes and `h` for hours. It has no effect if `wait-for-completion` is `false`. Default is `30s`.
43+
**/!\ Do not use a value that is too small to avoid `API Rate limit exceeded`**
3344

3445
## Outputs
35-
None
46+
### `workflow-conclusion`
47+
The result of the triggered workflow. May be one of `success`, `failure`, `cancelled`, `timed_out`, `skipped`, `neutral`, `action_required`. The step in your workflow will fail if the triggered workflow completes with `failure`, `cancelled` or `timed_out`. Other workflow conlusion are considered success.
48+
Only available if `wait-for-completion` is `true`
3649

3750

3851
## Example usage
3952
```yaml
40-
- name: Invoke workflow without inputs
41-
uses: benc-uk/workflow-dispatch@v1
53+
- name: Invoke workflow without inputs. Wait for result
54+
uses: aurelien-baudet/workflow-dispatch@v2
4255
with:
4356
workflow: My Workflow
4457
token: ${{ secrets.PERSONAL_TOKEN }}
4558
```
4659
60+
```yaml
61+
- name: Invoke workflow without inputs. Don't wait for result
62+
uses: aurelien-baudet/workflow-dispatch@v2
63+
with:
64+
workflow: My Workflow
65+
token: ${{ secrets.PERSONAL_TOKEN }}
66+
wait-for-completion: false
67+
```
68+
4769
```yaml
4870
- name: Invoke workflow with inputs
49-
uses: benc-uk/workflow-dispatch@v1
71+
uses: aurelien-baudet/workflow-dispatch@v2
5072
with:
5173
workflow: Another Workflow
5274
token: ${{ secrets.PERSONAL_TOKEN }}
@@ -55,10 +77,22 @@ None
5577
5678
```yaml
5779
- name: Invoke workflow in another repo with inputs
58-
uses: benc-uk/workflow-dispatch@v1
80+
uses: aurelien-baudet/workflow-dispatch@v2
5981
with:
6082
workflow: Some Workflow
6183
repo: benc-uk/example
6284
token: ${{ secrets.PERSONAL_TOKEN }}
6385
inputs: '{ "message": "blah blah", "debug": true }'
6486
```
87+
88+
```yaml
89+
- name: Invoke workflow and handle result
90+
id: trigger-step
91+
uses: aurelien-baudet/workflow-dispatch@v2
92+
with:
93+
workflow: Another Workflow
94+
token: ${{ secrets.PERSONAL_TOKEN }}
95+
- name: Another step that can handle the result
96+
if: always()
97+
run: echo "Another Workflow conclusion: ${{ steps.trigger-step.outputs.workflow-conclusion }}"
98+
```

action.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,19 @@ inputs:
1616
required: false
1717
repo:
1818
description: 'Repo owner & name, slash separated, only set if invoking a workflow in a different repo'
19-
required: false
19+
required: false
20+
wait-for-completion:
21+
description: 'Block until the triggered workflow has finished'
22+
required: false
23+
default: true
24+
wait-for-completion-timeout:
25+
description: 'Maximum amount of time (+unit) to wait to mark workflow as timed out'
26+
required: false
27+
default: 1h
28+
wait-for-completion-interval:
29+
description: 'Time to wait (+unit) between two polls to get run status'
30+
required: false
31+
default: 30s
2032

2133
runs:
2234
using: 'node12'

0 commit comments

Comments
 (0)