Running steps on workflow reject

Hi,

I have a workflow that requires manual approval. I modelled this using environments and environment protection rules as detailed in the documentation at Reviewing deployments - GitHub Docs

Now when a deployment is rejected by the approver, I need to run a couple of steps such as “send an email” or do some cleanup. From the documentation and going through google search, I cant see an example or steps that help me do that. Does anyone know how to do this?

Thanks a lot for your help.

That’s an interesting question… Did you check whether the workflow_run trigger works in such a case? I would be surprised if it did, however, because the rejected workflow never runs.

Thanks a lot @Simran-B . I checked this solution. The workflow_run trigger is exciting, but does not work in my case. In either of “the approval being rejected” as well as “the job failing”, in both cases, the github.event.workflow_run.conclusion is set to “failure”. If atleast during the rejection of the workflow, if the conclusion was set to “cancelled”, instead of failure, my work would have been done.

Thanks for the pointer though.

My main workflow that has an environment protection rule set for “ci”, that results in an approval request

name: XXX
on:
  push:
    branches:
    - main
jobs:
  tag:
    environment: ci
    runs-on: ubuntu-latest
    name: tag
    steps:
    - name: Debug info
      run: echo "Github ref = ${{ github.ref }}"

And my workflow that tries to look at the conclusion of that workflow.

name: Rejected workflow
on:
  workflow_run:
    workflows: ["XXX"]
    branches: [main]
    types: 
      - completed
jobs:
  on-success:
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    steps:
      - name: Success flow
        run: echo success
  on-failure:
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'failure' }}
    steps:
      - name: Failure flow
        run: echo failed
  on-cancelled:
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'cancelled' }}
    steps:
      - name: Cancellation flow
        run: echo cancelled
1 Like