Skip to content

Commit c0514e6

Browse files
newbe36524claude
andcommitted
fix: Correct version handling for publish result and release workflow
- Remove v prefix when building and pushing Docker images - Use clean version (without v) for publish result JSON - Fix release tag lookup to avoid double v prefix - Add tag push trigger to GitHub Release Workflow Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 555143a commit c0514e6

2 files changed

Lines changed: 54 additions & 27 deletions

File tree

.github/workflows/docker-build.yml

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ jobs:
204204
if: steps.config.outputs.version != 'latest'
205205
run: |
206206
VERSION="${{ steps.config.outputs.version }}"
207+
# Remove v prefix for Docker image tags
208+
CLEAN_VERSION="${VERSION#v}"
207209
PLATFORM="${{ steps.config.outputs.platform }}"
208210
IMAGE_NAME="hagicode"
209211
REGISTRY="${{ secrets.AZURE_ACR_REGISTRY }}"
@@ -215,7 +217,7 @@ jobs:
215217
# Generate Dockerfile from template
216218
mkdir -p output/docker-build-context
217219
cat docker_deployment/Dockerfile.app.template | \
218-
sed "s|{version}|${VERSION}|g" | \
220+
sed "s|{version}|${CLEAN_VERSION}|g" | \
219221
sed "s|{build_date}|${BUILD_DATE}|g" | \
220222
sed "s|{base_image_name}|${BASE_IMAGE}|g" \
221223
> output/docker-build-context/Dockerfile.app
@@ -230,59 +232,61 @@ jobs:
230232
# Multi-arch build with push to registry - only use Edge ACR
231233
docker buildx build \
232234
--platform linux/amd64,linux/arm64 \
233-
--tag ${REGISTRY}/${IMAGE_NAME}:${VERSION} \
235+
--tag ${REGISTRY}/${IMAGE_NAME}:${CLEAN_VERSION} \
234236
--file output/docker-build-context/Dockerfile.app \
235237
--output type=registry \
236238
output/docker-build-context/
237239
238-
echo "Multi-arch build completed for version: ${VERSION}"
240+
echo "Multi-arch build completed for version: ${CLEAN_VERSION}"
239241
else
240242
# Single platform build
241243
docker buildx build \
242244
--platform ${PLATFORM} \
243-
--tag ${REGISTRY}/${IMAGE_NAME}:${VERSION} \
245+
--tag ${REGISTRY}/${IMAGE_NAME}:${CLEAN_VERSION} \
244246
--file output/docker-build-context/Dockerfile.app \
245247
--load \
246248
output/docker-build-context/
247249
248-
echo "Single platform build completed: ${PLATFORM} for version: ${VERSION}"
250+
echo "Single platform build completed: ${PLATFORM} for version: ${CLEAN_VERSION}"
249251
250252
if [ "${{ inputs.dry_run }}" != "true" ]; then
251-
docker push ${REGISTRY}/${IMAGE_NAME}:${VERSION}
252-
echo "Image pushed: ${REGISTRY}/${IMAGE_NAME}:${VERSION}"
253+
docker push ${REGISTRY}/${IMAGE_NAME}:${CLEAN_VERSION}
254+
echo "Image pushed: ${REGISTRY}/${IMAGE_NAME}:${CLEAN_VERSION}"
253255
fi
254256
fi
255257
256258
- name: Push Additional Tags
257259
if: steps.config.outputs.version != 'latest' && (inputs.dry_run != 'true')
258260
run: |
259261
VERSION="${{ steps.config.outputs.version }}"
262+
# Remove v prefix for tag operations
263+
CLEAN_VERSION="${VERSION#v}"
260264
IMAGE_NAME="hagicode"
261-
REGISTRY="${{ secrets.AZURE_ACR_REGISTRY }}"
265+
REGISTRY="${{ secrets.AZURE_ACR_REGISTRY }}
262266
263-
# Parse version parts
264-
MAJOR=$(echo ${VERSION} | cut -d. -f1)
265-
MINOR=$(echo ${VERSION} | cut -d. -f2)
267+
# Parse version parts from clean version
268+
MAJOR=$(echo ${CLEAN_VERSION} | cut -d. -f1)
269+
MINOR=$(echo ${CLEAN_VERSION} | cut -d. -f2)
266270
267271
# For multi-arch images pushed with --output type=registry, we can't tag locally
268272
# Instead, we use docker manifest to verify tags exist
269273
# The manifest tool automatically handles cross-repo tagging
270274
271275
# Push minor version tag using manifest (works with multi-arch)
272-
docker buildx imagetools create -t ${REGISTRY}/${IMAGE_NAME}:${MAJOR}.${MINOR} ${REGISTRY}/${IMAGE_NAME}:${VERSION}
276+
docker buildx imagetools create -t ${REGISTRY}/${IMAGE_NAME}:${MAJOR}.${MINOR} ${REGISTRY}/${IMAGE_NAME}:${CLEAN_VERSION}
273277
echo "Pushed minor tag: ${REGISTRY}/${IMAGE_NAME}:${MAJOR}.${MINOR}"
274278
275279
# Push major version tag using manifest
276-
docker buildx imagetools create -t ${REGISTRY}/${IMAGE_NAME}:${MAJOR} ${REGISTRY}/${IMAGE_NAME}:${VERSION}
280+
docker buildx imagetools create -t ${REGISTRY}/${IMAGE_NAME}:${MAJOR} ${REGISTRY}/${IMAGE_NAME}:${CLEAN_VERSION}
277281
echo "Pushed major tag: ${REGISTRY}/${IMAGE_NAME}:${MAJOR}"
278282
279283
# Push latest tag only for stable releases (not pre-release like rc, beta, alpha)
280284
# Check if version contains pre-release suffixes
281-
if [[ ! ${VERSION} =~ ^(rc|beta|alpha|preview|dev)[0-9]*$ ]] && [[ ! ${VERSION} =~ -(rc|beta|alpha|preview|dev) ]]; then
282-
docker buildx imagetools create -t ${REGISTRY}/${IMAGE_NAME}:latest ${REGISTRY}/${IMAGE_NAME}:${VERSION}
285+
if [[ ! ${CLEAN_VERSION} =~ ^(rc|beta|alpha|preview|dev)[0-9]*$ ]] && [[ ! ${CLEAN_VERSION} =~ -(rc|beta|alpha|preview|dev) ]]; then
286+
docker buildx imagetools create -t ${REGISTRY}/${IMAGE_NAME}:latest ${REGISTRY}/${IMAGE_NAME}:${CLEAN_VERSION}
283287
echo "Pushed latest tag: ${REGISTRY}/${IMAGE_NAME}:latest"
284288
else
285-
echo "Skipped latest tag - pre-release version detected: ${VERSION}"
289+
echo "Skipped latest tag - pre-release version detected: ${CLEAN_VERSION}"
286290
fi
287291
288292
- name: Verify Images in Registry
@@ -346,13 +350,16 @@ jobs:
346350
GITHUB_REPO="${{ github.repository }}"
347351
GITHUB_SERVER_URL="${{ github.server_url }}"
348352
353+
# Remove v prefix from VERSION for internal processing
354+
CLEAN_VERSION="${VERSION#v}"
355+
349356
# Parse version parts
350-
MAJOR=$(echo ${VERSION} | cut -d. -f1)
351-
MINOR=$(echo ${VERSION} | cut -d. -f2)
357+
MAJOR=$(echo ${CLEAN_VERSION} | cut -d. -f1)
358+
MINOR=$(echo ${CLEAN_VERSION} | cut -d. -f2)
352359
353360
# Generate JSON using jq
354361
jq -n \
355-
--arg version "${VERSION}" \
362+
--arg version "${CLEAN_VERSION}" \
356363
--arg publishedAt "${PUBLISHED_AT}" \
357364
--arg runId "${GITHUB_RUN_ID}" \
358365
--arg runUrl "${GITHUB_SERVER_URL}/${GITHUB_REPO}/actions/runs/${GITHUB_RUN_ID}" \
@@ -377,18 +384,22 @@ jobs:
377384
{ name: $imageName, tag: "latest", fullUrl: ($registry + "/" + $imageName + ":latest") }
378385
]
379386
}
380-
}' > azure-publish-results-${VERSION}.json
387+
}' > azure-publish-results-${CLEAN_VERSION}.json
381388
382389
echo "Generated Azure publish result JSON:"
383-
cat azure-publish-results-${VERSION}.json
384-
echo "publish_result_file=azure-publish-results-${VERSION}.json" >> $GITHUB_OUTPUT
390+
cat azure-publish-results-${CLEAN_VERSION}.json
391+
echo "publish_result_file=azure-publish-results-${CLEAN_VERSION}.json" >> $GITHUB_OUTPUT
392+
echo "clean_version=${CLEAN_VERSION}" >> $GITHUB_OUTPUT
385393
386394
- name: Upload Publish Result to GitHub Release
387395
if: steps.config.outputs.version != 'latest' && (inputs.dry_run != 'true')
388396
run: |
389397
VERSION="${{ steps.config.outputs.version }}"
390-
FILE_NAME="azure-publish-results-${VERSION}.json"
391-
RELEASE_TAG="v${VERSION}"
398+
CLEAN_VERSION="${{ steps.generate-publish-result.outputs.clean_version }}"
399+
FILE_NAME="azure-publish-results-${CLEAN_VERSION}.json"
400+
401+
# Use VERSION as release tag (it already includes v prefix from git tag)
402+
RELEASE_TAG="${VERSION}"
392403
393404
echo "Uploading ${FILE_NAME} to release ${RELEASE_TAG}..."
394405

.github/workflows/github-release-workflow.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ name: GitHub Release Workflow
1515
on:
1616
repository_dispatch:
1717
types: [version-monitor-release]
18+
push:
19+
tags:
20+
- 'v*.*.*'
1821

1922
permissions:
2023
contents: write # Required for creating GitHub Releases
@@ -30,11 +33,24 @@ jobs:
3033
- name: Checkout repository
3134
uses: actions/checkout@v6
3235

33-
- name: Extract version from event payload
36+
- name: Extract version from event payload or tag
3437
id: extract-version
3538
run: |
36-
VERSION="${{ github.event.client_payload.version }}"
37-
echo "Extracted version: $VERSION"
39+
if [ "${{ github.event_name }}" = "repository_dispatch" ] && [ -n "${{ github.event.client_payload.version }}" ]; then
40+
VERSION="${{ github.event.client_payload.version }}"
41+
echo "Extracted version from repository_dispatch: $VERSION"
42+
elif [ "${{ github.event_name }}" = "push" ]; then
43+
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
44+
VERSION=${GITHUB_REF#refs/tags/}
45+
echo "Extracted version from tag: $VERSION"
46+
else
47+
echo "Error: Not a tag push event"
48+
exit 1
49+
fi
50+
else
51+
echo "Error: No version available"
52+
exit 1
53+
fi
3854
echo "version=$VERSION" >> $GITHUB_OUTPUT
3955
4056
- name: Run GitHub Release

0 commit comments

Comments
 (0)