-
-
Save andyfeller/7cf991f5f086ba1ccda5971fb590cf2f to your computer and use it in GitHub Desktop.
| name: fail | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| fail: | |
| description: whether to fail the workflow | |
| type: boolean | |
| default: false | |
| jobs: | |
| fail: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Intentional fail | |
| if: ${{ github.event.inputs.fail == 'true' }} | |
| run: | | |
| bash -c 'exit 1' | |
| - name: Success | |
| run: | | |
| echo 'Success!' |
| name: retrigger-fail | |
| on: | |
| workflow_run: | |
| workflows: ["fail"] | |
| types: [completed] | |
| jobs: | |
| on-failure: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'failure' }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v2 | |
| - name: Retrigger workflow without fail condition | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GH_CLI_TOKEN }} | |
| run: | | |
| gh workflow run fail --ref ${{ github.ref_name }} --field fail=false |
${{ secrets.GH_CLI_TOKEN }}is a Personal Access Token (PAT)?
@dennisroche : yeah it is. there used to be a restriction of GitHub Action workflows that you couldn't trigger workflows based from the automatic token generated for the workflow, however I'm not seeing that limitation anymore within https://docs.github.com/en/enterprise-cloud@latest/actions/using-workflows/events-that-trigger-workflows#workflow_run
It seems like they have limited nesting of calls 🤷
that restriction is still unfortunately in place.
events triggered by the
GITHUB_TOKENwill not create a new workflow run
this limits actions from pushing a commit with generated files or automatic fixes 😢. github support linked me this gist as a possible workaround.
Adding a note as https://github.blog/changelog/2022-09-08-github-actions-use-github_token-with-workflow_dispatch-and-repository_dispatch/ came out after this gist was created where the GitHub Actions automatic token can be used for triggering workflow and repository dispatch events
${{ secrets.GH_CLI_TOKEN }}is a Personal Access Token (PAT)?