Merge pull request #829 from samcharles93/fix/update-component-tags

fix(update): build each component from its own approved release tag
This commit is contained in:
sam authored and GitHub committed 2026-09-15 00:19:44 +10:00
commit e2f19c232e
3 files changed
+69 -17

No files matched your search

+1 -1
View File
@@ -83,7 +83,7 @@ automatically and note it in the handoff.
## Build & Test
Commands are defined in `Taskfile.yml` (requires Go 1.26.5,
Commands are defined in `Taskfile.yml` (requires Go 1.27.0,
[Task](https://taskfile.dev), `gofumpt`, `golangci-lint`, and Node/npm).
```bash
+53 -2
View File
@@ -27,7 +27,7 @@ func TestUpdateInstallGatewayOnlySkipsRuntimeWork(t *testing.T) {
assertCallContains(t, calls, "fetch --quiet --tags origin")
assertCallAbsent(t, calls, "git pull")
assertCallContains(t, calls, "git -C", "rev-parse --verify refs/tags/archied/v1.13.0^{commit}")
assertCallContains(t, calls, "checkout --quiet --detach approved-release-commit")
assertCallContains(t, calls, "checkout --quiet --detach archied-v1.13.0")
assertCallContains(t, calls, "go build", "internal/app/archied.runtimeVersion=1.9.9", "./cmd/archied")
assertCallAbsent(t, calls, "./cmd/archie-agent")
assertCallAbsent(t, calls, "docker compose build agent")
@@ -78,6 +78,54 @@ func TestUpdateInstallBothComponentsBuildsDaemonAndManagedWorkerImage(t *testing
}
}
// Components are independently versioned (RELEASING.md), so the newest
// archied/v* and archie/v* tags usually sit on different commits -- gateway-only
// releases are the norm. Each changed component must be built from its own
// approved tag; forcing both tags onto one commit refuses every update once
// the two components' newest releases diverge.
func TestUpdateInstallBuildsEachComponentFromItsOwnTag(t *testing.T) {
result, calls := runUpdateInstallScript(t, map[string]string{
"ARCHIE_UPDATE_DAEMON_PREVIOUS": "1.12.0",
"ARCHIE_UPDATE_DAEMON_VERSION": "1.13.0",
"ARCHIE_UPDATE_AGENT_PREVIOUS": "1.9.9",
"ARCHIE_UPDATE_AGENT_VERSION": "1.10.0",
})
if result.Installed[ComponentDaemon] != "1.13.0" || result.Installed[ComponentAgent] != "1.10.0" {
t.Fatalf("installed = %#v, want both release versions", result.Installed)
}
// The derived fake commits differ per tag, so these assertions fail if
// either component is built from the other's release.
daemonCheckout := indexOfCallContaining(t, calls, "checkout --quiet --detach archied-v1.13.0")
agentCheckout := indexOfCallContaining(t, calls, "checkout --quiet --detach archie-v1.10.0")
daemonBuild := indexOfCallContaining(t, calls, "go build", "./cmd/archied")
agentImageBuild := indexOfCallContaining(t, calls, "docker build")
if daemonCheckout < 0 || agentCheckout < 0 || daemonBuild < 0 || agentImageBuild < 0 {
t.Fatalf("missing expected step: daemon checkout %d, daemon build %d, agent checkout %d, agent image build %d",
daemonCheckout, daemonBuild, agentCheckout, agentImageBuild)
}
if daemonCheckout > daemonBuild {
t.Errorf("daemon binaries must be built from the daemon tag's commit; calls = %#v", calls)
}
if agentCheckout > agentImageBuild {
t.Errorf("the managed worker image must be built from the agent tag's commit; calls = %#v", calls)
}
}
func indexOfCallContaining(t *testing.T, calls []string, fragments ...string) int {
t.Helper()
for i, call := range calls {
matched := true
for _, fragment := range fragments {
matched = matched && strings.Contains(call, fragment)
}
if matched {
return i
}
}
return -1
}
func TestUpdateInstallNoopDoesNotFetchBuildInstallOrRestart(t *testing.T) {
result, calls := runUpdateInstallScript(t, map[string]string{
"ARCHIE_UPDATE_DAEMON_PREVIOUS": "1.13.0",
@@ -326,7 +374,10 @@ case "$*" in
done
: > "$source_dir/docker-compose.yml"
;;
*"rev-parse --verify refs/tags/"*) echo approved-release-commit ;;
*"rev-parse --verify refs/tags/"*)
tag="$(printf '%s' "$*" | sed 's/.*refs\/tags\///; s/\^.*//')"
echo "${tag//\//-}"
;;
esac
`)
writeFakeCommand(t, fakeDir, "go", `
+15 -14
View File
@@ -136,26 +136,23 @@ echo "==> fetching approved component releases"
git clone --quiet --filter=blob:none --no-checkout "$SOURCE_URL" "$source_dir"
git -C "$source_dir" fetch --quiet --tags origin
# Build from the exact approved release commit, not the moving branch tip. A
# temporary worktree keeps the operator's main checkout on its branch.
# Build from the exact approved release commit, not the moving branch tip.
# Resolve each changed component's tag commit independently: components are
# independently versioned (RELEASING.md), so the daemon and agent tags usually
# sit on different commits -- most releases are gateway-only. The first
# checkout is the daemon release when one is being installed, because the
# adapter refresh below reads the scripts of the release being installed; the
# agent image is rebuilt from its own tag's commit further down.
gw_commit=""
rt_commit=""
if [[ ",$components," == *,daemon,* ]]; then
gw_commit="$(git -C "$source_dir" rev-parse --verify "refs/tags/archied/v$GW^{commit}")"
fi
if [[ ",$components," == *,agent,* ]]; then
rt_commit="$(git -C "$source_dir" rev-parse --verify "refs/tags/archie/v$RT^{commit}")"
fi
case "$components" in
daemon) build_commit="$gw_commit" ;;
agent) build_commit="$rt_commit" ;;
daemon,agent)
if [ "$gw_commit" != "$rt_commit" ]; then
echo "approved component tags do not identify the same source commit" >&2
exit 1
fi
build_commit="$gw_commit"
;;
esac
build_commit="$gw_commit"
[ -n "$build_commit" ] || build_commit="$rt_commit"
git -C "$source_dir" checkout --quiet --detach "$build_commit"
cd "$source_dir"
@@ -228,6 +225,10 @@ if [[ ",$components," == *,daemon,* ]]; then
done
fi
if [[ ",$components," == *,agent,* ]]; then
# Independent versioning: the agent tag usually points at a different
# commit than the daemon's, so switch back to it for the image build (a
# no-op checkout for an agent-only update, which never left this commit).
git checkout --quiet --detach "$rt_commit"
echo "==> saving managed worker image $AGENT_IMAGE for rollback"
docker image save --output "$AGENT_IMAGE_BACKUP" "$AGENT_IMAGE"
echo "==> rebuilding managed worker image $AGENT_IMAGE for runtime $RT"