Skip to content

fix(sdk): return a single version tag when a commit has multiple tags - #53

Merged
Jiri Appl (jiria) merged 2 commits into
aclmainfrom
jiria/fix/single-git-version-tag
Aug 26, 2026
Merged

fix(sdk): return a single version tag when a commit has multiple tags#53
Jiri Appl (jiria) merged 2 commits into
aclmainfrom
jiria/fix/single-git-version-tag

Conversation

@jiria

@jiria Jiri Appl (jiria) commented Aug 17, 2026

Copy link
Copy Markdown
Member

Problem

Build acl-pr.20260817.1184334 failed the Build ACL Base Image task on every RPM image leg (amd64 + aarch64, Azure + QEMU) with:

###### Writing versionfile 'sdk_container/.repo/manifests/version.txt' to SDK '4459.0.0', OS '3.0.20260706
3.0.20260809+3.0-1153684
3.0-1179296'. ######

###### Creating a new container 'flatcar-sdk-all-4459.0.0_os-3.0.20260706-3.0-1153684
3.0.20260809-3.0-1179296' ######

Error response from daemon: Invalid container name
(flatcar-sdk-all-4459.0.0_os-3.0.20260706-3.0-1153684
3.0.20260809-3.0-1179296), only [a-zA-Z0-9][a-zA-Z0-9_.-] are allowed

Root cause

acl/build_rpm_image.sh invokes run_sdk_container without -v, so the OS version falls back to get_git_version():

local tag="$(git tag --points-at HEAD)"

git tag --points-at prints one line per tag. Two ACL releases were cut from the same aclmain commit:

$ git tag --points-at origin/aclmain
3.0.20260706-3.0-1153684
3.0.20260809-3.0-1179296

So os_version became a two-line string. strip_version_prefix() then amplified it — vernum_from_version() and build_id_from_version() use sed -n ...p, which also emits one line per match — yielding the exact three-line value seen in the log. run_sdk_container interpolates that into the container name, and Docker rejects it.

Nothing in the PR under test caused this: the build broke the moment a second release tag landed on the already-tagged aclmain commit.

Fix

  • get_git_version() picks the highest version tag deterministically via git for-each-ref --count=1 --sort=-v:refname, with no pipeline, so a git failure is never masked by a trailing tail/head; the git describe fallback is left unpiped so its exit status still propagates.
  • Defense in depth: vernum_from_version() and build_id_from_version() are clamped with head -n 1, so no caller-supplied version (e.g. via -v) can reintroduce a multi-line container name.

Single-tag behaviour is unchanged.

Validation

Exercised the version helpers against the real failing tag set:

=== failing case: commit carrying two release tags ===
strip_version_prefix -> [3.0.20260706+3.0-1153684]
container name       -> [flatcar-sdk-all-4459.0.0_os-3.0.20260706-3.0-1153684]
RESULT: VALID docker container name

=== regression: single-line inputs unchanged ===
3.0.20260809-3.0-1179296   vernum=[3.0.20260809] build=[3.0-1179296] strip=[3.0.20260809+3.0-1179296]
alpha-3244.0.1-nightly2    vernum=[3244.0.1]     build=[nightly2]    strip=[3244.0.1+nightly2]
3244.0.1                   vernum=[3244.0.1]     build=[]            strip=[3244.0.1]
3244.0.1+build7            vernum=[3244.0.1]     build=[build7]      strip=[3244.0.1+build7]

=== get_git_version() on the real multi-tag commit ===
get_git_version picks: [3.0.20260809-3.0-1179296]

bash -n sdk_lib/sdk_container_common.sh passes.

`get_git_version()` used the raw output of `git tag --points-at HEAD`,
which prints one line per tag. Two ACL releases were cut from the same
`aclmain` commit (3.0.20260706-3.0-1153684 and 3.0.20260809-3.0-1179296),
so the OS version became a two-line string.

That multi-line value flowed into `create_versionfile` and into the
container name derived by `run_sdk_container`, producing:

  Error response from daemon: Invalid container name
  (flatcar-sdk-all-4459.0.0_os-3.0.20260706-3.0-1153684
  3.0.20260809-3.0-1179296), only [a-zA-Z0-9][a-zA-Z0-9_.-] are allowed

which failed "Build ACL Base Image" on every RPM image leg (amd64 and
aarch64, Azure and QEMU).

Pick the highest version tag deterministically with `sort -V | tail -n 1`,
and clamp `git describe` to one line. Also clamp `vernum_from_version` and
`build_id_from_version`, whose `sed -n ...p` emits one line per match, so
no caller-supplied version can reintroduce a multi-line container name.

Single-tag behaviour is unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jiria
Jiri Appl (jiria) marked this pull request as ready for review August 25, 2026 20:53
@jiria
Jiri Appl (jiria) requested a review from a team as a code owner August 25, 2026 20:53
Copilot AI lite review requested due to automatic review settings August 25, 2026 20:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens SDK/OS version derivation in sdk_lib/sdk_container_common.sh to prevent multi-line version strings (e.g., when a commit is annotated with multiple release tags) from propagating into the versionfile and Docker container names, which can break container creation.

Changes:

  • Update get_git_version() to deterministically select a single tag when HEAD has multiple tags.
  • Clamp version parsing helpers (vernum_from_version(), build_id_from_version()) to a single output line to prevent multi-line fragments from propagating.
  • Clamp the git describe fallback output to one line.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread sdk_lib/sdk_container_common.sh
Review feedback: `git describe --tags | head -n 1` made the fallback branch
always exit 0, so a `git describe` failure (rc 128) would no longer abort
callers such as `run_sdk_container`, which runs under `set -e` and does a
plain `os_version=$(get_git_version)` assignment.

Use `git for-each-ref --count=1 --sort=-v:refname` to pick the highest tag
directly, and leave `git describe --tags` unpiped so its exit status still
propagates. `git describe` only ever prints one line, so the `head -n 1`
clamp was unnecessary.

Verified `for-each-ref` returns the same tag as `sort -V | tail -n 1` for
the real failing tag pair (3.0.20260706-3.0-1153684 and
3.0.20260809-3.0-1179296), that single-tag and untagged-HEAD behaviour is
unchanged, and that a git failure now yields rc 128 again.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 25, 2026 21:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@jiria
Jiri Appl (jiria) merged commit 032f9a2 into aclmain Aug 26, 2026
23 checks passed
@jiria
Jiri Appl (jiria) deleted the jiria/fix/single-git-version-tag branch August 26, 2026 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants