Skip to content

Commit c9ae70d

Browse files
aledbfclaude
andcommitted
fix(release,packaging): prep Docker for release parity, fail-closed packaging, hermetic gitroot test
Addresses four findings: 4. The release gate did not prepare Docker like the main workflow. release.yml's gate-runtime ran `task parity:runtime` without enabling the containerd image store, so its build-cache-export precondition fails on a default-driver runner and a tagged release stalls. Added the same "free disk + containerd store" step the go-cli.yml runtime job uses. 7. The release did not run OCI publish parity. `task parity:publish` runs only on the daily schedule, so a tag could ship a regression in features/templates publish. Added it to gate-runtime after parity:runtime. 5. Packaging could report success without valid metadata. writeCollectionMetadata discarded both the serialize and the write error, and its callers returned success — a full disk / read-only output produced an incomplete package with a success message. It now returns an error that packageCollection and packageSingleItem propagate; publishCollectionWith also checks the previously ignored MkdirTemp error (which left tmpDir="" and scattered artifacts into cwd). 8. Environment-dependent temp-dir test. TestDetectGitRootNotARepo assumed no ancestor of t.TempDir() held a `.git`, and failed when /tmp was itself a repo. Split detectGitRoot into a bounded detectGitRootUntil(dir, ceiling) so the walk can stop at an isolated root; the test now bounds the search and a new case asserts a `.git` above the ceiling is not found while the unbounded walk finds it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent d17abb8 commit c9ae70d

5 files changed

Lines changed: 106 additions & 11 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ jobs:
4545
- uses: actions/checkout@v7
4646
with:
4747
submodules: recursive
48+
# parity:runtime exports build cache (build.cache-to-*, build.output-oci-*),
49+
# which the default docker driver cannot do — its precondition fails ~1s in.
50+
# Enable the containerd image store exactly like the go-cli.yml runtime job,
51+
# or a tagged release stalls on a runner with the default driver. Also free
52+
# the big preinstalled SDKs so the serial image builds don't exhaust the disk.
53+
- name: Free disk space + configure Docker (containerd store)
54+
run: |
55+
echo "before:"; df -h / | tail -1
56+
sudo rm -rf /usr/share/dotnet /opt/ghc /usr/local/lib/android \
57+
/opt/hostedtoolcache/CodeQL /usr/share/swift \
58+
/usr/local/share/boost /usr/lib/jvm || true
59+
sudo docker image prune -af >/dev/null 2>&1 || true
60+
echo "after:"; df -h / | tail -1
61+
echo '{"features":{"containerd-snapshotter":true}}' | sudo tee /etc/docker/daemon.json
62+
sudo systemctl restart docker
63+
docker info -f 'driver={{.DriverStatus}}'
4864
- uses: actions/setup-go@v6
4965
with:
5066
go-version-file: go.mod
@@ -59,6 +75,10 @@ jobs:
5975
- run: task reference
6076
- run: task test:e2e
6177
- run: task parity:runtime
78+
# OCI publish parity (features/templates publish into a throwaway registry).
79+
# Runs daily in go-cli.yml; gate it on release too so a tag cannot ship a
80+
# regression in the publish path that daily CI would only catch afterwards.
81+
- run: task parity:publish
6282
- if: always()
6383
run: task clean
6484

‎internal/cli/collection_commands.go‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,9 @@ func packageCollection(targetFolder, outputDir, collectionType string, forceClea
351351
return &coreerrors.ExitCodeError{Code: 1}
352352
}
353353

354-
writeCollectionMetadata(outputDir, collectionType, collection)
354+
if err := writeCollectionMetadata(outputDir, collectionType, collection); err != nil {
355+
return err
356+
}
355357

356358
logger.Write(fmt.Sprintf("Packaged %d %s(s) to %s", len(collection), collectionType, outputDir), log.LevelInfo)
357359
return nil
@@ -388,22 +390,32 @@ func packageSingleItem(targetFolder, outputDir, collectionType, metaPath string,
388390
}
389391
logger.Write(fmt.Sprintf("Packaged %s '%s'", collectionType, id), log.LevelInfo)
390392

391-
writeCollectionMetadata(outputDir, collectionType, []*orderedmap.OrderedMap{meta})
393+
if err := writeCollectionMetadata(outputDir, collectionType, []*orderedmap.OrderedMap{meta}); err != nil {
394+
return err
395+
}
392396

393397
logger.Write(fmt.Sprintf("Packaged %d %s(s) to %s", 1, collectionType, outputDir), log.LevelInfo)
394398
return nil
395399
}
396400

397401
// writeCollectionMetadata writes devcontainer-collection.json: sourceInformation
398402
// first, then the features/templates array — JSON.stringify(collection, null, 4)
399-
// in TS, so 4-space indentation.
400-
func writeCollectionMetadata(outputDir, collectionType string, collection []*orderedmap.OrderedMap) {
403+
// in TS, so 4-space indentation. Returns an error instead of swallowing a
404+
// marshal/write failure: a full disk or read-only output would otherwise yield an
405+
// incomplete package that the command still reports as a success.
406+
func writeCollectionMetadata(outputDir, collectionType string, collection []*orderedmap.OrderedMap) error {
401407
collMeta := orderedmap.New()
402408
collMeta.Set("sourceInformation", map[string]string{"source": "devcontainer-cli"})
403409
collMeta.Set(fmt.Sprintf("%ss", collectionType), collection)
404-
collData, _ := json.MarshalIndent(collMeta, "", " ")
410+
collData, err := json.MarshalIndent(collMeta, "", " ")
411+
if err != nil {
412+
return fmt.Errorf("serialize collection metadata: %w", err)
413+
}
405414
collPath := filepath.Join(outputDir, "devcontainer-collection.json")
406-
os.WriteFile(collPath, collData, 0644)
415+
if err := os.WriteFile(collPath, collData, 0644); err != nil {
416+
return fmt.Errorf("write collection metadata: %w", err)
417+
}
418+
return nil
407419
}
408420

409421
// publishCollection wires the real OCI registry and process stdout, then
@@ -437,8 +449,12 @@ func publishCollectionWith(ctx context.Context, out Output, reg oci.Registry, ta
437449
Writer: os.Stderr,
438450
})
439451

440-
// Package first
441-
tmpDir, _ := os.MkdirTemp("", fmt.Sprintf("%s-output-", collectionType))
452+
// Package first. A failed MkdirTemp would otherwise leave tmpDir="" and scatter
453+
// the packaged artifacts into the current directory.
454+
tmpDir, err := os.MkdirTemp("", fmt.Sprintf("%s-output-", collectionType))
455+
if err != nil {
456+
return fmt.Errorf("create output dir: %w", err)
457+
}
442458
defer os.RemoveAll(tmpDir)
443459

444460
if err := packageCollection(targetFolder, tmpDir, collectionType, true, logLevelStr); err != nil {

‎internal/cli/collection_commands_test.go‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,24 @@ func TestGenerateDocs_IgnoresTopLevelFiles(t *testing.T) {
120120
}
121121
}
122122

123+
// TestWriteCollectionMetadata_WriteError locks the fix that a failed write of
124+
// devcontainer-collection.json surfaces as an error instead of a false success.
125+
func TestWriteCollectionMetadata_WriteError(t *testing.T) {
126+
// Writing into a directory that does not exist fails; the error must propagate.
127+
missing := filepath.Join(t.TempDir(), "does-not-exist")
128+
if err := writeCollectionMetadata(missing, "feature", nil); err == nil {
129+
t.Fatal("expected an error writing into a missing directory, got nil")
130+
}
131+
// The happy path still writes the file.
132+
ok := t.TempDir()
133+
if err := writeCollectionMetadata(ok, "feature", nil); err != nil {
134+
t.Fatalf("unexpected error on the happy path: %v", err)
135+
}
136+
if _, err := os.Stat(filepath.Join(ok, "devcontainer-collection.json")); err != nil {
137+
t.Errorf("collection metadata not written: %v", err)
138+
}
139+
}
140+
123141
func TestGenerateDocs_SkipsMissingMetadata(t *testing.T) {
124142
base := t.TempDir()
125143
// A directory without a devcontainer-feature.json must be skipped, not error.

‎internal/config/gitroot_test.go‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,38 @@ func TestDetectGitRoot(t *testing.T) {
4040
}
4141

4242
func TestDetectGitRootNotARepo(t *testing.T) {
43-
// A directory with no .git anywhere up to the temp root returns "".
44-
dir := filepath.Join(t.TempDir(), "x", "y")
43+
// Walk within an isolated tree only: bound the search at `root` so the result
44+
// does not depend on whether an ancestor of the system temp dir (e.g. /tmp)
45+
// happens to contain a `.git`.
46+
root := t.TempDir()
47+
dir := filepath.Join(root, "x", "y")
4548
if err := os.MkdirAll(dir, 0o755); err != nil {
4649
t.Fatal(err)
4750
}
48-
if got := detectGitRoot(dir); got != "" {
51+
if got := detectGitRootUntil(dir, root); got != "" {
4952
t.Errorf("non-repo = %q, want empty", got)
5053
}
5154
}
55+
56+
// TestDetectGitRootUntilStopsAtCeiling verifies the ceiling itself: a `.git`
57+
// ABOVE stopAt must not be found, while one AT or BELOW stopAt is.
58+
func TestDetectGitRootUntilStopsAtCeiling(t *testing.T) {
59+
root := t.TempDir()
60+
// A repo marker above the ceiling.
61+
if err := os.MkdirAll(filepath.Join(root, ".git"), 0o755); err != nil {
62+
t.Fatal(err)
63+
}
64+
ceiling := filepath.Join(root, "sub")
65+
nested := filepath.Join(ceiling, "a", "b")
66+
if err := os.MkdirAll(nested, 0o755); err != nil {
67+
t.Fatal(err)
68+
}
69+
// root/.git is above `ceiling`, so bounded walk must not find it.
70+
if got := detectGitRootUntil(nested, ceiling); got != "" {
71+
t.Errorf("bounded walk found a repo above the ceiling: %q", got)
72+
}
73+
// The unbounded walk still finds root/.git.
74+
if got := detectGitRootUntil(nested, ""); got != root {
75+
t.Errorf("unbounded walk = %q, want %q", got, root)
76+
}
77+
}

‎internal/config/loader.go‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,28 @@ func computeWorkspaceConfig(workspace *Workspace, config *DevContainer, mountWor
346346
// `/workspaces/x/../../..`) and a different mount. Returns "" when dir is not
347347
// inside a repository.
348348
func detectGitRoot(dir string) string {
349+
return detectGitRootUntil(dir, "")
350+
}
351+
352+
// detectGitRootUntil is detectGitRoot with an optional ceiling: the walk stops
353+
// (returning "") once it has checked stopAt, so it never ascends past it. stopAt
354+
// == "" walks all the way to the filesystem root. The ceiling exists so tests can
355+
// bound the walk to an isolated tree instead of depending on no ancestor of the
356+
// system temp dir happening to contain a `.git`.
357+
func detectGitRootUntil(dir, stopAt string) string {
349358
dir = filepath.Clean(dir)
359+
if stopAt != "" {
360+
stopAt = filepath.Clean(stopAt)
361+
}
350362
for {
351363
// `.git` is a directory in a normal clone and a regular file (a gitlink)
352364
// in a worktree or submodule checkout — accept either.
353365
if info, err := os.Stat(filepath.Join(dir, ".git")); err == nil && (info.IsDir() || info.Mode().IsRegular()) {
354366
return dir
355367
}
368+
if dir == stopAt {
369+
return "" // reached the ceiling without finding a repo
370+
}
356371
parent := filepath.Dir(dir)
357372
if parent == dir {
358373
return "" // reached the filesystem root without finding a repo

0 commit comments

Comments
 (0)