@@ -3,14 +3,21 @@ name: Build and Push Docker Image
33on :
44 push :
55 branches :
6- - main
7- - master
6+ - dev # Only auto-build on dev branch
87 tags :
9- - ' v*'
8+ - ' v*' # Still allow tagged releases
109 pull_request :
1110 branches :
1211 - main
1312 - master
13+ - dev
14+ workflow_dispatch : # Allow manual triggering
15+ inputs :
16+ force_push :
17+ description : ' Force push to registries (even from main branch)'
18+ required : false
19+ default : false
20+ type : boolean
1421
1522permissions :
1623 contents : read
@@ -47,15 +54,15 @@ jobs:
4754
4855 # Login to DockerHub
4956 - name : Login to DockerHub
50- if : github.event_name != 'pull_request'
57+ if : github.event_name != 'pull_request' && (github.ref != 'refs/heads/main' || github.event.inputs.force_push == 'true' || startsWith(github.ref, 'refs/tags/'))
5158 uses : docker/login-action@v3
5259 with :
5360 username : ${{ secrets.DOCKERHUB_USERNAME }}
5461 password : ${{ secrets.DOCKERHUB_PASSWORD }}
5562
5663 # Login to GitHub Container Registry
5764 - name : Login to GitHub Container Registry
58- if : github.event_name != 'pull_request'
65+ if : github.event_name != 'pull_request' && (github.ref != 'refs/heads/main' || github.event.inputs.force_push == 'true' || startsWith(github.ref, 'refs/tags/'))
5966 uses : docker/login-action@v3
6067 with :
6168 registry : ghcr.io
6875 with :
6976 context : .
7077 platforms : linux/amd64,linux/arm64
71- push : ${{ github.event_name != 'pull_request' }}
78+ # Only push if not a PR AND (not main branch OR manual force OR tagged release)
79+ push : ${{ github.event_name != 'pull_request' && (github.ref != 'refs/heads/main' || github.event.inputs.force_push == 'true' || startsWith(github.ref, 'refs/tags/')) }}
7280 tags : ${{ steps.meta.outputs.tags }}
7381 labels : ${{ steps.meta.outputs.labels }}
7482 cache-from : type=gha
0 commit comments