Skip to content

Commit 88e2fcb

Browse files
Merge pull request #115 from puppetlabs/maint_update_docs
Update workflow restarter documentation
2 parents 0732075 + 0b835de commit 88e2fcb

File tree

8 files changed

+99
-44
lines changed

8 files changed

+99
-44
lines changed

docs/workflow-restarter.md

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,13 @@ If setting up the the `workflow-restarter` for the first time, then make sure to
1212

1313
### Initialize the `Workflow Restarter`
1414

15-
First, configure the `workflow-restarter-proxy` custom action by creating a `workflow-restarter.yml` file beneath the `.github/workflows` directory in your repository.
15+
In order to begin using the workflow-restarter, you need to first raise a PR and add the workflow restarter to your target repository. In other words,
1616

17-
Second, configure the `workflow-restarter` re-usable workflow:
17+
* Copy [workflow-restarter.yml](./workflow-restarter/workflow-restarter.yml) and [workflow-restarter-test.yml](./workflow-restarter/workflow-restarter-test.yml) to the `.github/workflows` directory of your target directory.
18+
* Raise and merge a PR adding the above to the main branch of your repository.
19+
* Verify that the `Workflow Restarter TEST` workflow works as expected. See the [Appendix](#verify-workflow-restarter-with-workflow-restarter-test) for more information on what you should expect to see.
1820

19-
```yaml
20-
name: Workflow Restarter
21-
on:
22-
workflow_dispatch:
23-
inputs:
24-
repo:
25-
description: "GitHub repository name."
26-
required: true
27-
type: string
28-
run_id:
29-
description: "The ID of the workflow run to rerun."
30-
required: true
31-
type: string
32-
retries:
33-
description: "The number of times to retry the workflow run."
34-
required: false
35-
type: string
36-
default: "3"
37-
38-
jobs:
39-
call-reusable-workflow:
40-
uses: "puppetlabs/cat-github-actions/.github/workflows/workflow-restarter.yml@main"
41-
with:
42-
repo: ${{ inputs.repo }}
43-
run_id: ${{ inputs.run_id }}
44-
retries: ${{ inputs.retries }}
45-
```
46-
47-
Finally, verify that the `workflow-restarter.yml` performs as expected:
48-
1. Add a `workflow-restarter-test.yml` file to `.github/workflows`, copy the contents of `./github/workflows/workflow-restarter-test` from this repository
49-
2. Kick off the `workflow-restarter-test` and it should fail and be re-started 3 times. For example output see the [appendix below](#verify-workflow-restarter-with-workflow-restarter-test).
50-
51-
### Configure an existing workflow to use `on-failure-workflow-restarter`
52-
53-
Now add something like the following `yaml` job at the end of your workflow, changing only the `needs` section to suit.
54-
55-
For example, the following will trigger a restart if either the `acceptance` or the `unit` jobs preceeding it fail. A restart of the failing jobs will be attempted 3 times at which point if the failing jobs continue to fail, then the workflow will be marked as failed. If, however, at any point the `acceptance` and `unit` both pass fine then the restarted workflow will be marked as successful
21+
Once the above `Workflow Restarter TEST` is working then you should be able to add the workflow restarter to any of your existing github workflows. The key is to re-use the `on-failure-workflow-restarter-proxy` located in the `Workflow Restarter TEST`. For example, the following will trigger a restart if either the `acceptance` or the `unit` jobs preceeding it fail. A restart of the failing jobs will be attempted 3 times at which point if the failing jobs continue to fail, then the workflow will be marked as failed. If, however, at any point the `acceptance` and `unit` both pass fine then the restarted workflow will be marked as successful
5622

5723
```yaml
5824
on-failure-workflow-restarter-proxy:
@@ -82,22 +48,22 @@ For example, the following will trigger a restart if either the `acceptance` or
8248

8349
The following shows 3 `Workflow Restarter` occuring after the `Workflow Restarter TEST`, which is set to fail continuously.
8450

85-
![alt text](image.png)
51+
![alt text](./workflow-restarter/image.png)
8652

8753
Looking closer at the `Workflow Restarter TEST` reveals
8854

8955
* that the workflow includes 2 jobs `unit` and `acceptance`; and
9056
* that the workflow has been re-run 3 times, e.g.,
9157

92-
![alt text](image-1.png)
58+
![alt text](./workflow-restarter/image-1.png)
9359

9460
Further, the following sequence of screenshots shows that only failed jobs are re-run.
9561

9662
* The `on-failure-workflow-restarter` job **(1)** is triggered by the failure of the `unit` job and **(2)** successfully calls the `workflow-restarter` workflow
9763
* The `workflow-restarter` in turn triggers a re-run of the `unit` job **(3)** and the `Workflow Restarter TEST` shows this as an incremented attempt count at **(4)**.
9864

99-
![alt text](image-2.png)
65+
![alt text](./workflow-restarter/image-2.png)
10066

101-
![alt text](image-3.png)
67+
![alt text](./workflow-restarter/image-3.png)
10268

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

0 commit comments

Comments
 (0)