Workflow_run completed event triggered by failed workflow

I have a workflow triggered as follows:

name: Production deploy
on:
  workflow_run:
    workflows: ["Stage deploy"]
    types:
      - completed

I expect that after the stage deploy (which also runs API tests) completes successfully, then the production deploy would start. However, I just watched a failed stage deploy (which skipped its API tests due to the failed deploy) also trigger a production deploy. Is there a different “types” value for workflow_run that causes it not to fire if the workflow failed, rather than completed successfully?

3 Likes

@cuporter,

Currently, there are only the two types requested and completed for the workflow_run event.

As a workaround, you can use the expression “github.event.workflow_run.conclusion” to get the result of the previous workflow run, and use the job 's if conditional to skip all the job in the current workflow run when the previous workflow run is not success.

name: Production deploy
on:
  workflow_run:
    workflows: ["Stage deploy"]
    types:
      - completed

jobs:
  job1:
    if: ${{ github.event.workflow_run.conclusion == 'success' }}

  job2:
    if: ${{ github.event.workflow_run.conclusion == 'success' }}

    . . .

  jobN:
    if: ${{ github.event.workflow_run.conclusion == 'success' }}

Of course, you also can directly report a feature request that add more types for the workflow_run event (such as success and failure) here.
That will allow you to directly interact with the appropriate engineering team, and make it more convenient for the engineering team to collect and categorize your suggestions.

7 Likes

how do you use github.event.workflow_run.conclusion == 'success' when you have multiples workflows?

name: Production deploy
on:
  workflow_run:
    workflows: ["CI", "Linters"]
    types:
      - completed
1 Like

@edudepetris I assume that both CI and Linters both trigger separate workflow_run events, i.e. you only see a single conclusion, from one of the parent workflows. You may want to verify this with e.g.

name: Production deploy
on:
  workflow_run:
    workflows: ["CI", "Linters"]
    types:
      - completed
jobs:
  test:
    name: Test
    runs-on: ubuntu-latest
    steps:
      - name: Print github context
        env:
          GITHUB_CONTEXT: ${{ toJSON(github) }}
        run: echo "$GITHUB_CONTEXT"

If I’m right, then it might not be possible to wait for both parent workflows to succeed and then run the production deployment, unless you let Linters trigger CI and then let CI trigger Production deploy…

@brightran your suggestion works great, however, it is not documented in the webhook events docs: https://docs.github.com/en/free-pro-team@latest/developers/webhooks-and-events/webhook-events-and-payloads#workflow_run

I wonder if this property is authoritative, or will be removed in the future?

1 Like

How was this ever considered useful or fit for production use in it’s current form?
Triggering workflows on completion regardless of status is so naïve, it has no applicability in the real world

The workaround, aside from being ugly and error prone, still results in the workflow being triggered so you end up with hundreds of skipped runs when you look at the UI

5 Likes