1- name : Push Artifacts to Azure Registry
1+ name : Build and Push Artifacts
22
33on :
44 push :
5- tags :
6- - ' v*'
5+ branches :
6+ - next
7+ release :
8+ types : [published]
9+
10+ concurrency :
11+ group : build-and-push-${{ github.ref }}
12+ cancel-in-progress : false # false to queue, not cancel
713
814permissions :
915 contents : write
@@ -13,51 +19,192 @@ env:
1319 DOMAIN : infra
1420
1521jobs :
22+ # ---------------------------------------------------------------------------
23+ # Determine what triggered us and resolve all config up front.
24+ #
25+ # Three possible paths:
26+ # 1. push to next (developer commit) → dev, tag = next-{sha}
27+ # 2. release, prerelease=true → qa, tag = v0.1.2-rc.10
28+ # 3. release, prerelease=false → prod, tag = v0.1.2
29+ # + housekeeping: update qa & int
30+ #
31+ # The push-to-next path must skip commits from mapcolonies[bot]
32+ # (the empty "Release-As" footer commits from smart-release-please).
33+ # ---------------------------------------------------------------------------
34+ determine-config :
35+ runs-on : ubuntu-latest
36+ outputs :
37+ should_run : ${{ steps.check.outputs.should_run }}
38+ image_tag : ${{ steps.config.outputs.image_tag }}
39+ chart_tag : ${{ steps.config.outputs.chart_tag }}
40+ environment : ${{ steps.config.outputs.environment }}
41+ pr_labels : ${{ steps.config.outputs.pr_labels }}
42+ update_paths : ${{ steps.config.outputs.update_paths }}
43+ is_stable : ${{ steps.config.outputs.is_stable }}
44+ steps :
45+ - name : Check if should run
46+ id : check
47+ shell : bash
48+ run : |
49+ # Always run on release events
50+ if [[ "${{ github.event_name }}" == "release" ]]; then
51+ echo "should_run=true" >> "$GITHUB_OUTPUT"
52+ exit 0
53+ fi
54+
55+ # For push to next: skip bot commits
56+ COMMIT_MSG="${{ github.event.head_commit.message }}"
57+
58+ # Skip if commit message contains bot indicators
59+ if [[ "$COMMIT_MSG" == *"Release-As:"* ]] || \
60+ [[ "$COMMIT_MSG" == "chore: enforce correct rc version"* ]] || \
61+ [[ "$COMMIT_MSG" == *"chore(next): release"* ]] || \
62+ [[ "$COMMIT_MSG" == *"chore: release"* ]] || \
63+ [[ "$COMMIT_MSG" == "Merge branch 'master' into next"* ]]; then
64+ echo "should_run=false" >> "$GITHUB_OUTPUT"
65+ echo "Skipping bot commit"
66+ exit 0
67+ fi
68+
69+ echo "should_run=true" >> "$GITHUB_OUTPUT"
70+
71+ - name : Resolve config
72+ id : config
73+ if : steps.check.outputs.should_run == 'true'
74+ shell : bash
75+ run : |
76+ if [[ "${{ github.event_name }}" == "release" ]]; then
77+ TAG="${{ github.event.release.tag_name }}"
78+ echo "image_tag=${TAG}" >> "$GITHUB_OUTPUT"
79+ echo "chart_tag=${TAG}" >> "$GITHUB_OUTPUT"
80+ if [[ "${{ github.event.release.prerelease }}" == "true" ]]; then
81+ ENV="qa"
82+ echo "is_stable=false" >> "$GITHUB_OUTPUT"
83+ else
84+ ENV="prod"
85+ echo "is_stable=true" >> "$GITHUB_OUTPUT"
86+ fi
87+ else
88+ # push to next → dev
89+ ENV="dev"
90+ echo "image_tag=next-${{ github.sha }}" >> "$GITHUB_OUTPUT"
91+ echo "chart_tag=0.0.0-next-${{ github.sha }}" >> "$GITHUB_OUTPUT"
92+ echo "is_stable=false" >> "$GITHUB_OUTPUT"
93+ fi
94+ # Set environment-based outputs
95+ echo "environment=${ENV}" >> "$GITHUB_OUTPUT"
96+ echo "update_paths=infra/environments/${ENV}.yaml" >> "$GITHUB_OUTPUT"
97+
98+ # Set PR labels (dev gets auto-merge)
99+ if [[ "${ENV}" == "dev" ]]; then
100+ echo "pr_labels=${ENV}, auto-merge" >> "$GITHUB_OUTPUT"
101+ else
102+ echo "pr_labels=${ENV}" >> "$GITHUB_OUTPUT"
103+ fi
104+ # ---------------------------------------------------------------------------
105+ # Build & push Docker image
106+ # ---------------------------------------------------------------------------
16107 push-docker-image :
17108 runs-on : ubuntu-latest
109+ needs : determine-config
110+ if : needs.determine-config.outputs.should_run == 'true'
18111 steps :
19- - name : Login to Azure Container Registry
112+ - name : Checkout
113+ uses : actions/checkout@v6
114+
115+ - name : Login to ACR
20116 uses : docker/login-action@v3
21117 with :
22118 registry : ${{ secrets.ACR_URL }}
23119 username : ${{ secrets.ACR_PUSH_USER }}
24120 password : ${{ secrets.ACR_PUSH_TOKEN }}
25121
26- - name : Build and Push Docker image
27- id : build_and_push
122+ - name : Build and push
28123 uses : docker/build-push-action@v6
29124 with :
125+ context : .
30126 push : true
31- tags : ${{ secrets.ACR_URL }}/${{ env.DOMAIN }}/${{ github.event.repository.name }}:${{ github.ref_name }}
127+ tags : ${{ secrets.ACR_URL }}/${{ env.DOMAIN }}/${{ github.event.repository.name }}:${{ needs.determine-config.outputs.image_tag }}
32128
129+ # ---------------------------------------------------------------------------
130+ # Build & push Helm chart
131+ # ---------------------------------------------------------------------------
33132 push-helm-package :
34133 runs-on : ubuntu-latest
35- needs : push-docker-image
134+ if : needs.determine-config.outputs.should_run == 'true'
135+ needs : [determine-config]
36136 steps :
37- - name : Checkout Repository
137+ - name : Checkout
38138 uses : actions/checkout@v6
39139
40- - name : Login to Azure Container Registry
41- uses : docker/login-action@v3
140+ - name : Setup Helm
141+ uses : azure/setup-helm@v4
42142 with :
43- registry : ${{ secrets.ACR_URL }}
44- username : ${{ secrets.ACR_PUSH_USER }}
45- password : ${{ secrets.ACR_PUSH_TOKEN }}
143+ version : v3.15.4
46144
47- - name : Remove v from the tag
48- id : remove_v
49- run : |
50- TAG=${{ github.ref_name }}
51- echo "VERSION=${TAG#v}" >> $GITHUB_OUTPUT
52-
53- - name : Push Chart to ACR
145+ - name : Push chart to ACR
54146 uses : appany/helm-oci-chart-releaser@v0.5.0
55147 with :
56148 name : ${{ github.event.repository.name }}
57149 repository : helm/${{ env.DOMAIN }}
58- tag : ${{ steps.remove_v .outputs.version }}
150+ tag : ${{ needs.determine-config .outputs.chart_tag }}
59151 path : ./helm
60152 registry : ${{ secrets.ACR_URL }}
61153 registry_username : ${{ secrets.ACR_PUSH_USER }}
62154 registry_password : ${{ secrets.ACR_PUSH_TOKEN }}
63- update_dependencies : ' true' # Defaults to false
155+ update_dependencies : ' true'
156+
157+ # ---------------------------------------------------------------------------
158+ # Open the PR in site-values for the target environment.
159+ #
160+ # dev → auto-merge (labels: "dev")
161+ # prod → manual (labels: "prod")
162+ # ---------------------------------------------------------------------------
163+ update-site-values :
164+ runs-on : ubuntu-latest
165+ needs : [determine-config, push-docker-image, push-helm-package]
166+ steps :
167+ - name : Checkout
168+ uses : actions/checkout@v6
169+ with :
170+ fetch-depth : 0
171+
172+ - name : Open / update site-values PR
173+ uses : MapColonies/shared-workflows/actions/update-chart-version@update-chart-version-v0.1.0
174+ with :
175+ tag : ${{ needs.determine-config.outputs.chart_tag }}
176+ repository : site-values
177+ github_token : ${{ secrets.GH_PAT }}
178+ chart : ${{ github.event.repository.name }}
179+ environment : ${{ needs.determine-config.outputs.environment }}
180+ pr_labels : ${{ needs.determine-config.outputs.pr_labels }}
181+ paths : ${{ needs.determine-config.outputs.update_paths }}
182+
183+ # ---------------------------------------------------------------------------
184+ # Housekeeping — only on stable release.
185+ # When v0.1.2 is cut, qa and integration are still pointing at v0.1.2-rc.X.
186+ # This job auto-updates both to the new stable tag so they stay in sync.
187+ # ---------------------------------------------------------------------------
188+ housekeeping-update-qa-and-integration :
189+ runs-on : ubuntu-latest
190+ needs : [determine-config, push-helm-package, push-docker-image]
191+ if : needs.determine-config.outputs.is_stable == 'true'
192+ strategy :
193+ matrix :
194+ env_name : [qa, integration]
195+ steps :
196+ - name : Checkout
197+ uses : actions/checkout@v6
198+ with :
199+ fetch-depth : 0
200+
201+ - name : Update ${{ matrix.env_name }} to stable tag
202+ uses : MapColonies/shared-workflows/actions/update-chart-version@update-chart-version-v0.1.0
203+ with :
204+ tag : ${{ needs.determine-config.outputs.chart_tag }}
205+ repository : site-values
206+ github_token : ${{ secrets.GH_PAT }}
207+ chart : ${{ github.event.repository.name }}
208+ environment : ${{ matrix.env_name }}
209+ pr_labels : ${{ matrix.env_name }}, auto-merge
210+ paths : infra/environments/${{ matrix.env_name }}.yaml
0 commit comments