Skip to content

Commit 5bf692c

Browse files
committed
ci: use path hashing for pr image tags
1 parent 6bf625c commit 5bf692c

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,40 @@ jobs:
234234
secrets:
235235
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
236236

237-
build-docker-image:
237+
generate-image-tag:
238238
needs: [check-recording-bot-changes, chart-version-checks, retag-and-push]
239+
if: |
240+
always() &&
241+
needs.chart-version-checks.result == 'success' &&
242+
(
243+
needs.check-recording-bot-changes.outputs.build == 'True' ||
244+
needs.check-recording-bot-changes.outputs.src == 'True' ||
245+
needs.check-recording-bot-changes.outputs.scripts == 'True'
246+
) &&
247+
(
248+
github.event_name == 'pull_request' ||
249+
((github.event_name == 'push' || github.event_name == 'schedule') && needs.retag-and-push.outputs.image-exists == 'false')
250+
)
251+
runs-on: ubuntu-latest
252+
253+
outputs:
254+
image-tag: ${{ steps.generate-tag.outputs.tag }}
255+
256+
steps:
257+
- uses: actions/checkout@v4
258+
259+
- name: Generate content-based image tag
260+
id: generate-tag
261+
run: |
262+
hash=$(find src build scripts -type f -exec sha256sum {} \; | sort | sha256sum | awk '{print $1}')
263+
if [ '${{ github.event_name }}' = 'pull_request' ]; then
264+
echo "tag=pr-${{ github.event.number }}-${hash:0:8}" >> $GITHUB_OUTPUT
265+
else
266+
echo "tag=latest" >> $GITHUB_OUTPUT
267+
fi
268+
269+
build-docker-image:
270+
needs: [check-recording-bot-changes, chart-version-checks, retag-and-push, generate-image-tag]
239271
if: |
240272
always() &&
241273
needs.chart-version-checks.result == 'success' &&
@@ -252,12 +284,12 @@ jobs:
252284
permissions:
253285
packages: write
254286
with:
255-
tag: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || 'latest' }}
287+
tag: ${{ needs.generate-image-tag.outputs.image-tag }}
256288
cr-namespace-repository: ${{ vars.CR_NAMESPACE_REPOSITORY }}
257289
secrets: inherit
258290

259291
deploy-to-environment:
260-
needs: [check-recording-bot-changes, chart-version-checks, start-cluster, build-docker-image, retag-and-push]
292+
needs: [check-recording-bot-changes, chart-version-checks, start-cluster, build-docker-image, retag-and-push, generate-image-tag]
261293
if: |
262294
always() &&
263295
needs.start-cluster.result == 'success' &&
@@ -277,7 +309,7 @@ jobs:
277309
host: ${{ needs.start-cluster.outputs.cluster-fqdn }}
278310
image-registry: ${{ vars.CR_REGISTRY }}
279311
image-name: ${{ vars.CR_IMAGE_NAME }}
280-
image-tag: ${{ needs.build-docker-image.outputs.image-tag || 'latest' }}
312+
image-tag: ${{ needs.generate-image-tag.outputs.image-tag || 'latest' }}
281313
public-ip: ${{ needs.start-cluster.outputs.cluster-ip }}
282314
tls-email: ${{ vars.TLS_EMAIL }}
283315
enable-nginx: true
@@ -286,12 +318,12 @@ jobs:
286318
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
287319

288320
run-tests:
289-
needs: [check-recording-bot-changes, chart-version-checks, start-cluster, build-docker-image, deploy-to-environment]
321+
needs: [check-recording-bot-changes, chart-version-checks, start-cluster, build-docker-image, deploy-to-environment, generate-image-tag]
290322
if: always() && needs.deploy-to-environment.result == 'success'
291323
uses: ./.github/workflows/routine-runtests.yml
292324
with:
293325
headless-mode: true
294-
test-environment: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || 'latest' }}
326+
test-environment: ${{ needs.generate-image-tag.outputs.image-tag || 'latest' }}
295327
github-issue-number: ${{ github.event.number || '' }}
296328
secrets:
297329
USER_A_USERNAME: ${{ vars.TEST_USER_A_USERNAME }}

0 commit comments

Comments
 (0)