Github workflow not triggering on conditional branch name

Viewed 27

I have a job that I want to trigger for branches named feat/<something>, but I can't make it work.

If I name a branch feat and remove the / it works, but if I use feat/test it won't trigger

jobs:
  deploy_dev:
    if: github.event_name == 'push' && contains(github.ref_name, 'feat/')
    name: Deploy dev
    uses: ./.github/workflows/deploy-react.yml
    secrets:
      aws_role: ${{ secrets.AWS_ROLE_DEV }}
      s3_bucket: ${{ secrets.S3_BUCKET_APP_DEV }}
      cloudfront_id: ${{ secrets.CLOUDFRONT_APP_DEV }}
      aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
      aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
1 Answers

Test first if the alternative using filter would work better:

on:
  push:
    branches:
      - 'feat/**'

That way, no need to test github.event_name and github.ref_name.

Related