In a recent update you can now put if
conditionals at job
level. See the documentation here. https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idif
I tested this workflow which runs the job test
on every push, but only runs deploy
on the master branch.
name: my workflow
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Execute tests
run: exit 0
deploy:
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/master'
steps:
- name: Deploy app
run: exit 0
What follows is my original answer, and an alternative solution if you prefer to have separate workflows.
The first workflow runs for every branch except master
. In this workflow you run tests only.
on:
push:
branches:
- '*'
- '!master'
The second workflow runs for just master
and runs both your tests and deploys if the tests were successfully passed.
on:
push:
branches:
- master