Skip to content

Commit 2f3df81

Browse files
add workdlow restrater trigger
1 parent d79c0d4 commit 2f3df81

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Workflow Restarter TEST
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
fail:
7+
description: >
8+
For (acceptance, unit) jobs:
9+
'true' = (fail, succeed) and
10+
'false' = (succeed, fail)
11+
required: true
12+
default: 'true'
13+
14+
jobs:
15+
unit:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Check outcome
19+
run: |
20+
if [ "${{ github.event.inputs.fail }}" = "true" ]; then
21+
echo "'unit' job succeeded"
22+
exit 0
23+
else
24+
echo "'unit' job failed"
25+
exit 1
26+
fi
27+
acceptance:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Check outcome
31+
run: |
32+
if [ "${{ github.event.inputs.fail }}" = "true" ]; then
33+
echo "'acceptance' job failed"
34+
exit 1
35+
else
36+
echo "'acceptance' job succeeded"
37+
exit 0
38+
fi
39+
40+
on-failure-workflow-restarter-proxy:
41+
# (1) run this job after the "acceptance" job and...
42+
needs: [acceptance, unit]
43+
# (2) continue ONLY IF "acceptance" fails
44+
if: always() && needs.acceptance.result == 'failure' || needs.unit.result == 'failure'
45+
runs-on: ubuntu-latest
46+
steps:
47+
# (3) checkout this repository in order to "see" the following custom action
48+
- name: Checkout repository
49+
uses: actions/checkout@v4
50+
51+
# (4) "use" the custom action to retrigger the failed "acceptance job" above
52+
# NOTE: pass the SOURCE_GITHUB_TOKEN to the custom action because (a) it must have
53+
# this to trigger the reusable workflow that restarts the failed job; and
54+
# (b) custom actions do not have access to the calling workflow's secrets
55+
- name: Trigger reusable workflow
56+
uses: ./.github/actions/workflow-restarter-proxy
57+
env:
58+
SOURCE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
with:
60+
repository: ${{ github.repository }}
61+
run_id: ${{ github.run_id }}

0 commit comments

Comments
 (0)