Preserve release identity in records and receipts
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user