Skip to content

Commit 2ac9c02

Browse files
authored
Merge pull request #151 from Staffbase/CORE-4593_make_timestamped_tags_the_default
CORE-4593 make timestamped floating tags the default
2 parents 94f65be + 735e2bc commit 2ac9c02

4 files changed

Lines changed: 54 additions & 31 deletions

File tree

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Whenever the action updates a GitOps file, it stamps the following annotations o
114114
|------------|-------|
115115
| `deploy.staffbase.com/repositoryFullName` | The source repository in `owner/repo` form (`$GITHUB_REPOSITORY`) |
116116
| `deploy.staffbase.com/commitSha` | The commit SHA being deployed (`$GITHUB_SHA`) |
117-
| `deploy.staffbase.com/version` | The deployed image tag — `dev-<short-sha>` on `dev`, `main-<short-sha>` on `main`, `master-<short-sha>` on `master` (with `docker-tag-timestamp` a UTC timestamp is inserted before the SHA), the version without the leading `v` on `v*` tag pushes, and the tag name on other tag pushes |
117+
| `deploy.staffbase.com/version` | The deployed image tag — `dev-<timestamp>-<short-sha>` on `dev`, `main-<timestamp>-<short-sha>` on `main`, `master-<timestamp>-<short-sha>` on `master` (the UTC timestamp is inserted by default; with `docker-tag-timestamp: 'false'` it falls back to `<prefix>-<short-sha>`), the version without the leading `v` on `v*` tag pushes, and the tag name on other tag pushes |
118118

119119
These keys mirror the [Swarmia Deployment API](https://help.swarmia.com/settings/organization/configuring-deployments-in-swarmia) field names and are read by `flux-deployment-reporter` to report deployments to Swarmia once Flux finishes reconciling.
120120

@@ -126,7 +126,7 @@ These keys mirror the [Swarmia Deployment API](https://help.swarmia.com/settings
126126
| `docker-registry-api` | Docker Registry API (used for retagging without pulling) | `https://registry.staffbase.com/v2/` |
127127
| `docker-image` | Docker Image | |
128128
| `docker-custom-tag` | Docker Custom Tag to be set on the image | |
129-
| `docker-tag-timestamp` | Insert a UTC timestamp into `dev`/`main`/`master` branch tags (`dev-<timestamp>-<short-sha>`) to make them sortable for Flux image automation | `false` |
129+
| `docker-tag-timestamp` | Insert a UTC timestamp into `dev`/`main`/`master` branch tags (`dev-<timestamp>-<short-sha>`) to make them sortable for Flux image automation. Enabled by default; set to `'false'` for the legacy `<prefix>-<short-sha>` format | `true` |
130130
| `docker-tag-keep-v-prefix` | Keep the leading `v` on release (`v*`) tags (`v1.2.3` → `v1.2.3`). Default strips it (`v1.2.3` → `1.2.3`) | `false` |
131131
| `docker-username` | Username for the Docker Registry | |
132132
| `docker-password` | Password for the Docker Registry | |
@@ -159,22 +159,22 @@ These keys mirror the [Swarmia Deployment API](https://help.swarmia.com/settings
159159

160160
The generated image tag depends on the Git ref:
161161

162-
| Ref | Tag (default) | Tag (`docker-tag-timestamp: 'true'`) | Floating tag |
162+
| Ref | Tag (default) | Tag (`docker-tag-timestamp: 'false'`) | Floating tag |
163163
|-----|---------------|--------------------------------------|--------------|
164-
| `dev` branch | `dev-<short-sha>` | `dev-<utc-timestamp>-<short-sha>` | `dev` |
165-
| `main` branch | `main-<short-sha>` | `main-<utc-timestamp>-<short-sha>` | `main` |
166-
| `master` branch | `master-<short-sha>` | `master-<utc-timestamp>-<short-sha>` | `master` |
164+
| `dev` branch | `dev-<utc-timestamp>-<short-sha>` | `dev-<short-sha>` | `dev` |
165+
| `main` branch | `main-<utc-timestamp>-<short-sha>` | `main-<short-sha>` | `main` |
166+
| `master` branch | `master-<utc-timestamp>-<short-sha>` | `master-<short-sha>` | `master` |
167167
| `v*` tag (prod) | the version with the `v` stripped, e.g. `v2025.50.14` → `2025.50.14` (or kept with `docker-tag-keep-v-prefix: 'true'`) | _(unchanged)_ | `latest` |
168168
| other branch | `<short-sha>` (not pushed) | _(unchanged)_ | — |
169169

170-
By default branch tags keep the legacy `<prefix>-<short-sha>` shape. Set
171-
`docker-tag-timestamp: 'true'` to insert a `YYYYMMDDHHMMSS` (UTC) timestamp before
172-
the SHA. This makes branch tags **sortable** so
170+
By default branch tags carry a `YYYYMMDDHHMMSS` (UTC) timestamp inserted before the
171+
SHA. This makes branch tags **sortable** so
173172
[Flux image automation](https://fluxcd.io/flux/components/image/) can pick the
174173
newest build — the Git SHA alone is not orderable. The short SHA is kept for
175-
traceability and Flux sorts on the timestamp only.
174+
traceability and Flux sorts on the timestamp only. Set `docker-tag-timestamp: 'false'`
175+
to fall back to the legacy `<prefix>-<short-sha>` shape.
176176

177-
> **Note:** with `docker-tag-timestamp: 'true'` the build also pushes the plain
177+
> **Note:** with the timestamp enabled (the default) the build also pushes the plain
178178
> `<prefix>-<short-sha>` tag alongside the timestamped one. That stable per-commit
179179
> tag is what the release step retags into the version tag, so it must continue
180180
> to exist. It does not match the `^<prefix>-[0-9]+-[0-9a-f]+$` filter below, so

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ inputs:
1818
description: 'Docker Custom Tag'
1919
required: false
2020
docker-tag-timestamp:
21-
description: 'Insert a UTC timestamp into dev/main/master branch tags (e.g. dev-20260602143055-<short-sha>) to make them sortable for Flux image automation. Opt-in; defaults to the legacy <prefix>-<short-sha> format.'
21+
description: 'Insert a UTC timestamp into dev/main/master branch tags (e.g. dev-20260602143055-<short-sha>) to make them sortable for Flux image automation. Enabled by default; set to ''false'' for the legacy <prefix>-<short-sha> format.'
2222
required: false
23-
default: 'false'
23+
default: 'true'
2424
docker-tag-keep-v-prefix:
2525
description: 'Keep the leading "v" on release (v*) tags (v1.2.3 -> v1.2.3). Opt-in; defaults to stripping it (v1.2.3 -> 1.2.3).'
2626
required: false

scripts/generate-tags.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@ ALIAS_TAG=""
2323
# set_branch_tags computes the immutable tag(s) for an environment branch and
2424
# assigns them to the globals TAG and ALIAS_TAG.
2525
#
26-
# When INPUT_DOCKER_TAG_TIMESTAMP is "true" the canonical TAG gets a UTC timestamp
27-
# inserted before the short SHA (e.g. dev-20260602143055-abcdef12). This makes
28-
# branch tags sortable by Flux image automation (numerical policy) — the Git SHA
29-
# alone is not orderable, so Flux cannot otherwise tell which build is newest.
30-
# In that case ALIAS_TAG holds the legacy <prefix>-<short-sha> tag, which is also
31-
# pushed: it is the stable per-commit handle that retag-image.sh looks up to find
32-
# the source image for a release, so dropping it would break the release retag.
26+
# By default (INPUT_DOCKER_TAG_TIMESTAMP unset or "true") the canonical TAG gets a
27+
# UTC timestamp inserted before the short SHA (e.g. dev-20260602143055-abcdef12).
28+
# This makes branch tags sortable by Flux image automation (numerical policy) — the
29+
# Git SHA alone is not orderable, so Flux cannot otherwise tell which build is
30+
# newest. In that case ALIAS_TAG holds the legacy <prefix>-<short-sha> tag, which is
31+
# also pushed: it is the stable per-commit handle that retag-image.sh looks up to
32+
# find the source image for a release, so dropping it would break the release retag.
3333
# The alias does not match Flux's "<prefix>-<digits>-<hex>" pattern, so Flux
34-
# ignores it. When the flag is unset/false only the legacy <prefix>-<short-sha>
35-
# tag is produced, so existing consumers are unaffected.
34+
# ignores it. Set INPUT_DOCKER_TAG_TIMESTAMP="false" to opt out and produce only the
35+
# legacy <prefix>-<short-sha> tag.
3636
#
3737
# The timestamp is overridable via BUILD_TIMESTAMP for deterministic tests.
3838
set_branch_tags() {
3939
local prefix="$1"
4040
local sha="${GITHUB_SHA::8}"
41-
if [[ "${INPUT_DOCKER_TAG_TIMESTAMP:-false}" == "true" ]]; then
41+
if [[ "${INPUT_DOCKER_TAG_TIMESTAMP:-true}" == "true" ]]; then
4242
local ts="${BUILD_TIMESTAMP:-$(date -u +%Y%m%d%H%M%S)}"
4343
TAG="${prefix}-${ts}-${sha}"
4444
ALIAS_TAG="${prefix}-${sha}"

tests/generate-tags.bats

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ setup() {
1111
export INPUT_DOCKER_IMAGE="my-service"
1212
export INPUT_DOCKER_CUSTOM_TAG=""
1313
export INPUT_DOCKER_DISABLE_RETAGGING="false"
14-
# Timestamp suffix is opt-in; default off so the legacy <prefix>-<sha> format
15-
# is the baseline. Tests that exercise the suffix set the flag explicitly.
14+
# Timestamp suffix is on by default; leaving the flag unset exercises that
15+
# default (the timestamped <prefix>-<ts>-<sha> format). Tests that need the
16+
# legacy shape set the flag to "false" explicitly.
1617
unset INPUT_DOCKER_TAG_TIMESTAMP
1718
# Keeping the "v" prefix on release tags is opt-in; default off.
1819
unset INPUT_DOCKER_TAG_KEEP_V_PREFIX
@@ -30,7 +31,7 @@ teardown() {
3031
export GITHUB_REF="refs/heads/main"
3132
run "$SCRIPT"
3233
assert_success
33-
assert_output_value "tag" "main-abcdef12"
34+
assert_output_value "tag" "main-20260602143055-abcdef12"
3435
assert_output_value "latest" "main"
3536
assert_output_value "push" "true"
3637
assert_output_value "build" "true"
@@ -42,7 +43,7 @@ teardown() {
4243
export GITHUB_REF="refs/heads/master"
4344
run "$SCRIPT"
4445
assert_success
45-
assert_output_value "tag" "master-abcdef12"
46+
assert_output_value "tag" "master-20260602143055-abcdef12"
4647
assert_output_value "latest" "master"
4748
assert_output_value "push" "true"
4849
assert_output_value "build" "true"
@@ -54,13 +55,13 @@ teardown() {
5455
export GITHUB_REF="refs/heads/dev"
5556
run "$SCRIPT"
5657
assert_success
57-
assert_output_value "tag" "dev-abcdef12"
58+
assert_output_value "tag" "dev-20260602143055-abcdef12"
5859
assert_output_value "latest" "dev"
5960
assert_output_value "push" "true"
6061
assert_output_value "build" "true"
6162
}
6263

63-
# --- timestamp suffix (opt-in, Flux-sortable) ---
64+
# --- timestamp suffix (default, Flux-sortable) ---
6465

6566
@test "dev branch with timestamp flag inserts timestamp before sha" {
6667
export INPUT_DOCKER_TAG_TIMESTAMP="true"
@@ -83,6 +84,7 @@ teardown() {
8384
}
8485

8586
@test "no <prefix>-<sha> alias is added when timestamp flag is off" {
87+
export INPUT_DOCKER_TAG_TIMESTAMP="false"
8688
export GITHUB_REF="refs/heads/main"
8789
run "$SCRIPT"
8890
assert_success
@@ -127,12 +129,33 @@ teardown() {
127129
assert_output_value "tag" "2025.50.14"
128130
}
129131

130-
@test "timestamp flag explicitly 'false' produces legacy shape" {
132+
# --- legacy shape (timestamp explicitly off) ---
133+
134+
@test "dev branch with timestamp flag off produces legacy shape" {
131135
export INPUT_DOCKER_TAG_TIMESTAMP="false"
132136
export GITHUB_REF="refs/heads/dev"
133137
run "$SCRIPT"
134138
assert_success
135139
assert_output_value "tag" "dev-abcdef12"
140+
assert_output_value "latest" "dev"
141+
}
142+
143+
@test "main branch with timestamp flag off produces legacy shape" {
144+
export INPUT_DOCKER_TAG_TIMESTAMP="false"
145+
export GITHUB_REF="refs/heads/main"
146+
run "$SCRIPT"
147+
assert_success
148+
assert_output_value "tag" "main-abcdef12"
149+
assert_output_value "latest" "main"
150+
}
151+
152+
@test "master branch with timestamp flag off produces legacy shape" {
153+
export INPUT_DOCKER_TAG_TIMESTAMP="false"
154+
export GITHUB_REF="refs/heads/master"
155+
run "$SCRIPT"
156+
assert_success
157+
assert_output_value "tag" "master-abcdef12"
158+
assert_output_value "latest" "master"
136159
}
137160
# --- version tag ---
138161

@@ -247,7 +270,7 @@ teardown() {
247270
assert_success
248271
local tag_list
249272
tag_list=$(get_output_value "tag_list")
250-
[[ "$tag_list" == "registry.staffbase.com/my-service:main-abcdef12,registry.staffbase.com/my-service:main" ]]
273+
[[ "$tag_list" == "registry.staffbase.com/my-service:main-20260602143055-abcdef12,registry.staffbase.com/my-service:main-abcdef12,registry.staffbase.com/my-service:main" ]]
251274
}
252275

253276
@test "tag_list has no latest suffix for feature branches" {

0 commit comments

Comments
 (0)