Skip to content

Commit

Permalink
(CAT-1820) - add resuable workflow job for rerunning acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danadoherty639 committed Sep 30, 2024
1 parent fc38a30 commit ab47efd
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 279 deletions.
88 changes: 0 additions & 88 deletions .github/actions/workflow-restarter-proxy/README.md

This file was deleted.

40 changes: 0 additions & 40 deletions .github/actions/workflow-restarter-proxy/action.yml

This file was deleted.

Binary file removed .github/actions/workflow-restarter-proxy/image-1.png
Binary file not shown.
Binary file removed .github/actions/workflow-restarter-proxy/image-2.png
Binary file not shown.
Binary file removed .github/actions/workflow-restarter-proxy/image-3.png
Binary file not shown.
Binary file removed .github/actions/workflow-restarter-proxy/image-4.png
Binary file not shown.
Binary file removed .github/actions/workflow-restarter-proxy/image.png
Binary file not shown.

This file was deleted.

This file was deleted.

29 changes: 26 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ on:
workflow_dispatch:

env:
# SOURCE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

jobs:

spec:
strategy:
fail-fast: false
Expand All @@ -28,7 +28,7 @@ jobs:
ruby_version: "3.2"
name: "spec (ruby ${{ matrix.ruby_version }})"
uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main"
secrets: "inherit"
secrets: inherit
with:
rake_task: 'spec:coverage'
ruby_version: ${{ matrix.ruby_version }}
Expand All @@ -52,9 +52,32 @@ jobs:
ruby_version: "3.2"
name: "acceptance (ruby ${{ matrix.ruby_version }} | ${{ matrix.os }})"
uses: "puppetlabs/cat-github-actions/.github/workflows/gem_acceptance.yml@main"
secrets: "inherit"
secrets: inherit
with:
ruby_version: ${{ matrix.ruby_version }}
puppet_version: ${{ matrix.puppet_gem_version }}
rake_task: 'acceptance:local'
runs_on: ${{ matrix.os }}

on-failure-workflow-restarter-proxy:
# (1) run this job after the "acceptance" job and...
needs: [acceptance]
# (2) continue ONLY IF "acceptance" fails
if: always() && 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 "acceptance 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 }}
5 changes: 4 additions & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
- cron: "0 0 * * *"
workflow_dispatch:

env:
SOURCE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:

spec:
Expand Down Expand Up @@ -68,7 +71,7 @@ jobs:
# 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: ./.github/actions/workflow-restarter-proxy
uses: "puppetlabs/cat-github-actions/.github/actions/workflow-restarter-proxy@main"
env:
SOURCE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/workflow-restarter-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ on:
'false' = (succeed, fail)
required: true
default: 'true'
env:
SOURCE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
unit:
Expand Down Expand Up @@ -53,7 +55,7 @@ jobs:
# 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: ./.github/actions/workflow-restarter-proxy
uses: "puppetlabs/cat-github-actions/.github/actions/workflow-restarter-proxy@main"
env:
SOURCE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
43 changes: 9 additions & 34 deletions .github/workflows/workflow-restarter.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
# target-repo/.github/workflows/call-reusable-workflow.yml
name: Workflow Restarter
on:
workflow_dispatch:
Expand All @@ -14,38 +14,13 @@ on:
retries:
description: "The number of times to retry the workflow run."
required: false
type: number
default: 3
secrets:
GITHUB_TOKEN:
required: true
type: string
default: "3"

jobs:
rerun:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Check retry count
id: check-retry
run: |
# IF `--attempts` returns a non-zero exit code, then keep retrying
status_code=$(gh run view ${{ inputs.run_id }} --repo ${{ inputs.repo }} --attempt ${{ inputs.retries }} --json status) || {
echo "Retry count is within limit"
echo "::set-output name=should_retry::true"
exit 0
}
# ELSE `--attempts` returns a zero exit code, so stop retrying
echo "Retry count has reached the limit"
echo "::set-output name=should_retry::false"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Re-run failed jobs
if: ${{ steps.check-retry.outputs.should_retry == 'true' }}
run: gh run rerun --failed ${{ inputs.run_id }} --repo ${{ inputs.repo }}
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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 }}

0 comments on commit ab47efd

Please sign in to comment.