diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 52b9359..6a81936 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -21,8 +21,20 @@ env: jobs: - build: + # Publish gate: the test suite must pass before an image is built and pushed + # on master or a release tag. Pull requests already run test.yml directly and + # only build here without pushing, so the suite is skipped for them. + tests: + if: github.event_name != 'pull_request' + permissions: + contents: read + uses: ./.github/workflows/test.yml + build: + needs: tests + # A skipped `tests` job (pull requests) would skip `build` as well, hence + # the explicit condition. Failed or cancelled tests never publish. + if: ${{ !cancelled() && (github.event_name == 'pull_request' || needs.tests.result == 'success') }} runs-on: ubuntu-latest permissions: contents: read diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fa278d5..b528dff 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,11 +1,12 @@ name: Test +# Pull requests run this workflow directly. Pushes to master and v*.*.* tags run +# it as the gate of docker-publish.yml (workflow_call), so the suite runs exactly +# once per event and an image is never published without it. on: - push: - branches: [ "master" ] - tags: [ "v*.*.*" ] pull_request: branches: [ "master" ] + workflow_call: permissions: contents: read