Quite late to the party, but what about merging the jobs and adding the condition to the step?
jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- name build
run: echo "build"
- name test
if: ${{ github.ref_name == 'main' }}
run: echo "build"
- name deploy
run: echo "deploy"