Skip to content

Inject git commit info in CLI build - #13508

Merged
marcosnils merged 5 commits into
mainfrom
ci-use-workspace-git
Jul 23, 2026
Merged

marcosnils merged 5 commits into
mainfrom
ci-use-workspace-git

Conversation

@shykes

@shykes shykes commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

NOTE: The test-cache-persistence fix (#13700) is merged to main, but CI runs against the pinned engine v1.0.0-beta.6, which predates it. That check stays red until CI runs an engine that actually contains #13700 — either deploy a build from a commit that includes it, or wait for v1.0.0-beta.8 and bump engineVersion to it.

Problem

dagger version printed a blank commit and dirty state:

commit:      unknown
dirty:       no

The CLI and engine are built inside the Dagger sandbox, which has no .git. Normally go build records the commit and dirty state from the local git checkout — with no .git, that comes out empty.

Solution

The Go build toolchain now reads the git HEAD and dirty state from the caller's Workspace and passes them to go build via -ldflags, matching what a native build records.

Engine bump

We use Workspace.git(), which only exists in the 1.0 engine, so the CI toolchain modules bump to v1.0.0-beta.6. Almost the entire diff is regenerated API clients from that bump, not hand-written code.

Checks

@shykes
shykes force-pushed the better-version-strings branch from 419f54d to 0d114cc Compare June 18, 2026 17:33
@shykes
shykes force-pushed the ci-use-workspace-git branch from fcf2a46 to ac340af Compare June 18, 2026 17:33
@shykes
shykes force-pushed the better-version-strings branch from 0d114cc to 5c7dc48 Compare June 18, 2026 18:20
@shykes
shykes force-pushed the ci-use-workspace-git branch from ac340af to ab283be Compare June 18, 2026 18:20
@tiborvass
tiborvass force-pushed the better-version-strings branch from d702487 to 5f8b7ef Compare June 19, 2026 21:52
@tiborvass
tiborvass force-pushed the better-version-strings branch 12 times, most recently from 103bb31 to 5b58e5e Compare July 2, 2026 06:30
Base automatically changed from better-version-strings to main July 2, 2026 07:00
@tiborvass tiborvass self-assigned this Jul 16, 2026
@shykes
shykes force-pushed the ci-use-workspace-git branch 4 times, most recently from f1482db to 4c0f4ef Compare July 18, 2026 14:39
@shykes
shykes force-pushed the ci-use-workspace-git branch 5 times, most recently from 3b051bf to 8c6376c Compare July 18, 2026 18:03
@shykes shykes changed the title Inject git metadata into CLI build Fix blank commit info in dagger version Jul 18, 2026
@shykes shykes changed the title Fix blank commit info in dagger version Inject git commit info in CLI build Jul 18, 2026
@marcosnils
marcosnils force-pushed the ci-use-workspace-git branch from c7621bf to 3b6bb71 Compare July 18, 2026 18:36
shykes added a commit to dagger/go that referenced this pull request Jul 18, 2026
No longer needed: the dagger repo inlined its own copy
(dagger/dagger#13508) and is moving to stamp VCS metadata into
native build info directly. No consumers remain.
@shykes
shykes force-pushed the ci-use-workspace-git branch from 3b6bb71 to f95951b Compare July 20, 2026 12:45
shykes added a commit to dagger/go that referenced this pull request Jul 20, 2026
No longer needed: the dagger repo inlined its own copy
(dagger/dagger#13508) and is moving to stamp VCS metadata into
native build info directly. No consumers remain.
@shykes
shykes force-pushed the ci-use-workspace-git branch 2 times, most recently from 29e6631 to 627735a Compare July 21, 2026 15:46
shykes added 4 commits July 22, 2026 16:06
Needed for Workspace.git(), which we can use to simplify and speed up our builds, and better showcase what a great Dagger setup can achieve.

The diff is mostly module codegen.

Signed-off-by: Solomon Hykes <[email protected]>
buildinfo is a small wrapper for injecting git metadata into a binary
via -ldflags. We need it because our build runs inside the Dagger sandbox,
without the full .git directory available, which breaks Go's native buildinfo.

Initially we planned on making this helper available to other Go projects, so they too
can sandbox their builds in Dagger without losing vcs metadata. But, we have found a better
solution (instrument 'git' command to inject straight into native buildinfo - not yet implemented).
We no longer plan on making the buildinfo package public. So we're inlining it here.

There are no orthogonal edits - just the code move.

Signed-off-by: Solomon Hykes <[email protected]>
Fix `dagger version` printing a blank commit and dirty state. The CLI
and engine are built inside the Dagger sandbox, which has no .git, so the
git detection `go build` normally does comes up empty.

Instead, this reads the git HEAD and dirty state from the caller's
Workspace and passes them to `go build` via -ldflags, matching what a
native build would record.

Uses the new Workspace.git() API introduced in v1.0.0-beta

Signed-off-by: Solomon Hykes <[email protected]>
The previous approach stored the auto-injected Workspace as a field on
EngineDev (and Builder), and passed it down to the go/cli-dev toolchains.
Because a module object's cache key is its field values, holding a
session-scoped Workspace tainted the cache key of *every* EngineDev
method — so their build results could not be reused across a session or
an engine restart.

Resolve the Workspace to scalar commit/dirty values once, at the point
where it is auto-injected, and thread only those strings through the
toolchains. No module stores or receives a Workspace object for stamping
anymore, so builds stay content-addressed. go/cli-dev gain optional
vcsCommit/vcsDirty args (which take precedence over ws); dev/docs-dev/
release are unchanged and keep passing the Workspace, which is now
resolved to scalars internally.

Regenerated the affected dagger runtime bindings.

Note: cross-restart cache persistence for git-touching builds also
requires WorkspaceGit to be persistable in the dagql disk cache, fixed
separately in #13700.

Signed-off-by: Solomon Hykes <[email protected]>
@marcosnils
marcosnils force-pushed the ci-use-workspace-git branch from 627735a to 43d3c24 Compare July 22, 2026 19:06
@marcosnils marcosnils assigned marcosnils and unassigned tiborvass Jul 22, 2026
@marcosnils
marcosnils force-pushed the ci-use-workspace-git branch from 927e788 to 6dcd814 Compare July 23, 2026 03:22
Signed-off-by: Marcos Lilljedahl <[email protected]>
@marcosnils
marcosnils force-pushed the ci-use-workspace-git branch from 6dcd814 to 0c1e2ad Compare July 23, 2026 03:38
@marcosnils
marcosnils merged commit d7ed8bd into main Jul 23, 2026
87 checks passed
@marcosnils
marcosnils deleted the ci-use-workspace-git branch July 23, 2026 04:49
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.

4 participants