From 72adb5561def7c84fc79a617fc839110fc51bb1d Mon Sep 17 00:00:00 2001 From: James Hillyerd Date: Sun, 12 Nov 2023 11:49:00 -0800 Subject: [PATCH] docker-build action: only push to registry on main branch and v* tag pushes (#426) --- .github/workflows/docker-build.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 1d1b18f..b06e904 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -11,6 +11,9 @@ on: - submitted workflow_dispatch: # allow for manual run +env: + REGISTRY_PUSH: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') }} + jobs: build: name: 'Build Container' @@ -44,14 +47,14 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Login to DockerHub - if: github.event_name != 'pull_request' + if: $REGISTRY_PUSH uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Login to GitHub Container Registry - if: github.event_name != 'pull_request' + if: $REGISTRY_PUSH uses: docker/login-action@v2 with: registry: ghcr.io @@ -63,6 +66,6 @@ jobs: with: context: . platforms: linux/amd64,linux/arm64, linux/arm/v7 - push: ${{ github.event_name != 'pull_request' }} + push: $REGISTRY_PUSH tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }}