Skip to content

Commit e7014d5

Browse files
Merge pull request #230 from tomtom-international/lsi/fix-release-image-version
LSI-31 Build release image from bumped commit instead of retagging main
2 parents 2786f61 + 9a760e7 commit e7014d5

1 file changed

Lines changed: 22 additions & 62 deletions

File tree

.github/workflows/release.yml

Lines changed: 22 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ on:
55
branches:
66
- main
77

8-
env:
9-
REGISTRY: ghcr.io
10-
IMAGE_NAME: ${{ github.repository }}
11-
128
permissions:
139
contents: write
1410
packages: write
@@ -52,69 +48,33 @@ jobs:
5248
version=$(yq -r '.version' package.json)
5349
echo "version=$version" >> $GITHUB_OUTPUT
5450
51+
# Build the release image directly from the version-bump commit that triggered
52+
# this workflow, so the version baked into the image (src/version.ts, generated
53+
# from package.json at build time) matches the release tag. Previously this job
54+
# retagged the pre-bump `main` image, which left the image reporting the prior
55+
# version. Mirrors the build.yml invocation, adding the versioned + latest tags.
5556
tag-release-image:
56-
runs-on: ubuntu-22.04
5757
needs: [get-version]
58-
steps:
59-
- name: Log in to Container Registry
60-
uses: docker/login-action@v3
61-
with:
62-
registry: ${{ env.REGISTRY }}
58+
permissions:
59+
contents: read
60+
packages: write
61+
uses: docker/github-builder/.github/workflows/build.yml@v1
62+
with:
63+
output: image
64+
push: true
65+
platforms: linux/amd64,linux/arm64
66+
meta-images: ghcr.io/${{ github.repository }}
67+
meta-tags: |
68+
type=raw,value=v${{ needs.get-version.outputs.version }}
69+
type=raw,value=latest
70+
sign: false
71+
cache: true
72+
secrets:
73+
registry-auths: |
74+
- registry: ghcr.io
6375
username: ${{ github.actor }}
6476
password: ${{ secrets.GITHUB_TOKEN }}
6577
66-
- name: Get latest main SHA tag from package repository
67-
id: get-sha
68-
run: |
69-
REPO_OWNER="${{ github.repository_owner }}"
70-
REPO_NAME="$(basename ${{ github.repository }})"
71-
72-
# Check if the repo belongs to an org or user
73-
TYPE_CHECK=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
74-
-H "Accept: application/vnd.github.v3+json" \
75-
"https://api.github.com/users/${REPO_OWNER}" | \
76-
jq -r '.type')
77-
78-
if [[ "$TYPE_CHECK" == "Organization" ]]; then
79-
OWNER_TYPE="orgs"
80-
else
81-
OWNER_TYPE="users"
82-
fi
83-
84-
MAIN_SHA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
85-
-H "Accept: application/vnd.github.v3+json" \
86-
"https://api.github.com/${OWNER_TYPE}/${REPO_OWNER}/packages/container/${REPO_NAME}/versions" | \
87-
jq -r '.[] | select(.metadata.container.tags | index("main")) | .metadata.container.tags[]' | grep '^sha-')
88-
echo "main_sha=$MAIN_SHA" >> $GITHUB_OUTPUT
89-
echo "Main SHA: $MAIN_SHA"
90-
91-
- name: Pull, retag and push release image
92-
run: |
93-
# Ensure image names are all lowercase
94-
REPO_NAME_LOWER=$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]')
95-
96-
# Source image with SHA tag
97-
SOURCE_IMAGE="${{ env.REGISTRY }}/${REPO_NAME_LOWER}:${{ steps.get-sha.outputs.main_sha }}"
98-
# Target image with release tag
99-
TARGET_IMAGE="${{ env.REGISTRY }}/${REPO_NAME_LOWER}:v${{ needs.get-version.outputs.version }}"
100-
# Latest tag
101-
LATEST_IMAGE="${{ env.REGISTRY }}/${REPO_NAME_LOWER}:latest"
102-
103-
echo "Pulling source image: $SOURCE_IMAGE"
104-
docker pull $SOURCE_IMAGE
105-
106-
echo "Tagging as: $TARGET_IMAGE"
107-
docker tag $SOURCE_IMAGE $TARGET_IMAGE
108-
109-
echo "Tagging as: $LATEST_IMAGE"
110-
docker tag $SOURCE_IMAGE $LATEST_IMAGE
111-
112-
echo "Pushing release image: $TARGET_IMAGE"
113-
docker push $TARGET_IMAGE
114-
115-
echo "Pushing latest image: $LATEST_IMAGE"
116-
docker push $LATEST_IMAGE
117-
11878
add-release-artifacts:
11979
runs-on: ubuntu-22.04
12080
needs: [tag-release-image, get-version]

0 commit comments

Comments
 (0)