Skip to content

Commit 312bcef

Browse files
committed
Add latest tag detection for Docker image builds
- Add step to detect if release is marked as latest (not prerelease/draft) - Use GitHub API to check release status via github-script - Set TAG_LATEST based on actual release latest status - Push both version tag and latest tag when appropriate - Maintains existing version tagging behavior for non-latest releases - Works for both temporalio (docker.io) and fork (ghcr.io) registries
1 parent 144d933 commit 312bcef

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

.github/workflows/build-and-publish.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,25 @@ jobs:
6969
id: go
7070
run: echo "go=$(go version | cut -d ' ' -f 3)" >> $GITHUB_OUTPUT
7171

72+
- name: Check if release is latest
73+
if: inputs.publish
74+
id: check_latest_release
75+
uses: actions/github-script@v7
76+
with:
77+
script: |
78+
const releaseTag = '${{ inputs.version }}';
79+
const { data: release } = await github.rest.repos.getReleaseByTag({
80+
owner: context.repo.owner,
81+
repo: context.repo.repo,
82+
tag: releaseTag
83+
});
84+
85+
const isLatest = !release.prerelease && !release.draft;
86+
core.setOutput('is_latest', isLatest);
87+
console.log(`Release: ${release.tag_name}`);
88+
console.log(`Prerelease: ${release.prerelease}, Draft: ${release.draft}`);
89+
console.log(`Should tag as latest: ${isLatest}`);
90+
7291
- name: Run GoReleaser (release)
7392
if: inputs.publish
7493
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
@@ -200,7 +219,7 @@ jobs:
200219
IMAGE_SHA_TAG: ${{ steps.meta.outputs.image_sha_tag }}
201220
IMAGE_BRANCH_TAG: ${{ steps.meta.outputs.image_branch_tag }}
202221
VERSION: ${{ steps.meta.outputs.version }}
203-
TAG_LATEST: false
222+
TAG_LATEST: ${{ steps.check_latest_release.outputs.is_latest }}
204223
IMAGE_REPO: ${{ steps.meta.outputs.image_repo }}
205224
IMAGE_NAMESPACE: ${{ steps.meta.outputs.image_namespace }}
206225
IMAGE_NAME: ${{ steps.meta.outputs.image_name }}
@@ -217,9 +236,8 @@ jobs:
217236
IMAGE_SHA_TAG: ${{ steps.meta.outputs.image_sha_tag }}
218237
IMAGE_BRANCH_TAG: ${{ steps.meta.outputs.image_branch_tag }}
219238
VERSION: ${{ steps.meta.outputs.version }}
220-
TAG_LATEST: false
239+
TAG_LATEST: ${{ steps.check_latest_release.outputs.is_latest }}
221240
IMAGE_REPO: ${{ steps.meta.outputs.image_repo }}
222241
IMAGE_NAMESPACE: ${{ steps.meta.outputs.image_namespace }}
223242
IMAGE_NAME: ${{ steps.meta.outputs.image_name }}
224243
GITHUB_REPOSITORY: ${{ github.repository }}
225-
TARGETPLATFORM: linux/amd64,linux/arm64

0 commit comments

Comments
 (0)