Skip to content

Commit 3f796fa

Browse files
committed
fix release when timestamped tag is used
Signed-off-by: André Bauer <andre.bauer@staffbase.com>
1 parent e0dbf8e commit 3f796fa

3 files changed

Lines changed: 53 additions & 13 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ the SHA. This makes branch tags **sortable** so
173173
newest build — the Git SHA alone is not orderable. The short SHA is kept for
174174
traceability and Flux sorts on the timestamp only.
175175

176+
> **Note:** with `docker-tag-timestamp: 'true'` the build also pushes the plain
177+
> `<prefix>-<short-sha>` tag alongside the timestamped one. That stable per-commit
178+
> tag is what the release step retags into the version tag, so it must keep
179+
> existing. It does not match the `^<prefix>-[0-9]+-[0-9a-f]+$` filter below, so
180+
> Flux ignores it.
181+
176182
With the timestamp enabled, use one `ImagePolicy` per environment, filtering by prefix:
177183

178184
```yaml

scripts/generate-tags.sh

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,34 @@ require_env INPUT_DOCKER_REGISTRY
1616
require_env INPUT_DOCKER_IMAGE
1717

1818
BUILD="true"
19+
# ALIAS_TAG is an additional immutable tag pushed alongside TAG (see set_branch_tags).
20+
ALIAS_TAG=""
1921

20-
# branch_tag builds the immutable tag for an environment branch.
22+
# set_branch_tags computes the immutable tag(s) for an environment branch and
23+
# assigns them to the globals TAG and ALIAS_TAG.
2124
#
22-
# When INPUT_DOCKER_TAG_TIMESTAMP is "true" the tag gets a UTC timestamp inserted
23-
# before the short SHA (e.g. dev-20260602143055-abcdef12). This makes branch tags
24-
# sortable by Flux image automation (numerical policy) — the git SHA alone is not
25-
# orderable, so Flux cannot otherwise tell which build is newest. The SHA is kept
26-
# for traceability. When the flag is unset/false the legacy <prefix>-<sha> shape
27-
# is produced, so existing consumers are unaffected.
25+
# When INPUT_DOCKER_TAG_TIMESTAMP is "true" the canonical TAG gets a UTC timestamp
26+
# inserted before the short SHA (e.g. dev-20260602143055-abcdef12). This makes
27+
# branch tags sortable by Flux image automation (numerical policy) — the git SHA
28+
# alone is not orderable, so Flux cannot otherwise tell which build is newest.
29+
# In that case ALIAS_TAG holds the legacy <prefix>-<short-sha> tag, which is also
30+
# pushed: it is the stable per-commit handle that retag-image.sh looks up to find
31+
# the source image for a release, so dropping it would break the release retag.
32+
# The alias does not match Flux's "<prefix>-<digits>-<hex>" pattern, so Flux
33+
# ignores it. When the flag is unset/false only the legacy <prefix>-<short-sha>
34+
# tag is produced, so existing consumers are unaffected.
2835
#
2936
# The timestamp is overridable via BUILD_TIMESTAMP for deterministic tests.
30-
branch_tag() {
37+
set_branch_tags() {
3138
local prefix="$1"
39+
local sha="${GITHUB_SHA::8}"
3240
if [[ "${INPUT_DOCKER_TAG_TIMESTAMP:-false}" == "true" ]]; then
3341
local ts="${BUILD_TIMESTAMP:-$(date -u +%Y%m%d%H%M%S)}"
34-
echo "${prefix}-${ts}-${GITHUB_SHA::8}"
42+
TAG="${prefix}-${ts}-${sha}"
43+
ALIAS_TAG="${prefix}-${sha}"
3544
else
36-
echo "${prefix}-${GITHUB_SHA::8}"
45+
TAG="${prefix}-${sha}"
46+
ALIAS_TAG=""
3747
fi
3848
}
3949

@@ -43,15 +53,15 @@ if [[ -n "${INPUT_DOCKER_CUSTOM_TAG:-}" ]]; then
4353
PUSH="true"
4454
BUILD="${INPUT_DOCKER_DISABLE_RETAGGING:-false}"
4555
elif [[ $GITHUB_REF == refs/heads/master ]]; then
46-
TAG="$(branch_tag master)"
56+
set_branch_tags master
4757
LATEST="master"
4858
PUSH="true"
4959
elif [[ $GITHUB_REF == refs/heads/main ]]; then
50-
TAG="$(branch_tag main)"
60+
set_branch_tags main
5161
LATEST="main"
5262
PUSH="true"
5363
elif [[ $GITHUB_REF == refs/heads/dev ]]; then
54-
TAG="$(branch_tag dev)"
64+
set_branch_tags dev
5565
LATEST="dev"
5666
PUSH="true"
5767
elif [[ $GITHUB_REF == refs/tags/v* ]]; then
@@ -71,6 +81,9 @@ else
7181
fi
7282

7383
TAG_LIST="${INPUT_DOCKER_REGISTRY}/${INPUT_DOCKER_IMAGE}:${TAG}"
84+
if [[ -n "${ALIAS_TAG:-}" ]]; then
85+
TAG_LIST+=",${INPUT_DOCKER_REGISTRY}/${INPUT_DOCKER_IMAGE}:${ALIAS_TAG}"
86+
fi
7487
if [[ -n "${LATEST:-}" ]]; then
7588
TAG_LIST+=",${INPUT_DOCKER_REGISTRY}/${INPUT_DOCKER_IMAGE}:${LATEST}"
7689
fi

tests/generate-tags.bats

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,27 @@ teardown() {
6969
assert_output_value "latest" "dev"
7070
}
7171

72+
@test "timestamp flag pushes a stable <prefix>-<sha> alias in tag_list" {
73+
export INPUT_DOCKER_TAG_TIMESTAMP="true"
74+
export GITHUB_REF="refs/heads/main"
75+
run "$SCRIPT"
76+
assert_success
77+
# canonical timestamped tag + stable sha alias (for release retag) + floating tag
78+
local tag_list
79+
tag_list=$(get_output_value "tag_list")
80+
[[ "$tag_list" == "registry.staffbase.com/my-service:main-20260602143055-abcdef12,registry.staffbase.com/my-service:main-abcdef12,registry.staffbase.com/my-service:main" ]]
81+
}
82+
83+
@test "no <prefix>-<sha> alias is added when timestamp flag is off" {
84+
export GITHUB_REF="refs/heads/main"
85+
run "$SCRIPT"
86+
assert_success
87+
local tag_list
88+
tag_list=$(get_output_value "tag_list")
89+
[[ "$tag_list" != *"my-service:main-abcdef12,"*"my-service:main-abcdef12"* ]]
90+
[[ "$tag_list" == "registry.staffbase.com/my-service:main-abcdef12,registry.staffbase.com/my-service:main" ]]
91+
}
92+
7293
@test "main branch with timestamp flag inserts timestamp before sha" {
7394
export INPUT_DOCKER_TAG_TIMESTAMP="true"
7495
export GITHUB_REF="refs/heads/main"

0 commit comments

Comments
 (0)