Rung 4/9 — feat(output): Emit a machine-readable build result as JSON and GitHub output - #23
Merged
Conversation
… output Add an exported BuildResult type (BuildLog.Result()) and two emitters: WriteBuildOutput, which prints an indented JSON BuildResult to stdout (or --output-file) when --output-format=json, and WriteGitHubOutput, which appends hash/cache-hit/image/version/primary-tag/tags/platforms to $GITHUB_OUTPUT whenever it is set, regardless of --output-format. On a build failure, cmd/build.go still emits the partial JSON result so a caller can see whatever was computed - eg. the hash - before the error. Implements Phase 2 of PLAN.md (Rung 4 of the stacked branch ladder, feature/build-result on feature/manifest-head-errors). Deferred: the e2e JSON-parseability assertion (needs a real registry) and the kerren/setup-dockem follow-up issue (external repo) - both left unchecked in PLAN.md with a note.
Develop carried rewritten (but patch-equivalent) copies of this branch's logging, tag-resolution and manifest-head commits, plus one new fix: fix(logging), which routed the pre-panic separator in cmd/build.go through LogInfo and dropped the now-unused fmt import. That collided with the build-result work, which had wrapped the same separator in an `outputFormat != "json"` guard so that a JSON run kept stdout free of anything but the result. LogInfo writes to stderr, so the guard's only justification is gone: keep the build-result structure and emit the separator unconditionally through LogInfo, which leaves stdout pure JSON on the failure path as well. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CShtKNBF7tSFSiXBpCPXiB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 2. A pipeline had no way to learn the tag it should deploy, or whether a build actually happened, short of scraping prose from stdout.
Adds
BuildResult+BuildLog.Result(),WriteBuildOutput(--output-format=text|json,--output-file) andWriteGitHubOutput(hash,cache-hit,image,version,primary-tag,tags,platforms).Review focus: that
--output-format=jsonputs only JSON on stdout — the contract downstream pipelines depend on, and only true because of rung 1. Also that$GITHUB_OUTPUTis openedO_APPEND|O_WRONLYand never truncated, since other steps write to the same file.On failure the partial result is still emitted under
--output-format=json, so callers can see the hash computed before the error.Deferred: the e2e JSON-cleanliness assertion (needs a registry; covered by a unit test here) and the follow-up issue on
kerren/setup-dockem(external repo).Merging this completes the v2.6.0 scope — everything to here is additive with no hash change, so users upgrade with no cache impact.
Stack (each PR is based on the one above it — review and merge top-down):
develop← docs ← 1 log-helpers ← 2 resolve-target-tags ← 3 manifest-head-errors ← 4 build-result ← v2.6.0 ← 5 dockerignore-hashing ← 6 dockerignore-default ← 7 buildx-detect ← 8 buildx-build ← 9 buildx-cache ← v3.0.0Verified on every rung:
go build ./...,go vet ./..., and the full non-e2e unit suite. The e2e suite was not run anywhere — no registry credentials in this environment — so any new e2e test is compile-verified only.