File tree Expand file tree Collapse file tree 3 files changed +57
-15
lines changed
Expand file tree Collapse file tree 3 files changed +57
-15
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ # Computes the OCI image tag for Garden Linux ccloud images
3+ #
4+ # This script centralizes the image tag format computation to ensure consistency
5+ # across all workflows (nightly, dev, upload_oci).
6+ #
7+ # Usage:
8+ # ./compute-image-tag.sh <version> [flavor]
9+ #
10+ # Arguments:
11+ # version - The version for the tag (e.g., "1877.10.1", "pr-123")
12+ # flavor - The image flavor (e.g., "metal-sci-usi-amd64"). Defaults to "metal-sci-usi-amd64".
13+ #
14+ # Environment:
15+ # GITHUB_SHA - Git commit SHA (required, set automatically by GitHub Actions)
16+ #
17+ # Output:
18+ # Prints the computed image tag to stdout
19+ #
20+ # Tag format:
21+ # {version}-{flavor}-{dashed_version}-{commit_sha_short}
22+ #
23+ # Examples:
24+ # ./compute-image-tag.sh "1877.10.1"
25+ # # Output: 1877.10.1-metal-sci-usi-amd64-1877-10-1-abcd1234
26+ #
27+ # ./compute-image-tag.sh "pr-123" "metal-capi-amd64"
28+ # # Output: pr-123-metal-capi-amd64-pr-123-abcd1234
29+
30+ set -euo pipefail
31+
32+ VERSION=" ${1:? Error: VERSION argument required} "
33+ FLAVOR=" ${2:- metal-sci-usi-amd64} "
34+
35+ if [ -z " ${GITHUB_SHA:- } " ]; then
36+ echo " Error: GITHUB_SHA environment variable is required" >&2
37+ exit 1
38+ fi
39+
40+ COMMIT_SHA=" ${GITHUB_SHA:: 8} "
41+ DASHED_VERSION=" ${VERSION// ./ -} "
42+
43+ IMAGE_TAG=" ${VERSION} -${FLAVOR} -${DASHED_VERSION} -${COMMIT_SHA} "
44+
45+ echo " $IMAGE_TAG "
Original file line number Diff line number Diff line change @@ -54,16 +54,18 @@ jobs:
5454 runs-on : ubuntu-latest
5555 outputs :
5656 UPLOAD_VERSION : ${{ steps.meta.outputs.upload_version }}
57- COMMIT_SHA : ${{ steps.meta.outputs.sha }}
57+ image_tag : ${{ steps.meta.outputs.image_tag }}
5858 steps :
59- - name : Derive image version
59+ - name : Checkout
60+ uses : actions/checkout@v4
61+ - name : Compute image metadata
6062 id : meta
6163 run : |
6264 PR_NUMBER=${{ github.event.pull_request.number }}
6365 UPLOAD_VERSION="pr-${PR_NUMBER}"
6466 echo "upload_version=${UPLOAD_VERSION}" >> $GITHUB_OUTPUT
65- SHA= "${GITHUB_SHA::8}"
66- echo "sha =${SHA }" >> $GITHUB_OUTPUT
67+ IMAGE_TAG=$(.github/scripts/compute-image-tag.sh "${UPLOAD_VERSION}")
68+ echo "image_tag =${IMAGE_TAG }" >> $GITHUB_OUTPUT
6769
6870 upload :
6971 name : Upload PR image to OCI
8284 if : ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.event.action != 'closed' }}
8385 uses : ./.github/workflows/test.yml
8486 with :
85- image_tag : " ${{ needs.meta.outputs.UPLOAD_VERSION }}-metal-sci-usi-amd64-${{ needs.meta.outputs.UPLOAD_VERSION }}-${{ needs.meta.outputs.COMMIT_SHA }} "
87+ image_tag : ${{ needs.meta.outputs.image_tag }}
8688
8789 cleanup_images :
8890 name : Cleanup PR images
Original file line number Diff line number Diff line change @@ -36,20 +36,15 @@ jobs:
3636 needs : [build]
3737 runs-on : ubuntu-latest
3838 outputs :
39- VERSION : ${{ needs.build.outputs.version }}
40- DASHED_VERSION : ${{ steps.meta.outputs.dashed_version }}
41- COMMIT_SHA : ${{ steps.meta.outputs.sha }}
39+ image_tag : ${{ steps.meta.outputs.image_tag }}
4240 steps :
4341 - name : Checkout
4442 uses : actions/checkout@v4
45- - name : Derive image metadata
43+ - name : Compute image tag
4644 id : meta
4745 run : |
48- SHA="${GITHUB_SHA::8}"
49- echo "sha=${SHA}" >> $GITHUB_OUTPUT
50- VERSION="${{ needs.build.outputs.version }}"
51- DASHED_VERSION=${VERSION//./-}
52- echo "dashed_version=${DASHED_VERSION}" >> $GITHUB_OUTPUT
46+ IMAGE_TAG=$(.github/scripts/compute-image-tag.sh "${{ needs.build.outputs.version }}")
47+ echo "image_tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT
5348 upload_oci :
5449 name : Run glcli to publish to OCI
5550 needs : [build]
6358 needs : [meta, upload_oci]
6459 uses : ./.github/workflows/test.yml
6560 with :
66- image_tag : " ${{ needs.meta.outputs.VERSION }}-metal-sci-usi-amd64-${{ needs.meta.outputs.DASHED_VERSION }}-${{ needs.meta.outputs.COMMIT_SHA }} "
61+ image_tag : ${{ needs.meta.outputs.image_tag }}
You can’t perform that action at this time.
0 commit comments