forked from rodjek/puppet-lint
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from puppetlabs/cat_2090
(CAT-2090) - Add workflow-restarter and workflow-restarter-test to wo…
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: Workflow Restarter TEST | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
fail: | ||
description: > | ||
For (spec, acceptance) jobs: | ||
'true' = (fail, succeed) and | ||
'false' = (succeed, fail) | ||
required: true | ||
default: 'true' | ||
env: | ||
SOURCE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
jobs: | ||
spec: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check outcome | ||
run: | | ||
if [ "${{ github.event.inputs.fail }}" = "true" ]; then | ||
echo "'spec' job succeeded" | ||
exit 0 | ||
else | ||
echo "'spec' job failed" | ||
exit 1 | ||
fi | ||
acceptance: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check outcome | ||
run: | | ||
if [ "${{ github.event.inputs.fail }}" = "true" ]; then | ||
echo "'acceptance' job failed" | ||
exit 1 | ||
else | ||
echo "'acceptance' job succeeded" | ||
exit 0 | ||
fi | ||
on-failure-workflow-restarter-proxy: | ||
# (1) run this job after the "spec" job and... | ||
needs: [spec, acceptance] | ||
# (2) continue ONLY IF "spec" fails | ||
if: always() && needs.spec.result == 'failure' || needs.acceptance.result == 'failure' | ||
runs-on: ubuntu-latest | ||
steps: | ||
# (3) checkout this repository in order to "see" the following custom action | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
# (4) "use" the custom action to retrigger the failed "spec job" above | ||
# NOTE: pass the SOURCE_GITHUB_TOKEN to the custom action because (a) it must have | ||
# this to trigger the reusable workflow that restarts the failed job; and | ||
# (b) custom actions do not have access to the calling workflow's secrets | ||
- name: Trigger reusable workflow | ||
uses: "puppetlabs/cat-github-actions/.github/actions/workflow-restarter-proxy@main" | ||
env: | ||
SOURCE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
repository: ${{ github.repository }} | ||
run_id: ${{ github.run_id }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# target-repo/.github/workflows/call-reusable-workflow.yml | ||
name: Workflow Restarter | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
repo: | ||
description: "GitHub repository name." | ||
required: true | ||
type: string | ||
run_id: | ||
description: "The ID of the workflow run to rerun." | ||
required: true | ||
type: string | ||
retries: | ||
description: "The number of times to retry the workflow run." | ||
required: false | ||
type: string | ||
default: "3" | ||
|
||
jobs: | ||
call-reusable-workflow: | ||
uses: "puppetlabs/cat-github-actions/.github/workflows/workflow-restarter.yml@main" | ||
with: | ||
repo: ${{ inputs.repo }} | ||
run_id: ${{ inputs.run_id }} | ||
retries: ${{ inputs.retries }} |