Defer container building for conditional step

Hi,

(I’m a relatively new GitHub Actions user)

On our CI workflow we have a Slack notification to report failures on push events. The workflow however runs on both pushes and PRs.

I noticed building the container is redundant 9/10. Defacto for PRs, but also on pushes ideally i’d build the container on, well, failure.

on:
    push:
        branches: [ master, develop, release/* ]
    pull_request:
jobs:
    some:
        runs-on: ubuntu-latest
        steps:

# <snip>

            -
                uses: ravsamhq/notify-slack-action@v1
                if: ${{ failure() && github.event_name == 'push' }}

Basically, is there a way to improve it? Or should we live with it?

image
image

this is the annoying part :slight_smile:

If you run the slack action inside a local composite action, you can delay building the image.

Alternativly this should work, this action creates a temporary local action (which allows some conditionals in composite actions)

- uses: ChristopherHX/conditional@b4a9649204f81002ec9a4ef7d4bf7d6b2ab7fa55
  if: ${{ failure() && github.event_name == 'push' }}
  with:
    step: |
      uses: ravsamhq/notify-slack-action@v1
1 Like