From e1987911392f833b9e2c6b527d733e751e8a2170 Mon Sep 17 00:00:00 2001 From: jubnl Date: Sun, 12 Apr 2026 16:39:42 +0200 Subject: [PATCH] fix: address prerelease workflow review issues - Remove stale mauriceboe/nomad tags from docker-dev.yml - Fix APP_VERSION empty string fallback (?? -> ||) - Fix compareVersions to handle -pre.N suffixes correctly - Use highest existing N instead of tag count to avoid collision after cleanup - Add cleanup step to keep only last 5 prerelease tags per base version --- .github/workflows/docker-dev.yml | 27 +++++++++++++++++++++------ server/src/services/adminService.ts | 22 +++++++++++++++++----- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/.github/workflows/docker-dev.yml b/.github/workflows/docker-dev.yml index 91800bec..88a2de16 100644 --- a/.github/workflows/docker-dev.yml +++ b/.github/workflows/docker-dev.yml @@ -54,9 +54,9 @@ jobs: fi echo "Target: $TARGET" - # Count existing prerelease tags for this target and increment - N=$(git tag -l "v${TARGET}-pre.*" | wc -l) - N=$((N + 1)) + # Find the highest existing prerelease N for this target and increment + LAST_N=$(git tag -l "v${TARGET}-pre.*" | sed 's/.*-pre\.//' | sort -n | tail -1) + N=$(( ${LAST_N:-0} + 1 )) NEW_VERSION="${TARGET}-pre.${N}" echo "VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT @@ -151,10 +151,25 @@ jobs: -t mauriceboe/trek:latest-pre \ -t mauriceboe/trek:$MAJOR_TAG \ -t mauriceboe/trek:$VERSION \ - -t mauriceboe/nomad:latest-pre \ - -t mauriceboe/nomad:$MAJOR_TAG \ - -t mauriceboe/nomad:$VERSION \ "${digests[@]}" - name: Inspect manifest run: docker buildx imagetools inspect mauriceboe/trek:latest-pre + + - name: Clean up old prerelease tags + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + KEEP=5 + VERSION=${{ needs.version-bump.outputs.version }} + BASE_VERSION="$(echo "$VERSION" | sed 's/-pre\..*//')" + git fetch --tags + mapfile -t ALL_TAGS < <(git tag -l "v${BASE_VERSION}-pre.*" | sort -t. -k4 -n) + TOTAL=${#ALL_TAGS[@]} + DELETE_COUNT=$((TOTAL - KEEP)) + if [ "$DELETE_COUNT" -gt 0 ]; then + for TAG in "${ALL_TAGS[@]:0:$DELETE_COUNT}"; do + echo "Deleting old prerelease tag: $TAG" + git push origin --delete "$TAG" + done + fi diff --git a/server/src/services/adminService.ts b/server/src/services/adminService.ts index 3a947a59..d96289f8 100644 --- a/server/src/services/adminService.ts +++ b/server/src/services/adminService.ts @@ -21,13 +21,25 @@ export function utcSuffix(ts: string | null | undefined): string | null { } export function compareVersions(a: string, b: string): number { - const pa = a.split('.').map(Number); - const pb = b.split('.').map(Number); - for (let i = 0; i < Math.max(pa.length, pb.length); i++) { - const na = pa[i] || 0, nb = pb[i] || 0; + const parse = (v: string) => { + const [base, pre] = v.split('-pre.'); + const parts = base.split('.').map(Number); + const preN = pre !== undefined ? parseInt(pre, 10) : null; + return { parts, preN }; + }; + const pa = parse(a), pb = parse(b); + for (let i = 0; i < Math.max(pa.parts.length, pb.parts.length); i++) { + const na = pa.parts[i] || 0, nb = pb.parts[i] || 0; if (na > nb) return 1; if (na < nb) return -1; } + // Equal base: stable > prerelease; higher preN wins among prereleases + if (pa.preN === null && pb.preN !== null) return 1; + if (pa.preN !== null && pb.preN === null) return -1; + if (pa.preN !== null && pb.preN !== null) { + if (pa.preN > pb.preN) return 1; + if (pa.preN < pb.preN) return -1; + } return 0; } @@ -304,7 +316,7 @@ export async function getGithubReleases(perPage: string = '10', page: string = ' } export async function checkVersion() { - const currentVersion: string = process.env.APP_VERSION ?? require('../../package.json').version; + const currentVersion: string = process.env.APP_VERSION || require('../../package.json').version; const isPrerelease = currentVersion.includes('-pre.'); const fallback = { current: currentVersion, latest: currentVersion, update_available: false, is_docker: isDocker, is_prerelease: isPrerelease }; try {