|
| 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 }} |
0 commit comments