Skip to content

Commit 8d2e52d

Browse files
committed
Skip Docker auth and push steps when secrets are unavailable
On fork pushes, secrets are not available but the event_name is "push" (not "pull_request"), so the existing guards don't prevent the Google auth step from running and failing. Add env.SERVICE_ACCOUNT != '' checks to all secret-dependent steps so they are skipped gracefully on forks.
1 parent bdc15be commit 8d2e52d

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

.github/workflows/main.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
- name: Google auth
5353
id: auth
5454
uses: 'google-github-actions/auth@v2'
55-
if: ${{ github.event_name != 'pull_request' }}
55+
if: ${{ github.event_name != 'pull_request' && env.SERVICE_ACCOUNT != '' }}
5656
with:
5757
token_format: 'access_token'
5858
project_id: ${{ env.PROJECT_ID }}
@@ -62,7 +62,7 @@ jobs:
6262
- name: Docker Auth
6363
id: docker-auth
6464
uses: 'docker/login-action@v3'
65-
if: ${{ github.event_name != 'pull_request' }}
65+
if: ${{ github.event_name != 'pull_request' && env.SERVICE_ACCOUNT != '' }}
6666
with:
6767
registry: gcr.io
6868
username: 'oauth2accesstoken'
@@ -73,19 +73,19 @@ jobs:
7373
uses: docker/build-push-action@v6
7474
with:
7575
platforms: ${{ matrix.platform }}
76-
outputs: type=image,name=gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }}
76+
outputs: type=image,name=gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' && env.SERVICE_ACCOUNT != '' }}
7777
cache-from: type=gha,scope=${{ matrix.runner }}
7878
cache-to: type=gha,scope=${{ matrix.runner }},mode=max
7979

8080
- name: Export digest
81-
if: ${{ github.event_name != 'pull_request' }}
81+
if: ${{ github.event_name != 'pull_request' && env.SERVICE_ACCOUNT != '' }}
8282
run: |
8383
mkdir -p /tmp/digests
8484
digest="${{ steps.build.outputs.digest }}"
8585
touch "/tmp/digests/${digest#sha256:}"
8686
8787
- name: Upload digest
88-
if: ${{ github.event_name != 'pull_request' }}
88+
if: ${{ github.event_name != 'pull_request' && env.SERVICE_ACCOUNT != '' }}
8989
uses: actions/upload-artifact@v4
9090
with:
9191
name: digests-${{ matrix.runner }}
@@ -96,7 +96,7 @@ jobs:
9696
docker-merge:
9797
name: Docker Merge
9898
runs-on: ubuntu-24.04
99-
if: ${{ github.event_name != 'pull_request' }}
99+
if: ${{ github.event_name != 'pull_request' && secrets.GCLOUD_SERVICE_ACCOUNT != '' }}
100100
needs: docker
101101
permissions:
102102
contents: 'read'

0 commit comments

Comments
 (0)