Skip to content

Commit c075cca

Browse files
(CAT-2092) - Add workflow restarter
1 parent 29f141c commit c075cca

File tree

4 files changed

+138
-0
lines changed

4 files changed

+138
-0
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,4 @@ jobs:
7777
- name: Run tests
7878
run: |
7979
bundle exec rake spec
80+

.github/workflows/nightly.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,5 @@ jobs:
7575
- name: Run tests
7676
run: |
7777
bundle exec rake spec
78+
79+
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+
linux_tests:
18+
name: Linux, Puppet ${{ matrix.cfg.puppet_version }}, Ruby ${{ matrix.cfg.ruby }}
19+
runs-on: ubuntu-latest
20+
strategy:
21+
matrix:
22+
cfg:
23+
- {puppet_version: '7', ruby: '2.7'}
24+
- {puppet_version: '7', ruby: 'jruby-9.3.7.0'}
25+
- {puppet_version: '8', ruby: '3.2'}
26+
- {puppet_version: '8', ruby: 'jruby-9.4.2.0'}
27+
env:
28+
PUPPET_GEM_VERSION: ~> ${{ matrix.cfg.puppet_version }}
29+
steps:
30+
- name: Checkout current PR
31+
uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0
34+
- name: Install Ruby version ${{ matrix.cfg.ruby }}
35+
uses: ruby/setup-ruby@v1
36+
with:
37+
ruby-version: ${{ matrix.cfg.ruby }}
38+
- name: Update rubygems and install gems
39+
run: |
40+
bundle config set without development
41+
bundle install --jobs 4 --retry 3
42+
43+
- name: Rubocop
44+
run: |
45+
bundle exec rake rubocop
46+
47+
- name: Run tests
48+
run: |
49+
bundle exec rake spec
50+
51+
# Starting with version 3.2, Ruby no longer bundles libffi, which is necessary for tests on Windows. Due to a discrepancy between the C
52+
# library the Windows Puppet gem is built against and what GitHub runners use (MinGW and ucrt, respectively) we can't install the
53+
# Windows-specific Puppet gem that includes libffi. To work around these issues, we have a separate "integration" group that we include
54+
# when testing Puppet 8 / Ruby 3.2 on Windows. See PA-5406 for more.
55+
windows_tests:
56+
name: Windows, Puppet ${{ matrix.cfg.puppet_version }}, Ruby ${{ matrix.cfg.ruby }}
57+
runs-on: windows-latest
58+
strategy:
59+
matrix:
60+
cfg:
61+
- {puppet_version: '7', ruby: '2.7'}
62+
- {puppet_version: '8', ruby: '3.2', extra: 'bundle config set with integration'}
63+
env:
64+
PUPPET_GEM_VERSION: ~> ${{ matrix.cfg.puppet_version }}
65+
steps:
66+
- name: Checkout current PR
67+
uses: actions/checkout@v4
68+
with:
69+
fetch-depth: 0
70+
- name: Install Ruby version ${{ matrix.cfg.ruby }}
71+
uses: ruby/setup-ruby@v1
72+
with:
73+
ruby-version: ${{ matrix.cfg.ruby }}
74+
- name: Update rubygems and install gems
75+
run: |
76+
bundle config set without development
77+
${{ matrix.cfg.extra }}
78+
bundle install --jobs 4 --retry 3
79+
80+
- name: Rubocop
81+
run: |
82+
bundle exec rake rubocop
83+
84+
- name: Run tests
85+
run: |
86+
bundle exec rake spec
87+
88+
on-failure-workflow-restarter-proxy:
89+
# (1) run this job after the "acceptance" job and...
90+
needs: [linux_tests, windows_tests]
91+
# (2) continue ONLY IF "acceptance" fails
92+
if: always() && needs.linux_tests.result == 'failure' || needs.windows_tests.result == 'failure'
93+
runs-on: ubuntu-latest
94+
steps:
95+
# (3) checkout this repository in order to "see" the following custom action
96+
- name: Checkout repository
97+
uses: actions/checkout@v4
98+
99+
# (4) "use" the custom action to retrigger the failed "acceptance job" above
100+
# NOTE: pass the SOURCE_GITHUB_TOKEN to the custom action because (a) it must have
101+
# this to trigger the reusable workflow that restarts the failed job; and
102+
# (b) custom actions do not have access to the calling workflow's secrets
103+
- name: Trigger reusable workflow
104+
uses: "puppetlabs/cat-github-actions/.github/actions/workflow-restarter-proxy@main"
105+
env:
106+
SOURCE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107+
with:
108+
repository: ${{ github.repository }}
109+
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)