<p>In a recent update you can now put <code>if</code> conditionals at <code>job</code> level. See the documentation here. <a href="https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idif">https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idif</a></p>
<p>I tested this workflow which runs the job <code>test</code> on every push, but only runs <code>deploy</code> on the master branch.</p>
<pre><code class="lang-auto">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
</code></pre>
<p>What follows is my original answer, and an alternative solution if you prefer to have separate workflows.</p>
<p>The first workflow runs for every branch except <code>master</code>. In this workflow you run tests only.</p>
<pre><code class="lang-auto">on:
push:
branches:
- '*'
- '!master'
</code></pre>
<p>The second workflow runs for just <code>master</code> and runs both your tests and deploys if the tests were successfully passed.</p>
<pre><code class="lang-auto">on:
push:
branches:
- master
</code></pre>