Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,41 @@ Artifacts are placed in:
./dist/<platform>/<arch>/<binary>
```

Use --out to change the base directory. Relative paths are resolved from the current working directory and can include .. segments.
Each run generates a `builds.manifest` JSON file in the output directory with a digest of all artifacts:

```json
{
"generated_at": "2026-05-17T12:00:00Z",
"targets": 4,
"succeeded": 4,
"failed": 0,
"duration": "12s",
"artifacts": [
{
"path": "linux/amd64/app",
"platform": "linux",
"arch": "amd64",
"size": 5242880,
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
}
]
}
```

The summary also prints artifact paths, sizes, and short SHA256 digests:

```
summary: ok, total=4, succeeded=4, failed=0, elapsed=12s

artifacts: 4 file(s), 20.0 MB total
linux/amd64/app 5.0 MB e3b0c44298fc
linux/arm64/app 5.0 MB 8bb0cf6eb9b1
macos/amd64/app 5.0 MB 1b4f0e9851b4
macos/arm64/app 5.0 MB 92cfceb39d2d
manifest: dist/builds.manifest
```

Use `--out` to change the base directory. Relative paths are resolved from the current working directory and can include .. segments.

## phases

Expand Down
145 changes: 145 additions & 0 deletions internal/build/manifest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package build

import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
"sort"
"strings"
"time"
)

type ManifestEntry struct {
Path string `json:"path"`
Platform string `json:"platform"`
Arch string `json:"arch"`
Size int64 `json:"size"`
SHA256 string `json:"sha256"`
}

type Manifest struct {
GeneratedAt string `json:"generated_at"`
Targets int `json:"targets"`
Succeeded int `json:"succeeded"`
Failed int `json:"failed"`
Duration string `json:"duration"`
Artifacts []ManifestEntry `json:"artifacts"`
}

func BuildManifest(cfg Config, targets []Target, errs []string, duration time.Duration) *Manifest {
baseDir := outputBaseDir(cfg)

targetDirs := make(map[string]struct{ platform, arch string })
for _, t := range targets {
dir := filepath.Join(t.Label, t.GOARCH)
targetDirs[dir] = struct{ platform, arch string }{t.Label, t.GOARCH}
}

m := &Manifest{
GeneratedAt: time.Now().UTC().Format(time.RFC3339),
Targets: len(targets),
Succeeded: len(targets) - len(errs),
Failed: len(errs),
Duration: duration.Round(time.Second).String(),
}

info, err := os.Stat(baseDir)
if err != nil {
return m
}
if !info.IsDir() {
return m
}

filepath.Walk(baseDir, func(path string, info os.FileInfo, err error) error {
if err != nil || info.IsDir() {
return nil
}
rel, err := filepath.Rel(baseDir, path)
if err != nil {
return nil
}
if rel == "builds.manifest" {
return nil
}

entry := ManifestEntry{
Path: filepath.ToSlash(rel),
Size: info.Size(),
}

dir := filepath.Dir(rel)
if ti, ok := targetDirs[dir]; ok {
entry.Platform = ti.platform
entry.Arch = ti.arch
} else {
parts := strings.SplitN(rel, string(filepath.Separator), 3)
if len(parts) >= 2 {
entry.Platform = parts[0]
entry.Arch = parts[1]
}
}

f, err := os.Open(path)
if err != nil {
return nil
}
defer f.Close()
h := sha256.New()
if _, err := io.Copy(h, f); err != nil {
return nil
}
entry.SHA256 = hex.EncodeToString(h.Sum(nil))

m.Artifacts = append(m.Artifacts, entry)
return nil
})

sort.Slice(m.Artifacts, func(i, j int) bool {
return m.Artifacts[i].Path < m.Artifacts[j].Path
})
return m
}

func WriteManifest(baseDir string, m *Manifest) error {
if err := os.MkdirAll(baseDir, 0o755); err != nil {
return err
}
path := filepath.Join(baseDir, "builds.manifest")
data, err := json.MarshalIndent(m, "", " ")
if err != nil {
return err
}
data = append(data, '\n')
return os.WriteFile(path, data, 0o644)
}

func (m *Manifest) TotalSize() int64 {
var total int64
for _, a := range m.Artifacts {
total += a.Size
}
return total
}

func formatSize(bytes int64) string {
switch {
case bytes >= 1024*1024:
return fmt.Sprintf("%.1f MB", float64(bytes)/(1024*1024))
case bytes >= 1024:
return fmt.Sprintf("%.1f KB", float64(bytes)/1024)
default:
return fmt.Sprintf("%d B", bytes)
}
}

func formatSHA256Short(s string) string {
if len(s) < 12 {
return s
}
return s[:12]
}
25 changes: 22 additions & 3 deletions internal/build/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ func Run(ctx context.Context, cfg Config) error {
}
ui.BuildUpdate(label, "done", "")
}
printSummary(cfg, len(targets), errs, time.Since(start))
duration := time.Since(start)
manifest := BuildManifest(cfg, targets, errs, duration)
if err := WriteManifest(outputBaseDir(cfg), manifest); err != nil && cfg.Verbose {
fmt.Fprintf(os.Stderr, "failed to write manifest: %v\n", err)
}
printSummary(cfg, len(targets), errs, duration, manifest)
return handleBuildErrors(cfg, errs)
}

Expand Down Expand Up @@ -152,11 +157,16 @@ func Run(ctx context.Context, cfg Config) error {
for err := range errCh {
errs = append(errs, err.Error())
}
printSummary(cfg, len(targets), errs, time.Since(start))
duration := time.Since(start)
manifest := BuildManifest(cfg, targets, errs, duration)
if err := WriteManifest(outputBaseDir(cfg), manifest); err != nil && cfg.Verbose {
fmt.Fprintf(os.Stderr, "failed to write manifest: %v\n", err)
}
printSummary(cfg, len(targets), errs, duration, manifest)
return handleBuildErrors(cfg, errs)
}

func printSummary(cfg Config, total int, errs []string, duration time.Duration) {
func printSummary(cfg Config, total int, errs []string, duration time.Duration, m *Manifest) {
failed := len(errs)
succeeded := total - failed
status := "ok"
Expand All @@ -171,6 +181,15 @@ func printSummary(cfg Config, total int, errs []string, duration time.Duration)
if cfg.Strict && failed > 0 {
fmt.Fprintf(os.Stdout, "summary: output removed due to strict mode (%s)\n", outputBaseLabel(cfg))
}

if m != nil && len(m.Artifacts) > 0 {
fmt.Fprintln(os.Stdout, "")
fmt.Fprintf(os.Stdout, "artifacts: %d file(s), %s total\n", len(m.Artifacts), formatSize(m.TotalSize()))
for _, a := range m.Artifacts {
fmt.Fprintf(os.Stdout, " %-30s %8s %s\n", a.Path, formatSize(a.Size), formatSHA256Short(a.SHA256))
}
fmt.Fprintf(os.Stdout, "manifest: %s/builds.manifest\n", outputBaseLabel(cfg))
}
}

func handleBuildErrors(cfg Config, errs []string) error {
Expand Down
Loading
Loading