From 73e5e8100cb89133b3d7a7634ad74ff9dcfafaa9035885ed14fa503b1c3810d9 Mon Sep 17 00:00:00 2001 From: gsadmin Date: Tue, 11 Aug 2026 06:58:12 -0400 Subject: [PATCH] CI: one deterministic version (commit time) so images/binaries dont drift [skip ci] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The images job recomputed the version with its own `date` clock while build-test used Get-UnifiedVersion, so a build spanning a minute landed the container images and the binaries a minute apart (e.g. ...1041 vs ...1042). - Get-UnifiedVersion now derives the version from the HEAD commit's committer time (UTC) when not given one explicitly, so every job and workflow building the same commit computes the same version — deterministic, reproducible. - The images job no longer recomputes: build-test exposes its version as a job output and images consumes needs.build-test.outputs.version. - release.yml already calls Get-UnifiedVersion, so it now matches ci.yml for the same commit too. Verified locally: the version equals the HEAD commit time, is stable across calls, and an explicit -Version / UNIFIED_VERSION still wins. Co-Authored-By: Claude Fable 5 --- .gitea/workflows/ci.yml | 13 +++++++++---- scripts/Get-UnifiedVersion.ps1 | 17 ++++++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 953e0d7..0488404 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -35,6 +35,10 @@ jobs: # Windows is required to build/test the agent (CIM, ConPTY, DPAPI, service). # Label must match a registered runner: windows-host. runs-on: windows-host + # Single source of truth for the version: the images job consumes this + # instead of recomputing, so binaries and container images never drift. + outputs: + version: ${{ steps.ver.outputs.version }} steps: # This repository uses the SHA-256 object format. actions/checkout # cannot clone it (it inits a SHA-1 repo then fetches: "mismatched @@ -187,12 +191,13 @@ jobs: git clone --depth 1 --branch "$REF" "$URL" . git log -1 --format='%H %s' - - name: Resolve version and registry target + - name: Resolve registry target id: ver shell: bash run: | set -e - echo "version=$(date -u +%Y.%m.%d.%H%M)" >> "$GITHUB_OUTPUT" + # The version is NOT recomputed here — it comes from build-test's + # output (needs.build-test.outputs.version) so images match the binaries. # Default to Gitea's own registry on this instance; fall back to the # REGISTRY_* secrets only when an external registry is configured. @@ -239,7 +244,7 @@ jobs: - name: Build images env: - VERSION: ${{ steps.ver.outputs.version }} + VERSION: ${{ needs.build-test.outputs.version }} PREFIX: ${{ steps.ver.outputs.prefix }} SOURCE_URL: ${{ github.server_url }}/${{ github.repository }} run: | @@ -259,7 +264,7 @@ jobs: - name: Tag and push env: - VERSION: ${{ steps.ver.outputs.version }} + VERSION: ${{ needs.build-test.outputs.version }} PREFIX: ${{ steps.ver.outputs.prefix }} REF_NAME: ${{ github.ref_name }} run: | diff --git a/scripts/Get-UnifiedVersion.ps1 b/scripts/Get-UnifiedVersion.ps1 index 2d87421..9565777 100644 --- a/scripts/Get-UnifiedVersion.ps1 +++ b/scripts/Get-UnifiedVersion.ps1 @@ -1,8 +1,11 @@ <# .SYNOPSIS -Computes the unified build version (yyyy.MM.dd.HHmm, UTC) exactly once per build. +Computes the unified build version (yyyy.MM.dd.HHmm, UTC). Honors an explicit -Version argument or the UNIFIED_VERSION environment variable -(as set by CI) so every artifact in one pipeline shares the same version. +first. Otherwise it derives the version from the HEAD commit's committer time, so +every job and workflow building the same commit lands on the same version — no +drift between the binaries and the container images. Falls back to the current +time only when git is unavailable. #> [CmdletBinding()] param( @@ -12,7 +15,15 @@ param( $ErrorActionPreference = 'Stop' if (-not $Version) { $Version = $env:UNIFIED_VERSION } -if (-not $Version) { $Version = [DateTime]::UtcNow.ToString('yyyy.MM.dd.HHmm') } +if (-not $Version) { + $epoch = "$(git show -s --format=%ct HEAD 2>$null)".Trim() + if ($epoch -match '^\d+$') { + $Version = [DateTimeOffset]::FromUnixTimeSeconds([long]$epoch).UtcDateTime.ToString('yyyy.MM.dd.HHmm') + } + else { + $Version = [DateTime]::UtcNow.ToString('yyyy.MM.dd.HHmm') + } +} if ($Version -notmatch '^\d{4}\.\d{2}\.\d{2}\.\d{4}$') { throw "Unified version '$Version' does not match yyyy.MM.dd.HHmm." -- 2.52.0