@@ -3,64 +3,154 @@ name: Container
33on :
44 push :
55 branches :
6- - ' main'
6+ - main
77 tags :
88 - ' v*'
99 workflow_run :
10- workflows : [ Releaser ]
10+ workflows : [Releaser]
1111 types :
1212 - completed
1313 pull_request :
1414
15+ concurrency :
16+ group : ${{ github.workflow }}-${{ github.ref }}
17+ cancel-in-progress : true
18+
19+ env :
20+ REGISTRY : ghcr.io
21+ IMAGE_NAME : ${{ github.repository }}
22+
1523jobs :
24+ # PR Build Check - validate Dockerfile compiles, single platform, no push
25+ build-check :
26+ if : github.event_name == 'pull_request'
27+ name : Build Check
28+ runs-on : ubuntu-latest
29+ steps :
30+ - name : Checkout
31+ uses : actions/checkout@v4
32+
33+ - name : Set up Docker Buildx
34+ uses : docker/setup-buildx-action@v3
35+
36+ - name : Build (amd64 only, no push)
37+ uses : docker/build-push-action@v6
38+ with :
39+ context : .
40+ push : false
41+ platforms : linux/amd64
42+ cache-from : type=gha
43+
44+ # Prepare ref for Releaser workflow integration
1645 prepare-checkout :
17- if : github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success'
46+ if : github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success'
1847 name : Prepare ref
1948 runs-on : ubuntu-latest
2049 outputs :
21- ref : ${{ github.event_name != 'workflow_run' && github.ref || steps.releaser.outputs.version }}
50+ ref : ${{ steps.releaser.outputs.version }}
2251 steps :
23- - name : Get Ref from releaser
52+ - name : Get ref from Releaser
2453 id : releaser
25- if : github.event_name == 'workflow_run'
2654 uses : ipdxco/unified-github-workflows/.github/actions/inspect-releaser@v1.0
2755 with :
2856 artifacts-url : ${{ github.event.workflow_run.artifacts_url }}
29- publish :
30- name : Publish
31- needs : [ prepare-checkout ]
57+
58+ # Publish on push to main branch
59+ publish-main :
60+ if : github.event_name == 'push' && github.ref == 'refs/heads/main'
61+ name : Publish (main)
3262 runs-on : ubuntu-latest
3363 permissions :
3464 contents : read
3565 packages : write
3666 steps :
3767 - name : Checkout
38- uses : actions/checkout@v3
39- with :
40- ref : ${{ needs.prepare-checkout.outputs.ref }}
68+ uses : actions/checkout@v4
69+
4170 - name : Set up Docker Buildx
42- uses : docker/setup-buildx-action@v2
43- - name : Log in to the Container registry
44- uses : docker/login-action@v2
71+ uses : docker/setup-buildx-action@v3
72+
73+ - name : Log in to Container registry
74+ uses : docker/login-action@v3
4575 with :
46- registry : ghcr.io
76+ registry : ${{ env.REGISTRY }}
4777 username : ${{ github.actor }}
48- password : ${{ github.token }}
78+ password : ${{ secrets.GITHUB_TOKEN }}
79+
4980 - name : Extract metadata
5081 id : meta
51- uses : docker/metadata-action@v4
82+ uses : docker/metadata-action@v5
5283 with :
53- images : ghcr.io /${{ github.repository }}
84+ images : ${{ env.REGISTRY }} /${{ env.IMAGE_NAME }}
5485 tags : |
55- type=semver,pattern={{raw}}
56- type=ref,event=branch
57- type=raw,value=${{ needs.prepare-checkout.outputs.ref }}
58- - name : Build and push Docker image
59- uses : docker/build-push-action@v4
86+ type=raw,value=main
87+ type=sha,prefix=sha-,format=short
88+
89+ - name : Build and push
90+ uses : docker/build-push-action@v6
6091 with :
6192 context : .
93+ push : true
94+ platforms : linux/amd64,linux/arm64
95+ tags : ${{ steps.meta.outputs.tags }}
96+ labels : ${{ steps.meta.outputs.labels }}
6297 cache-from : type=gha
6398 cache-to : type=gha,mode=max
64- push : ${{ github.event_name != 'pull_request' }}
99+
100+ # Publish on release tag (v*) - direct push or via Releaser
101+ publish-release :
102+ name : Publish (release)
103+ needs : [prepare-checkout]
104+ # Run if: direct tag push OR workflow_run completed successfully
105+ # always() allows running even when prepare-checkout was skipped (direct tag push)
106+ if : |
107+ always() && !cancelled() && !failure() &&
108+ ((github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) ||
109+ (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success'))
110+ runs-on : ubuntu-latest
111+ permissions :
112+ contents : read
113+ packages : write
114+ steps :
115+ - name : Determine ref
116+ id : ref
117+ run : |
118+ if [ "${{ github.event_name }}" = "workflow_run" ]; then
119+ echo "ref=${{ needs.prepare-checkout.outputs.ref }}" >> $GITHUB_OUTPUT
120+ else
121+ echo "ref=${{ github.ref }}" >> $GITHUB_OUTPUT
122+ fi
123+
124+ - name : Checkout
125+ uses : actions/checkout@v4
126+ with :
127+ ref : ${{ steps.ref.outputs.ref }}
128+
129+ - name : Set up Docker Buildx
130+ uses : docker/setup-buildx-action@v3
131+
132+ - name : Log in to Container registry
133+ uses : docker/login-action@v3
134+ with :
135+ registry : ${{ env.REGISTRY }}
136+ username : ${{ github.actor }}
137+ password : ${{ secrets.GITHUB_TOKEN }}
138+
139+ - name : Extract metadata
140+ id : meta
141+ uses : docker/metadata-action@v5
142+ with :
143+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
144+ tags : |
145+ type=semver,pattern={{version}}
146+
147+ - name : Build and push
148+ uses : docker/build-push-action@v6
149+ with :
150+ context : .
151+ push : true
152+ platforms : linux/amd64,linux/arm64
65153 tags : ${{ steps.meta.outputs.tags }}
66154 labels : ${{ steps.meta.outputs.labels }}
155+ cache-from : type=gha
156+ cache-to : type=gha,mode=max
0 commit comments