Preserve release identity in records and receipts

This commit is contained in:
2026-12-05 21:34:51 +00:00
parent bbee996f84
commit 697ab32715
20 changed files with 343 additions and 44 deletions

View File

@@ -59,6 +59,7 @@ type BuildResult struct {
VersionFormat VersionFormat // selected production identifier format.
VersionPrefix string // selected production identifier prefix.
IdentityKind string // production or diagnostic identity kind.
NotePath string // repository-relative production note path, when applicable.
ModuleDir string // absolute selected module directory.
ModulePath string // selected module's declared Go path.
Tag string // complete tag derived for this version.
@@ -126,6 +127,7 @@ func publicBuildResult(result internalbuild.Result) BuildResult {
VersionFormat: VersionFormat(result.Identity.VersionFormat),
VersionPrefix: result.Identity.VersionPrefix,
IdentityKind: result.Identity.Kind,
NotePath: result.Identity.NotePath,
ModuleDir: result.ModuleDir,
ModulePath: result.ModulePath,
Tag: result.Tag,
@@ -168,7 +170,7 @@ func internalBuildResult(result BuildResult) *internalbuild.Result {
input := internalBuildSpec(&BuildSpec{MainPackage: result.MainPackage, BinaryName: result.BinaryName, Targets: result.Targets})
settings := artifact.NormalizeSettings(input.MainPackage, input.BinaryName, input.Targets)
converted := &internalbuild.Result{RepositoryDir: result.RepositoryDir, ModuleDir: result.ModuleDir, ModulePath: result.ModulePath, Tag: result.Tag, CandidateCommit: result.CandidateCommit, SourceVerified: result.SourceVerified, Settings: settings, Version: result.Version, OutputDir: result.OutputDir, Compiler: result.Compiler}
converted.Identity = releaseidentity.Identity{Kind: result.IdentityKind, SourceDir: result.SourceDir, SourceSubdir: result.SourceSubdir, GoEnabled: result.GoEnabled, Publication: string(result.Publication), VersionFormat: string(result.VersionFormat), VersionPrefix: result.VersionPrefix}
converted.Identity = releaseidentity.Identity{Kind: result.IdentityKind, SourceDir: result.SourceDir, SourceSubdir: result.SourceSubdir, GoEnabled: result.GoEnabled, Publication: string(result.Publication), VersionFormat: string(result.VersionFormat), VersionPrefix: result.VersionPrefix, NotePath: result.NotePath}
for _, artifact := range result.Artifacts {
converted.Artifacts = append(converted.Artifacts, internalbuild.Artifact{Path: artifact.Path, Filename: artifact.Filename, Target: internalbuild.Target{OS: artifact.Target.OS, Arch: artifact.Target.Arch}, SHA256: artifact.SHA256})
}

View File

@@ -2,21 +2,24 @@ package cli
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
"os"
"path"
"path/filepath"
"strings"
"go.maximumdirect.net/releasekit/internal/artifact"
"go.maximumdirect.net/releasekit/internal/releaseidentity"
"go.maximumdirect.net/releasekit/internal/versioncontract"
"golang.org/x/mod/module"
)
const BuildReceiptName = ".releasekit-build.json"
const BuildReceiptSchemaVersion = 1
const BuildReceiptSchemaVersion = 2
type ReceiptTarget struct {
OS string `json:"os"`
@@ -34,6 +37,14 @@ type ReceiptArtifact struct {
type BuildReceipt struct {
SchemaVersion int `json:"schema_version"`
RepositoryDir string `json:"repository_dir"`
SourceDir string `json:"source_dir"`
SourceSubdir string `json:"source_subdir"`
GoEnabled bool `json:"go_enabled"`
Publication string `json:"publication_mode"`
VersionFormat string `json:"version_format"`
VersionPrefix string `json:"version_prefix"`
IdentityKind string `json:"identity_kind"`
NotePath string `json:"note_path,omitempty"`
ModuleDir string `json:"module_dir"`
ModulePath string `json:"module_path"`
Tag string `json:"tag"`
@@ -113,7 +124,6 @@ func LoadBuildReceipt(path string) (BuildReceipt, error) {
defer file.Close()
var receipt BuildReceipt
decoder := json.NewDecoder(file)
decoder.DisallowUnknownFields()
if err := decoder.Decode(&receipt); err != nil {
return BuildReceipt{}, fmt.Errorf("decode build receipt: %w", err)
}
@@ -169,11 +179,8 @@ func validateBuildReceipt(receipt BuildReceipt) error {
if receipt.SchemaVersion != BuildReceiptSchemaVersion {
return fmt.Errorf("unsupported or missing build receipt schema version %d", receipt.SchemaVersion)
}
if !versioncontract.ValidStableVersion(receipt.Version) {
return fmt.Errorf("build receipt has invalid version %q", receipt.Version)
}
if !filepath.IsAbs(receipt.RepositoryDir) || !filepath.IsAbs(receipt.ModuleDir) || !filepath.IsAbs(receipt.OutputDir) {
return errors.New("build receipt repository, module, and output directories must be absolute")
if !filepath.IsAbs(receipt.RepositoryDir) || !filepath.IsAbs(receipt.SourceDir) || !filepath.IsAbs(receipt.ModuleDir) || !filepath.IsAbs(receipt.OutputDir) {
return errors.New("build receipt repository, source, module, and output directories must be absolute")
}
if strings.TrimSpace(receipt.ModulePath) == "" || strings.TrimSpace(receipt.Tag) == "" {
return errors.New("build receipt is missing module path or full tag")
@@ -215,16 +222,65 @@ func validateBuildReceipt(receipt BuildReceipt) error {
func validateRecordedIdentity(receipt BuildReceipt) error {
repositoryDir := filepath.Clean(receipt.RepositoryDir)
moduleDir := filepath.Clean(receipt.ModuleDir)
relative, err := filepath.Rel(repositoryDir, moduleDir)
sourceDir := filepath.Clean(receipt.SourceDir)
relative, err := filepath.Rel(repositoryDir, sourceDir)
if err != nil {
return fmt.Errorf("relate module directory to repository: %w", err)
}
if relative == ".." || strings.HasPrefix(relative, ".."+string(filepath.Separator)) || filepath.IsAbs(relative) {
return errors.New("module directory is outside repository")
return errors.New("source directory is outside repository")
}
if relative == "" {
relative = "."
}
if filepath.ToSlash(relative) != receipt.SourceSubdir || sourceDir != moduleDir || !receipt.GoEnabled {
return errors.New("source and module selections do not match")
}
if err := module.CheckImportPath(receipt.ModulePath); err != nil {
return fmt.Errorf("invalid module path: %w", err)
}
if _, _, ok := module.SplitPathVersion(receipt.ModulePath); !ok {
return errors.New("invalid module path major")
}
if receipt.Publication != "source" && receipt.Publication != "go-module" {
return errors.New("invalid publication mode")
}
if receipt.VersionFormat == "" {
return errors.New("missing version format")
}
_, err = releaseidentity.NormalizeSource("", &releaseidentity.SourceSpec{
Dir: receipt.SourceSubdir, GoEnabled: receipt.GoEnabled, Publication: receipt.Publication,
VersionFormat: receipt.VersionFormat, VersionPrefix: &receipt.VersionPrefix,
})
if err != nil {
return fmt.Errorf("invalid source selection: %w", err)
}
if receipt.Publication == "go-module" && (receipt.VersionFormat != "semver" || receipt.VersionPrefix != "v") {
return errors.New("Go module publication requires prefixed semantic versions")
}
if receipt.IdentityKind == "diagnostic" {
attempt := strings.TrimPrefix(receipt.Version, "releasekit-test-")
if !strings.HasPrefix(receipt.Version, "releasekit-test-") || len(attempt) != 32 || strings.ToLower(attempt) != attempt {
return errors.New("invalid diagnostic version")
}
selector := strings.TrimSuffix(strings.TrimPrefix(receipt.Tag, "releasekit-test/"), "/"+attempt)
if _, err := hex.DecodeString(attempt); err != nil || !strings.HasPrefix(receipt.Tag, "releasekit-test/") || !strings.HasSuffix(receipt.Tag, "/"+attempt) || selector == "" || strings.Contains(selector, "/") {
return errors.New("invalid diagnostic tag")
}
return nil
}
if receipt.IdentityKind != "production" || !versioncontract.ValidIdentifier(receipt.Version, receipt.VersionFormat, receipt.VersionPrefix) {
return errors.New("invalid production identity or version")
}
if receipt.NotePath != path.Join(receipt.SourceSubdir, "docs", "releases", receipt.Version+".md") {
return errors.New("release note path does not match source and version")
}
if receipt.Publication == "source" {
if receipt.Tag != receipt.Version && !strings.HasSuffix(receipt.Tag, "/"+receipt.Version) {
return errors.New("full tag does not match source version")
}
return nil
}
identity, err := releaseidentity.Derive(releaseidentity.Selection{
RepositoryDir: repositoryDir,
ModuleDir: moduleDir,

View File

@@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"os"
"path"
"path/filepath"
"strings"
"testing"
@@ -19,6 +20,7 @@ func TestWriteBuildReceiptReportsTemporaryCleanup(t *testing.T) {
name := "app-v1.2.3-linux-amd64"
receipt := BuildReceipt{
SchemaVersion: BuildReceiptSchemaVersion, RepositoryDir: repository, ModuleDir: repository,
SourceDir: repository, SourceSubdir: ".", GoEnabled: true, Publication: "go-module", VersionFormat: "semver", VersionPrefix: "v", IdentityKind: "production", NotePath: "docs/releases/v1.2.3.md",
ModulePath: "example.com/receipt", Tag: "v1.2.3", CandidateCommit: strings.Repeat("a", 40),
Version: "v1.2.3", MainPackage: ".", BinaryName: "app", Compiler: "go fixture",
Targets: []ReceiptTarget{{OS: "linux", Arch: "amd64"}},
@@ -96,6 +98,14 @@ func TestBuildReceiptRoundTripBindsRootAndNestedModuleIdentity(t *testing.T) {
receipt := BuildReceipt{
SchemaVersion: BuildReceiptSchemaVersion,
RepositoryDir: repositoryDir,
SourceDir: moduleDir,
SourceSubdir: test.moduleDir,
GoEnabled: true,
Publication: "go-module",
VersionFormat: "semver",
VersionPrefix: "v",
IdentityKind: "production",
NotePath: path.Join(test.moduleDir, "docs/releases/v1.2.3.md"),
ModuleDir: moduleDir,
ModulePath: test.modulePath,
Tag: test.tag,
@@ -114,6 +124,22 @@ func TestBuildReceiptRoundTripBindsRootAndNestedModuleIdentity(t *testing.T) {
if err != nil {
t.Fatal(err)
}
data, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
var fields map[string]any
if err := json.Unmarshal(data, &fields); err != nil {
t.Fatal(err)
}
fields["future_field"] = true
data, err = json.Marshal(fields)
if err != nil {
t.Fatal(err)
}
if err := os.WriteFile(path, data, 0600); err != nil {
t.Fatal(err)
}
loaded, err := LoadBuildReceipt(path)
if err != nil {
t.Fatal(err)
@@ -159,15 +185,15 @@ func TestBuildReceiptRoundTripBindsRootAndNestedModuleIdentity(t *testing.T) {
}
}
func TestLoadBuildReceiptRejectsUnknownFieldsAndMultipleValues(t *testing.T) {
func TestLoadBuildReceiptRejectsOldSchemasAndMultipleValues(t *testing.T) {
for _, test := range []struct {
name string
body string
want string
}{
{name: "unknown field", body: `{"schema_version":1,"unexpected":true}`, want: "unknown field"},
{name: "old receipt", body: `{"schema_version":1,"unexpected":true}`, want: "regenerate it with the updated build command"},
{name: "unversioned receipt", body: `{}`, want: "regenerate it with the updated build command"},
{name: "unknown schema", body: `{"schema_version":2}`, want: "regenerate it with the updated build command"},
{name: "unknown schema", body: `{"schema_version":3}`, want: "regenerate it with the updated build command"},
{name: "multiple values", body: `{} {}`, want: "multiple JSON values"},
} {
t.Run(test.name, func(t *testing.T) {
@@ -191,6 +217,7 @@ func TestWriteBuildReceiptRejectsInconsistentRecordedIdentity(t *testing.T) {
outputDir := t.TempDir()
receipt := BuildReceipt{
SchemaVersion: BuildReceiptSchemaVersion,
SourceDir: moduleDir, SourceSubdir: "integrations/ckconfig", GoEnabled: true, Publication: "go-module", VersionFormat: "semver", VersionPrefix: "v", IdentityKind: "production", NotePath: "integrations/ckconfig/docs/releases/v1.2.3.md",
RepositoryDir: repositoryDir, ModuleDir: moduleDir, ModulePath: "example.com/ckconfig", Tag: "v1.2.3",
CandidateCommit: strings.Repeat("a", 40), Version: "v1.2.3", MainPackage: ".", BinaryName: "helper",
OutputDir: outputDir, Targets: []ReceiptTarget{{OS: "linux", Arch: "amd64"}}, Compiler: "go version fixture",
@@ -215,6 +242,7 @@ func TestLoadBuildReceiptRejectsMismatchedModuleIdentity(t *testing.T) {
digest := sha256.Sum256(contents)
receipt := BuildReceipt{
SchemaVersion: BuildReceiptSchemaVersion,
SourceDir: repositoryDir, SourceSubdir: ".", GoEnabled: true, Publication: "go-module", VersionFormat: "semver", VersionPrefix: "v", IdentityKind: "production", NotePath: "docs/releases/v1.2.3.md",
RepositoryDir: repositoryDir, ModuleDir: repositoryDir, ModulePath: "example.com/receipt", Tag: "v1.2.3",
CandidateCommit: strings.Repeat("a", 40), Version: "v1.2.3", MainPackage: ".", BinaryName: "helper",
OutputDir: outputDir, Targets: []ReceiptTarget{{OS: "linux", Arch: "amd64"}}, Compiler: "go version fixture",
@@ -244,3 +272,26 @@ func TestLoadBuildReceiptRejectsMismatchedModuleIdentity(t *testing.T) {
t.Fatalf("LoadBuildReceipt() error = %v, want inconsistent module identity", err)
}
}
func TestDiagnosticBuildReceiptRoundTrip(t *testing.T) {
repo, output := t.TempDir(), t.TempDir()
attempt := strings.Repeat("a", 32)
version := "releasekit-test-" + attempt
name := "helper-" + version + "-linux-amd64"
receipt := BuildReceipt{
SchemaVersion: BuildReceiptSchemaVersion, RepositoryDir: repo, SourceDir: repo, SourceSubdir: ".",
GoEnabled: true, Publication: "go-module", VersionFormat: "semver", VersionPrefix: "v", IdentityKind: "diagnostic",
ModuleDir: repo, ModulePath: "example.com/receipt", Tag: "releasekit-test/root/" + attempt,
CandidateCommit: strings.Repeat("b", 40), Version: version, MainPackage: ".", BinaryName: "helper", Compiler: "go version fixture",
Targets: []ReceiptTarget{{OS: "linux", Arch: "amd64"}},
Artifacts: []ReceiptArtifact{{Path: filepath.Join(output, name), Filename: name, Target: ReceiptTarget{OS: "linux", Arch: "amd64"}, SHA256: strings.Repeat("a", 64)}},
}
path, err := WriteBuildReceipt(output, receipt)
if err != nil {
t.Fatal(err)
}
loaded, err := LoadBuildReceipt(path)
if err != nil || loaded.IdentityKind != "diagnostic" || loaded.Version != version || loaded.Tag != receipt.Tag {
t.Fatalf("diagnostic receipt = %+v, error = %v", loaded, err)
}
}

View File

@@ -646,6 +646,9 @@ func writeDeliveryRecovery(output io.Writer, result releasekit.DeliveryResult) {
func buildResultFromReceipt(receipt cli.BuildReceipt) *releasekit.BuildResult {
result := &releasekit.BuildResult{
RepositoryDir: receipt.RepositoryDir, ModuleDir: receipt.ModuleDir, ModulePath: receipt.ModulePath, Tag: receipt.Tag,
SourceDir: receipt.SourceDir, SourceSubdir: receipt.SourceSubdir, GoEnabled: receipt.GoEnabled,
Publication: releasekit.PublicationMode(receipt.Publication), VersionFormat: releasekit.VersionFormat(receipt.VersionFormat),
VersionPrefix: receipt.VersionPrefix, IdentityKind: receipt.IdentityKind, NotePath: receipt.NotePath,
CandidateCommit: receipt.CandidateCommit, SourceVerified: receipt.SourceVerified,
Version: receipt.Version, MainPackage: receipt.MainPackage, BinaryName: receipt.BinaryName,
OutputDir: receipt.OutputDir, Compiler: receipt.Compiler,
@@ -682,6 +685,14 @@ func receiptFromBuild(result releasekit.BuildResult) cli.BuildReceipt {
receipt := cli.BuildReceipt{
SchemaVersion: cli.BuildReceiptSchemaVersion,
RepositoryDir: result.RepositoryDir,
SourceDir: result.SourceDir,
SourceSubdir: result.SourceSubdir,
GoEnabled: result.GoEnabled,
Publication: string(result.Publication),
VersionFormat: string(result.VersionFormat),
VersionPrefix: result.VersionPrefix,
IdentityKind: result.IdentityKind,
NotePath: result.NotePath,
ModuleDir: result.ModuleDir,
ModulePath: result.ModulePath,
Tag: result.Tag,

View File

@@ -1542,6 +1542,8 @@ func writeDeliveryReceipt(t *testing.T, repository string, settings cli.BuildSet
receipt := cli.BuildReceipt{
SchemaVersion: cli.BuildReceiptSchemaVersion,
RepositoryDir: resolvedRepository, ModuleDir: resolvedRepository, ModulePath: "example.com/cli-candidate", Tag: "v1.2.3",
SourceDir: resolvedRepository, SourceSubdir: ".", GoEnabled: true, Publication: "go-module",
VersionFormat: "semver", VersionPrefix: "v", IdentityKind: "production", NotePath: "docs/releases/v1.2.3.md",
CandidateCommit: cliGitOutput(t, repository, "rev-parse", "HEAD"),
SourceVerified: true,
Version: "v1.2.3", MainPackage: settings.MainPackage, BinaryName: settings.BinaryName,

View File

@@ -22,6 +22,44 @@ import (
"go.maximumdirect.net/releasekit/internal/publish"
)
func TestSourceOnlyPublicationRecoveryAfterLauncherExit(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("fixture executes POSIX recovery commands")
}
repo, remote := newSimplePublishRepository(t, false)
cliGitRun(t, repo, "rm", "go.mod")
writeRepositoryFile(t, repo, "releasekit.json", `{"product":"Example Product","source":{},"version":{"format":"date"}}`)
writeRepositoryFile(t, repo, "docs/releases/2026-12-01.md", "# Example Product 2026-12-01\n\nRelease.\n")
cliGitRun(t, repo, "add", ".")
cliGitRun(t, repo, "commit", "-m", "Configure source only publication")
cliGitRun(t, repo, "push", "origin", "main")
if err := os.WriteFile(filepath.Join(remote, "hooks", "pre-receive"), []byte("#!/bin/sh\nexit 1\n"), 0700); err != nil {
t.Fatal(err)
}
executable := filepath.Join(t.TempDir(), "releasekit")
build := exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), "build", "-o", executable, "./cmd/releasekit")
build.Dir = repositoryRoot(t)
if output, err := build.CombinedOutput(); err != nil {
t.Fatalf("build CLI: %v: %s", err, output)
}
launcher := exec.Command(executable, "publish", "--repo", repo, "2026-12-01")
output, err := launcher.CombinedOutput()
var exitError *exec.ExitError
if !errors.As(err, &exitError) || exitError.ExitCode() != 1 {
t.Fatalf("publication: %v: %s", err, output)
}
command := outputLineValue(string(output), "recovery command: ")
if command == "" || !strings.Contains(command, shellQuote(executable)) {
t.Fatalf("missing installed tool handoff: %s", output)
}
recovery := exec.Command("sh", "-c", command)
recovery.Dir = t.TempDir()
recovered, err := recovery.CombinedOutput()
if !errors.As(err, &exitError) || exitError.ExitCode() != 1 || !strings.Contains(string(recovered), "tag=2026-12-01 state=not_published") {
t.Fatalf("source recovery: %v: %s", err, recovered)
}
}
func TestVendoredAPIOnlyPublicationRecovery(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("fixture executes POSIX recovery commands")

View File

@@ -22,6 +22,14 @@ type recoveryDiagnostic struct {
type safeEvidence struct {
RepositoryDir string `json:"repository_dir,omitempty"`
SourceDir string `json:"source_dir,omitempty"`
SourceSubdir string `json:"source_subdir,omitempty"`
GoEnabled bool `json:"go_enabled,omitempty"`
Publication string `json:"publication_mode,omitempty"`
VersionFormat string `json:"version_format,omitempty"`
VersionPrefix string `json:"version_prefix,omitempty"`
IdentityKind string `json:"identity_kind,omitempty"`
NotePath string `json:"note_path,omitempty"`
ModuleDir string `json:"module_dir,omitempty"`
ModulePath string `json:"module_path,omitempty"`
Version string `json:"version,omitempty"`
@@ -61,6 +69,14 @@ type attemptsDocument struct {
func safe(e releasekit.PublicationEvidence) safeEvidence {
return safeEvidence{
RepositoryDir: git.DisplayDiagnostic(e.RepositoryDir),
SourceDir: git.DisplayDiagnostic(e.SourceDir),
SourceSubdir: git.DisplayDiagnostic(e.SourceSubdir),
GoEnabled: e.GoEnabled,
Publication: git.DisplayDiagnostic(e.Publication),
VersionFormat: git.DisplayDiagnostic(e.VersionFormat),
VersionPrefix: git.DisplayDiagnostic(e.VersionPrefix),
IdentityKind: git.DisplayDiagnostic(e.IdentityKind),
NotePath: git.DisplayDiagnostic(e.NotePath),
ModuleDir: git.DisplayDiagnostic(e.ModuleDir),
ModulePath: git.DisplayDiagnostic(e.ModulePath),
Version: git.DisplayDiagnostic(e.Version),

View File

@@ -3,6 +3,7 @@ package main
import (
"bytes"
"context"
"fmt"
"os"
"path/filepath"
"runtime"
@@ -98,3 +99,22 @@ func TestExpectedSourceChecksTheProfileSelection(t *testing.T) {
t.Fatal("accepted conflicting expected directories")
}
}
func TestCalendarBuildWritesIdentityReceipt(t *testing.T) {
repo := newCLIBuildRepository(t, `package main
import ("fmt"; "os"; "go.maximumdirect.net/releasekit/buildinfo")
func main() { if len(os.Args) == 2 && os.Args[1] == "version" { fmt.Println("fixture", buildinfo.Version()) } }
`)
profile := fmt.Sprintf(`{"product":"Example Product","go":{},"version":{"format":"date"},"build":{"main_package":"./cmd/app","binary_name":"fixture","targets":[%q]}}`, runtime.GOOS+"/"+runtime.GOARCH)
writeRepositoryFile(t, repo, "releasekit.json", profile)
output := t.TempDir()
var stdout, stderr bytes.Buffer
status := run(context.Background(), []string{"build", "--repo", repo, "--output", output, "2026-12-01.1"}, &stdout, &stderr)
if status != 0 {
t.Fatalf("build status = %d, stdout = %q, stderr = %q", status, stdout.String(), stderr.String())
}
receipt, err := cli.LoadBuildReceipt(filepath.Join(output, cli.BuildReceiptName))
if err != nil || receipt.SchemaVersion != 2 || receipt.SourceDir != repo || receipt.SourceSubdir != "." || !receipt.GoEnabled || receipt.Publication != "source" || receipt.VersionFormat != "date" || receipt.VersionPrefix != "" || receipt.IdentityKind != "production" || receipt.Version != "2026-12-01.1" || receipt.Tag != "2026-12-01.1" {
t.Fatalf("calendar receipt = %+v, error = %v", receipt, err)
}
}

View File

@@ -233,9 +233,8 @@ output directory are invalidated; no new receipt is written. An
empty target list returns the source commit without building or writing a
receipt.
The current receipt format supports the legacy prefixed SemVer module identity.
For other source identities, use the Go `Build` API until receipt support is
updated.
The current receipt format carries the selected source and release identity;
receipts from older formats must be regenerated with `build`.
The command returns status 0 on completion, 1 for build or output failure, and
2 for usage, profile, or invalid-version errors. It builds the current source

View File

@@ -137,12 +137,13 @@ RELEASEKIT_GITEA_TOKEN="$GITEA_TOKEN" releasekit deliver --assets dist v1.2.3
The build command does not need delivery credentials. The `--assets DIR`
directory must contain the private `.releasekit-build.json` receipt created by
`build`. ReleaseKit checks its schema, repository, commit, version, resolved
module directory and path, full tag, normalized build settings, and artifact
declarations. Old receipts must be regenerated with the updated `build`
`build`. ReleaseKit checks its schema, repository, commit, source selection,
identity kind, version, module directory and path, full tag, normalized build
settings, and artifact declarations. Old receipts must be regenerated with the updated `build`
command. Delivery verifies the artifact bytes and sizes after read-only
preflight and before any hosted write; caller-owned files remain available for
retries.
retries. See the [receipt format](../integrations/build-receipts.md) for its
identity and compatibility rules.
Ordinary `deliver` does not download application dependencies or change the
checkout.

View File

@@ -0,0 +1,22 @@
# Build receipts
The CLI writes a private `.releasekit-build.json` receipt after a successful
nonempty build. It lets a later `deliver --assets` invocation bind the retained
files to the selected source and release identity. The
[delivery guide](../consumers/delivery.md) describes the workflow and ownership
of those files.
The current receipt uses `schema_version: 2`. Its identity includes the
repository and physical source directories, repository-relative source scope,
Go capability and module identity, publication mode, version format and prefix,
identity kind, exact version, full tag, production note path when applicable,
and captured commit. It also records source verification, compiler and build
settings, output directory, targets, artifact paths, filenames, and SHA-256
digests. A diagnostic identity has a diagnostic version and tag rather than a
production note path.
Readers accept additive unknown fields in schema 2. Older or unsupported
schemas require a new build and receipt. Loading a receipt checks its structure
and declared identity; delivery verifies the selected source and actual artifact
bytes before making hosted writes. A receipt is local coordination evidence, not
a source attestation.

View File

@@ -13,9 +13,17 @@ Each saved attempt is one complete JSON document with this versioned envelope:
```json
{
"format_version": 1,
"format_version": 3,
"evidence": {
"repository_dir": "/work/project",
"source_dir": "/work/project",
"source_subdir": ".",
"go_enabled": true,
"publication_mode": "go-module",
"version_format": "semver",
"version_prefix": "v",
"identity_kind": "production",
"note_path": "docs/releases/v1.2.3.md",
"module_dir": "/work/project",
"module_path": "example.com/project",
"version": "v1.2.3",
@@ -34,20 +42,20 @@ stopped before they were captured; loading preserves that partial evidence and
does not fill fields from the current checkout. Additional fields in a
supported version are ignored. A missing or unsupported version, malformed or
multiple JSON documents, or fields with invalid structural types are reported
as record-format errors. The codec supports versions 1 and 2; no migration from
as record-format errors. The codec reads versions 1, 2, and 3; no migration from
an unsupported version is performed.
Ordinary UTF-8 evidence uses version 1. Evidence containing other pathname or
endpoint bytes uses version 2 with the same `evidence` object and an additional
`evidence_bytes` object. Each entry in `evidence_bytes` uses an evidence field
New records use version 3, including source and selection evidence. Legacy
versions 1 and 2 retain only the evidence they captured. Version 2 and version 3
may include an `evidence_bytes` object for non-UTF-8 string values. Each entry
in `evidence_bytes` uses an evidence field
name and a standard base64 string containing its exact bytes. That entry
supplies the field's value when loading; the writer omits its lossy string form
from `evidence`. Invalid known-field types or base64 encodings produce a
record-format error with the available decoding cause. Unknown field names are
ignored. This representation applies
to every evidence field and preserves the same identity as typed Go evidence.
Older CLIs that support only version 1 report an unsupported version for these
byte-containing records; use a CLI supporting version 2 to load them.
to string evidence fields and preserves the same identity as typed Go evidence.
Older CLIs report an unsupported version for records they cannot read.
The `endpoint` value is stored exactly as captured and may contain credentials.
Private records are sensitive. Do not copy them into public logs or source
@@ -65,7 +73,8 @@ not private attempt records or a Go serialization of public structs.
was read. Available `observed_tag_object` and `observed_commit` fields are
included when present. A `diagnostic` is included for unresolved observation
or record loading failure. Loading failure omits evidence, state, and observed
IDs.
IDs. Safe evidence may include source, capability, publication, and version
selection fields when those were captured.
`publication-attempts` includes `record_dir`, an `attempts` array with each
`record_path` and safe `evidence`, and a `diagnostics` array. A top-level

View File

@@ -229,6 +229,13 @@ and existing cancellation, cleanup, partial-upload, and immutable-retry tests.
## Stage 5: Update identity evidence and publication recovery
**Completed:** Publication records write format 3 and retain legacy readers;
build receipts carry and bind the complete selected identity. Source-only
recovery works after the publishing process exits. Calendar and diagnostic
receipts, exact evidence bytes, recovery, the offline `go test ./...` suite,
and `go run ./internal/apicheck` pass. The committed-pin bootstrap is implemented
in Stage 8.
**Work:** update facade evidence, CLI receipts, publication codecs, recovery
handoffs, and their integration references.

View File

@@ -261,10 +261,8 @@ func validateBuildIdentity(identity releaseidentity.Identity, commit string, bui
if buildRepository != identity.RepositoryDir || buildModule != identity.ModuleDir || build.ModulePath != identity.ModulePath || build.Tag != identity.Tag || build.CandidateCommit != commit || build.Version != identity.Version {
return errors.New("build result does not identify the selected tagged module")
}
if identity.Publication == "source" || build.Identity.Kind != "" {
if build.Identity.Kind != identity.Kind || build.Identity.SourceDir != identity.SourceDir || build.Identity.SourceSubdir != identity.SourceSubdir || build.Identity.GoEnabled != identity.GoEnabled || build.Identity.Publication != identity.Publication || build.Identity.VersionFormat != identity.VersionFormat || build.Identity.VersionPrefix != identity.VersionPrefix {
return errors.New("build result does not match the selected source identity")
}
if build.Identity.Kind != identity.Kind || build.Identity.SourceDir != identity.SourceDir || build.Identity.SourceSubdir != identity.SourceSubdir || build.Identity.GoEnabled != identity.GoEnabled || build.Identity.Publication != identity.Publication || build.Identity.VersionFormat != identity.VersionFormat || build.Identity.VersionPrefix != identity.VersionPrefix {
return errors.New("build result does not match the selected source identity")
}
if len(build.Settings.Targets) == 0 {
return nil

View File

@@ -120,7 +120,12 @@ func Publish(ctx context.Context, request Request) (result Result, resultErr err
result.ModulePath = captured.ModulePath
result.Tag = captured.Tag
result.CandidateCommit = captured.Commit
result.Evidence = Evidence{RepositoryDir: captured.RepositoryDir, ModuleDir: captured.ModuleDir, ModulePath: captured.ModulePath, Version: captured.Version, Tag: captured.Tag, CandidateCommit: captured.Commit, Remote: remoteName}
result.Evidence = Evidence{
RepositoryDir: captured.RepositoryDir, SourceDir: captured.Identity.SourceDir, SourceSubdir: captured.Identity.SourceSubdir,
GoEnabled: captured.Identity.GoEnabled, Publication: captured.Identity.Publication, VersionFormat: captured.Identity.VersionFormat,
VersionPrefix: captured.Identity.VersionPrefix, IdentityKind: captured.Identity.Kind, NotePath: captured.Identity.NotePath,
ModuleDir: captured.ModuleDir, ModulePath: captured.ModulePath, Version: captured.Version, Tag: captured.Tag, CandidateCommit: captured.Commit, Remote: remoteName,
}
if captured.RepositoryDir != "" {
initialized = true
result.Evidence.RecordedAt = time.Now().UTC().Format(time.RFC3339Nano)

View File

@@ -10,6 +10,14 @@ import (
// Evidence is the identity captured when one publication was attempted.
type Evidence struct {
RepositoryDir string `json:"repository_dir,omitempty"`
SourceDir string `json:"source_dir,omitempty"`
SourceSubdir string `json:"source_subdir,omitempty"`
GoEnabled bool `json:"go_enabled"`
Publication string `json:"publication_mode,omitempty"`
VersionFormat string `json:"version_format,omitempty"`
VersionPrefix string `json:"version_prefix"`
IdentityKind string `json:"identity_kind,omitempty"`
NotePath string `json:"note_path,omitempty"`
ModuleDir string `json:"module_dir,omitempty"`
ModulePath string `json:"module_path,omitempty"`
Version string `json:"version,omitempty"`

View File

@@ -19,6 +19,7 @@ import (
const recordFormatVersion = 1
const recordByteFormatVersion = 2
const recordSourceFormatVersion = 3
type recordEnvelope struct {
FormatVersion int `json:"format_version"`
@@ -36,7 +37,7 @@ func LoadEvidence(path string) (Evidence, error) {
if err := json.Unmarshal(data, &envelope); err != nil {
return Evidence{}, &RecoveryError{Kind: "record_format", RecordPath: path, cause: fmt.Errorf("decode record %q: %w", path, err)}
}
if envelope.FormatVersion != recordFormatVersion && envelope.FormatVersion != recordByteFormatVersion {
if envelope.FormatVersion != recordFormatVersion && envelope.FormatVersion != recordByteFormatVersion && envelope.FormatVersion != recordSourceFormatVersion {
return Evidence{}, &RecoveryError{Kind: "record_format", RecordPath: path, cause: fmt.Errorf("record %q has unsupported format version %d", path, envelope.FormatVersion)}
}
if len(envelope.Evidence) == 0 || string(envelope.Evidence) == "null" {
@@ -46,7 +47,7 @@ func LoadEvidence(path string) (Evidence, error) {
if err := json.Unmarshal(envelope.Evidence, &evidence); err != nil {
return Evidence{}, &RecoveryError{Kind: "record_format", RecordPath: path, cause: fmt.Errorf("decode record evidence %q: %w", path, err)}
}
if envelope.FormatVersion == recordByteFormatVersion && len(envelope.EvidenceBytes) > 0 {
if envelope.FormatVersion >= recordByteFormatVersion && len(envelope.EvidenceBytes) > 0 {
var fields map[string]json.RawMessage
if err := json.Unmarshal(envelope.EvidenceBytes, &fields); err != nil {
return Evidence{}, &RecoveryError{Kind: "record_format", RecordPath: path, cause: fmt.Errorf("decode record evidence bytes %q: %w", path, err)}
@@ -76,9 +77,12 @@ type evidenceField struct {
value *string
}
func evidenceFields(e *Evidence) [10]evidenceField {
return [10]evidenceField{
func evidenceFields(e *Evidence) []evidenceField {
return []evidenceField{
{"repository_dir", &e.RepositoryDir}, {"module_dir", &e.ModuleDir},
{"source_dir", &e.SourceDir}, {"source_subdir", &e.SourceSubdir},
{"publication_mode", &e.Publication}, {"version_format", &e.VersionFormat},
{"version_prefix", &e.VersionPrefix}, {"identity_kind", &e.IdentityKind}, {"note_path", &e.NotePath},
{"module_path", &e.ModulePath}, {"version", &e.Version}, {"tag", &e.Tag},
{"candidate_commit", &e.CandidateCommit}, {"tag_object", &e.TagObject},
{"endpoint", &e.Endpoint}, {"remote", &e.Remote}, {"recorded_at", &e.RecordedAt},
@@ -86,7 +90,7 @@ func evidenceFields(e *Evidence) [10]evidenceField {
}
func encodeRecord(evidence Evidence) ([]byte, error) {
envelope := recordEnvelope{FormatVersion: recordFormatVersion}
envelope := recordEnvelope{FormatVersion: recordSourceFormatVersion}
var bytes map[string][]byte
for _, field := range evidenceFields(&evidence) {
if !utf8.ValidString(*field.value) {
@@ -99,7 +103,6 @@ func encodeRecord(evidence Evidence) ([]byte, error) {
}
var err error
if bytes != nil {
envelope.FormatVersion = recordByteFormatVersion
envelope.EvidenceBytes, err = json.Marshal(bytes)
if err != nil {
return nil, err
@@ -109,6 +112,19 @@ func encodeRecord(evidence Evidence) ([]byte, error) {
if err != nil {
return nil, err
}
if len(bytes) != 0 {
var fields map[string]json.RawMessage
if err := json.Unmarshal(envelope.Evidence, &fields); err != nil {
return nil, err
}
for name := range bytes {
delete(fields, name)
}
envelope.Evidence, err = json.Marshal(fields)
if err != nil {
return nil, err
}
}
return json.Marshal(envelope)
}

View File

@@ -62,7 +62,7 @@ func TestLoadEvidenceValidatesKnownByteFieldsAsBase64Strings(t *testing.T) {
func TestRecordsRoundTripNonUTF8Evidence(t *testing.T) {
repo := recordRepo(t)
raw := "path-\xff"
evidence := Evidence{RepositoryDir: raw, ModuleDir: raw, ModulePath: raw, Version: raw, Tag: raw, CandidateCommit: raw, TagObject: raw, Endpoint: raw, Remote: raw, RecordedAt: raw}
evidence := Evidence{RepositoryDir: raw, SourceDir: raw, SourceSubdir: raw, GoEnabled: true, Publication: raw, VersionFormat: raw, VersionPrefix: raw, IdentityKind: raw, NotePath: raw, ModuleDir: raw, ModulePath: raw, Version: raw, Tag: raw, CandidateCommit: raw, TagObject: raw, Endpoint: raw, Remote: raw, RecordedAt: raw}
path, err := SaveEvidence(t.Context(), repo, t.TempDir(), evidence)
if err != nil {
t.Fatal(err)
@@ -76,9 +76,16 @@ func TestRecordsRoundTripNonUTF8Evidence(t *testing.T) {
t.Fatal(err)
}
var envelope recordEnvelope
if err := json.Unmarshal(data, &envelope); err != nil || envelope.FormatVersion != recordByteFormatVersion {
if err := json.Unmarshal(data, &envelope); err != nil || envelope.FormatVersion != recordSourceFormatVersion {
t.Fatalf("byte record envelope: %#v, %v", envelope, err)
}
var fields map[string]json.RawMessage
if err := json.Unmarshal(envelope.Evidence, &fields); err != nil {
t.Fatal(err)
}
if _, ok := fields["version_prefix"]; ok {
t.Fatal("lossy version prefix remained in the evidence object")
}
// Unknown fields remain ignorable; known byte fields retain real codec errors.
for _, test := range []struct {
field string
@@ -168,7 +175,7 @@ func TestLoadEvidenceAcceptsPartialAndRejectsMalformedRecords(t *testing.T) {
if err != nil || got != (Evidence{}) {
t.Fatalf("partial record = %#v, %v", got, err)
}
for name, data := range map[string]string{"bad-json": "{", "unsupported": `{"format_version":3,"evidence":{}}`, "type": `{"format_version":1,"evidence":{"tag":false}}`, "trailing": `{"format_version":1,"evidence":{}} {}`} {
for name, data := range map[string]string{"bad-json": "{", "unsupported": `{"format_version":4,"evidence":{}}`, "type": `{"format_version":1,"evidence":{"tag":false}}`, "trailing": `{"format_version":1,"evidence":{}} {}`} {
t.Run(name, func(t *testing.T) {
path := filepath.Join(dir, name)
if err := os.WriteFile(path, []byte(data), 0600); err != nil {
@@ -215,6 +222,18 @@ func TestLoadEvidenceRequiresOneDocumentAndPreservesSyntaxCause(t *testing.T) {
}
}
func TestLoadSourceEvidenceAcceptsAdditiveFields(t *testing.T) {
path := filepath.Join(t.TempDir(), "record.json")
data := `{"format_version":3,"evidence":{"source_dir":"/repo/config","source_subdir":"config","go_enabled":false,"publication_mode":"source","version_format":"date","version_prefix":"","identity_kind":"production","note_path":"config/docs/releases/2026-12-01.md","future":true},"future":{}}`
if err := os.WriteFile(path, []byte(data), 0600); err != nil {
t.Fatal(err)
}
evidence, err := LoadEvidence(path)
if err != nil || evidence.SourceSubdir != "config" || evidence.Publication != "source" || evidence.VersionFormat != "date" || evidence.IdentityKind != "production" {
t.Fatalf("source evidence = %+v, error = %v", evidence, err)
}
}
func TestLoadEvidenceReadFailureHasTypedError(t *testing.T) {
_, err := LoadEvidence(filepath.Join(t.TempDir(), "missing.json"))
var recovery *RecoveryError

View File

@@ -16,9 +16,17 @@ import (
// credentials; treat this value and saved records as sensitive.
type PublicationEvidence struct {
RepositoryDir string // Git working-directory context for relative endpoints; empty uses the caller's current directory.
SourceDir string // physical source directory captured for this attempt.
SourceSubdir string // repository-relative source directory.
GoEnabled bool // whether Go capability was selected.
Publication string // captured publication mode.
VersionFormat string // captured production identifier format.
VersionPrefix string // captured production identifier prefix.
IdentityKind string // captured identity kind; empty in older records.
NotePath string // repository-relative release-note path.
ModuleDir string // physical module directory captured for this attempt.
ModulePath string // declared module path captured for this attempt.
Version string // semantic version selected for this attempt.
Version string // production identifier selected for this attempt.
Tag string // complete Git tag ref selected for this attempt.
CandidateCommit string // candidate commit captured before publication.
TagObject string // annotated tag object ID captured before pushing, when available.

View File

@@ -73,6 +73,17 @@ func TestSourceOnlyCheckAndPublish(t *testing.T) {
if result.State != releasekit.PublicationPublished || result.SourceDir != checked.SourceDir || result.Tag != checked.Tag || result.CandidateCommit != commit {
t.Fatalf("publication result = %+v", result)
}
if result.RecordError != nil || result.RecordPath == "" {
t.Fatalf("publication record = %q, error = %v", result.RecordPath, result.RecordError)
}
evidence, err := releasekit.LoadPublicationEvidence(result.RecordPath)
if err != nil || evidence.SourceDir != checked.SourceDir || evidence.SourceSubdir != "config" || evidence.GoEnabled || evidence.Publication != "source" || evidence.VersionFormat != "date" || evidence.VersionPrefix != "" || evidence.IdentityKind != "production" || evidence.NotePath != "config/docs/releases/2026-12-01.md" {
t.Fatalf("publication evidence = %+v, error = %v", evidence, err)
}
observation, err := releasekit.ReconcilePublication(t.Context(), evidence)
if err != nil || observation.State != releasekit.PublicationPublished {
t.Fatalf("reconciliation = %+v, error = %v", observation, err)
}
if got := gitText(t, remote, "rev-parse", "refs/tags/config/2026-12-01^{}"); got != commit {
t.Fatalf("remote tag points to %q, want %q", got, commit)
}