Skip to content

Commit 0101515

Browse files
MatteoMoriclaude
andcommitted
ci: only build and push on version tags, not main branch
Changed workflow to only trigger on version tags (v*.*.*). PRs still trigger for validation (build only, no push). Workflow behavior: - Push to main: No action - Push tag v1.2.3: Build and push to DockerHub - Open PR: Build only (validation) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 9c8e50f commit 0101515

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

.github/workflows/build-and-push.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ name: Build and Push Docker Image
22

33
on:
44
push:
5-
branches:
6-
- main
75
tags:
8-
- 'v*.*.*' # Triggers on version tags like v1.0.0, v1.2.3, etc.
6+
- 'v*.*.*' # Only trigger on version tags like v1.0.0, v1.2.3, etc.
97
pull_request:
108
branches:
119
- main
@@ -37,7 +35,7 @@ jobs:
3735
uses: docker/setup-buildx-action@v3
3836

3937
- name: Log in to DockerHub
40-
if: github.event_name != 'pull_request'
38+
if: startsWith(github.ref, 'refs/tags/v')
4139
uses: docker/login-action@v3
4240
with:
4341
username: ${{ secrets.DOCKERHUB_USERNAME }}
@@ -69,15 +67,15 @@ jobs:
6967
uses: docker/build-push-action@v5
7068
with:
7169
context: .
72-
push: ${{ github.event_name != 'pull_request' }}
70+
push: ${{ startsWith(github.ref, 'refs/tags/v') }}
7371
tags: ${{ steps.meta.outputs.tags }}
7472
labels: ${{ steps.meta.outputs.labels }}
7573
cache-from: type=gha
7674
cache-to: type=gha,mode=max
7775
platforms: linux/amd64
7876

7977
- name: Generate artifact attestation
80-
if: github.event_name != 'pull_request'
78+
if: startsWith(github.ref, 'refs/tags/v')
8179
uses: actions/attest-build-provenance@v1
8280
with:
8381
subject-name: ${{ env.DOCKER_IMAGE }}

0 commit comments

Comments
 (0)