Validate and publish source-only candidates

This commit is contained in:
2026-12-05 21:05:56 +00:00
parent 0f9923d230
commit 3b925231d5
18 changed files with 291 additions and 56 deletions

View File

@@ -10,7 +10,7 @@ import (
"go.maximumdirect.net/releasekit/internal/validation"
)
// ErrInvalidVersion reports a version that is not stable vMAJOR.MINOR.PATCH.
// ErrInvalidVersion reports an identifier that does not match its selected format.
var ErrInvalidVersion = candidate.ErrInvalidVersion
// ErrUnexpectedPushURL reports that the effective publication push URL does
@@ -18,15 +18,22 @@ var ErrInvalidVersion = candidate.ErrInvalidVersion
var ErrUnexpectedPushURL = publish.ErrUnexpectedPushURL
// Candidate identifies one committed local source revision selected for
// validation. ModuleDir is the absolute selected module directory, ModulePath
// is its declared Go import path, and Tag is the complete derived Git tag.
// validation. SourceDir is the absolute selected source directory. ModuleDir
// and ModulePath identify a selected Go module and are empty for source-only
// releases. Tag is the complete derived Git tag.
type Candidate struct {
RepositoryDir string
SourceDir string
SourceSubdir string
GoEnabled bool
Publication PublicationMode
VersionFormat VersionFormat
VersionPrefix string
ModuleDir string
ModulePath string
Tag string
Commit string
Version string // selected stable semantic version.
Version string // selected production identifier.
}
// ReleaseRequest contains the inputs used to validate and optionally build one
@@ -43,7 +50,7 @@ type ReleaseRequest struct {
// the ModuleDir Go-module shorthand.
Source *SourceSpec
Product string
Version string // stable semantic version, independent of the derived Git tag.
Version string // production identifier, independent of the derived Git tag.
Remote string
// ExpectedPushURL optionally requires Publish's resolved push URL to match
// this string exactly before validation or tag creation. Check ignores this
@@ -140,12 +147,10 @@ type GoValidationSpec struct {
}
// Check validates one local, committed release candidate. It requires a clean
// worktree and index on main, a selected module declaration and module-local
// committed note matching Product and Version, and an unused local tag. An
// empty ModuleDir selects the repository root. The module declaration
// determines the full Git tag for the semantic Version. It always runs the
// offline Go test suite with the available compatible local Go toolchain and
// Go host target, then calls
// worktree and index on main, a committed source-local note matching Product
// and Version, and an unused local tag. A Go selection also requires a module
// declaration. Nil Source retains the ModuleDir Go-module shorthand. Check
// runs the offline Go test suite when Go is enabled, then calls
// AdditionalChecks when supplied. Validation.Go.Race runs that one suite with
// the race detector, Validation.Go.FullVet runs go vet after the suite instead
// of test-time vet, and Validation.Go.CompileTargets compiles all packages for
@@ -169,7 +174,7 @@ type GoValidationSpec struct {
// Nil disables the check; an empty object enables it. Outside-checkout
// destinations are reported as out of scope unless the selected specification
// enforces the checkout boundary. Submodule contents remain out of scope.
// The zero values of all selections preserve the ordinary suite. If
// The zero values of the legacy module selections preserve the ordinary suite. If
// Build selects targets, Check builds them after validation in temporary
// storage outside the worktree, then rechecks
// branch, HEAD, worktree, index, and local tag state. Success establishes local
@@ -185,6 +190,12 @@ func Check(ctx context.Context, request ReleaseRequest) (Candidate, error) {
func publicCandidate(checked candidate.Candidate) Candidate {
return Candidate{
RepositoryDir: checked.RepositoryDir,
SourceDir: checked.Identity.SourceDir,
SourceSubdir: checked.Identity.SourceSubdir,
GoEnabled: checked.Identity.GoEnabled,
Publication: PublicationMode(checked.Identity.Publication),
VersionFormat: VersionFormat(checked.Identity.VersionFormat),
VersionPrefix: checked.Identity.VersionPrefix,
ModuleDir: checked.ModuleDir,
ModulePath: checked.ModulePath,
Tag: checked.Tag,
@@ -199,6 +210,7 @@ func candidateRequest(request ReleaseRequest) candidate.Request {
RepositoryDir: request.RepositoryDir,
ModuleDir: request.ModuleDir,
Source: internalSourceSpec(request.Source),
BuildTargets: request.Build != nil && len(request.Build.Targets) != 0,
Product: request.Product,
Version: request.Version,
Validation: validation.Settings{

View File

@@ -279,10 +279,11 @@ func candidateRequest(invocation cli.Invocation, settings cli.Settings, output i
if len(settings.Checks) != 0 {
checks := settings.Checks
request.AdditionalChecks = func(ctx context.Context, candidate releasekit.Candidate) error {
return cli.RunChecks(ctx, candidate.ModuleDir, checks, map[string]string{
return cli.RunChecks(ctx, candidate.SourceDir, checks, map[string]string{
"RELEASEKIT_VERSION": candidate.Version,
"RELEASEKIT_CANDIDATE": candidate.Commit,
"RELEASEKIT_REPOSITORY_DIR": candidate.RepositoryDir,
"RELEASEKIT_SOURCE_DIR": candidate.SourceDir,
"RELEASEKIT_MODULE_DIR": candidate.ModuleDir,
"RELEASEKIT_MODULE_PATH": candidate.ModulePath,
"RELEASEKIT_TAG": candidate.Tag,

View File

@@ -1,8 +1,14 @@
package main
import (
"context"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
releasekit "go.maximumdirect.net/releasekit"
"go.maximumdirect.net/releasekit/cmd/releasekit/internal/cli"
)
@@ -22,3 +28,31 @@ func TestSourceSelectionMapsToRequest(t *testing.T) {
t.Fatal("legacy profile was converted to an explicit source selection")
}
}
func TestSourceCheckCommandUsesSelectedDirectoryAndEnvironment(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("POSIX shell check")
}
repo := t.TempDir()
source := filepath.Join(repo, "config")
if err := os.Mkdir(source, 0755); err != nil {
t.Fatal(err)
}
result := filepath.Join(t.TempDir(), "context")
settings := cli.Settings{Checks: []cli.CheckCommand{{
Args: []string{"sh", "-c", `printf '%s\n' "$PWD" "$RELEASEKIT_SOURCE_DIR" "$RELEASEKIT_MODULE_DIR" "$RELEASEKIT_MODULE_PATH" "$RELEASEKIT_TAG" > "$RESULT"`},
Env: map[string]string{"RESULT": result},
}}}
request := candidateRequest(cli.Invocation{}, settings, nil)
if err := request.AdditionalChecks(context.Background(), releasekit.Candidate{RepositoryDir: repo, SourceDir: source, Tag: "config/v1.0.0"}); err != nil {
t.Fatal(err)
}
data, err := os.ReadFile(result)
if err != nil {
t.Fatal(err)
}
want := strings.Join([]string{source, source, "", "", "config/v1.0.0", ""}, "\n")
if string(data) != want {
t.Fatalf("check context = %q, want %q", data, want)
}
}

View File

@@ -27,7 +27,7 @@ version. The repository argument defaults to the current directory. ReleaseKit
resolves its containing Git checkout root before selecting the module or profile;
the profile defaults to `<repository-root>/releasekit.json`. A successful command prints the
captured module, version, full tag, and commit. It checks the committed release note and
local Git state, runs the standard offline Go test suite (with `-race` when
local Git state, runs the standard offline Go test suite when Go is selected (with `-race` when
`validation.go.race` is true), and runs a separate `go vet -mod=readonly ./...`
pass after successful tests when `validation.go.full_vet` is true. It then runs
selected package compilation and committed Go formatting, followed by
@@ -37,11 +37,12 @@ availability or publish a tag.
The profile's optional `module_dir` selects a repository-relative physical
module directory; omission selects the root module. Validation and configured
product checks use that module selection. Additional check commands run with
the selected module as their working directory and receive
the selected source as their working directory and receive
`RELEASEKIT_VERSION`, `RELEASEKIT_CANDIDATE`, `RELEASEKIT_REPOSITORY_DIR`,
`RELEASEKIT_MODULE_DIR`, `RELEASEKIT_MODULE_PATH`, and `RELEASEKIT_TAG` in their
`RELEASEKIT_SOURCE_DIR`, `RELEASEKIT_MODULE_DIR`, `RELEASEKIT_MODULE_PATH`, and `RELEASEKIT_TAG` in their
environment. These values are added to each child environment without changing
the ReleaseKit process environment.
the ReleaseKit process environment. Module values are empty for source-only
selections.
When `validation.go.compile_targets` is selected, `check` compiles all packages
for each configured `GOOS/GOARCH` pair after tests and full vet, using static
@@ -82,7 +83,7 @@ go run ./cmd/releasekit publish [--repo DIR] [--config FILE] [--expected-module
`publish` reads the same product, remote, validation, and additional-check
settings as `check`. It checks the authoritative remote and validates the
candidate: the single standard offline Go test suite runs first, with `-race`
candidate: when Go is selected, the standard offline Go test suite runs first, with `-race`
when `validation.go.race` is true. When `validation.go.full_vet` is true,
test-time vet is disabled and `go vet -mod=readonly ./...` runs after successful
tests. Selected package compilation and committed Go formatting follow. The

View File

@@ -10,7 +10,11 @@ The current profile fields are:
| Field | Required | Behavior |
| --- | --- | --- |
| `product` | Yes | Product name used by release operations. |
| `module_dir` | No | Repository-relative physical Go module directory with its own `go.mod`; omission selects `.` (the repository root). |
| `module_dir` | No | Repository-relative physical directory; in the legacy model it selects a Go module and defaults to `.`. |
| `source` | No | Explicit source selection with optional `dir` and `tag_prefix`. |
| `go` | No | A non-null object selects Go capability in the explicit model. |
| `publication` | No | Explicit publication `mode`: `source` or `go-module`. |
| `version` | No | Explicit identifier `format` and `prefix`. |
| `remote` | No | Selected Git remote; defaults to `origin`. |
| `expected_push_url` | No | Exact effective push URL required by `publish`; ignored by local `check`. |
| `checks` | No | Ordered additional child commands, each with an argument vector and optional environment map. |
@@ -25,6 +29,22 @@ live either at `integrations/core` or `integrations/core/v2`, while both use the
same full release tag. Root-only profiles can omit `module_dir` and do not need
a module map.
When all four selection objects are absent or null, the legacy selection uses
Go module publication and prefixed stable semantic versions. Any non-null
selection object chooses the explicit model: `source.dir` defaults to `.` or
the supplied `module_dir`, `go` defaults to disabled, and `publication.mode`
defaults to `source`. If both directory fields are supplied they must resolve
to the same physical directory. Go module publication requires `go: {}`.
`version.format` defaults to `semver` and also accepts `date` and `year-month`;
`version.prefix` accepts `v` or an empty string, defaulting to `v` for SemVer
and empty for calendar formats. `source.tag_prefix` overrides the physical
source directory used as the source-tag prefix; an explicit empty string
selects an unprefixed tag. Go module publication requires prefixed SemVer and
rejects tag-prefix overrides that conflict with Go's module tag rules. The Go
facade's `Check` and `Publish` support these
selections; the current CLI version argument is restricted as described in the
[command reference](cli.md).
Each check requires a nonempty `args` array whose first element names the
executable. Arguments are passed directly to the child process; ReleaseKit does
not parse a shell command string. Select a shell explicitly when a check needs
@@ -45,9 +65,11 @@ exist in the candidate, even when no file checks are enabled. Paths are literal,
repository-relative files with no glob semantics and may select a file outside
the chosen module. ReleaseKit deduplicates them with module inputs by path. This
field does not enable any checks or expand Go test, vet, or package-compilation
scope. Automatic file inputs stop at independent nested-module boundaries;
vendored files remain included. Reference inspection can read destinations
elsewhere in the captured repository without adding them to those inputs.
scope. For Go selections, automatic file inputs stop at independent
nested-module boundaries; source-only selections treat nested `go.mod` files
as data. Vendored files remain included. Reference inspection can read
destinations elsewhere in the captured repository without adding them to those
inputs.
`validation.go.race` enables the race detector for the single standard Go test
suite. `validation.go.full_vet` runs a separate native `go vet` pass after that
suite succeeds; ReleaseKit disables test-time vet for that suite to avoid
@@ -59,6 +81,8 @@ This source compatibility check does not name or produce binaries, run a target
executable, or create an artifact manifest. Omitted or empty `compile_targets`
selects no package-compilation pass. When `full_vet` is omitted or false, the
test command keeps its existing vet behavior. These settings are independent.
For source-only selections, Go execution checks and nonempty build targets are
configuration errors; explicitly selected file checks remain available.
`validation.go_format` checks regular committed Go blobs with the Go formatter
used to build ReleaseKit. It uses the selected file inputs, including vendor and
explicit shared files, and ignores

View File

@@ -33,13 +33,23 @@ example, both `integrations/core/v2` and `integrations/core` can declare
`<module>/docs/releases/<version>.md`.
The repository must have a clean index and worktree on `main`, and the selected
version must be stable `vMAJOR.MINOR.PATCH`. The module-local committed
version must match the selected format. With the module shorthand it must be
stable `vMAJOR.MINOR.PATCH`. The module-local committed
`<module>/docs/releases/<version>.md` note must have a first Markdown H1 containing the
product name and exact version as complete title elements. No local tag with
the derived complete tag may already exist. Different modules may use the same
semantic version with distinct notes and tags.
ReleaseKit runs one `go test -mod=readonly -count=1 ./...` suite from the
For an explicit source release, set `Source` on the request. A zero-valued
`SourceSpec` selects the repository root without Go capability; `Dir` selects
a nested physical source directory. Set `GoEnabled` for Go checks, and select
`PublicationGoModule` only when distributing a Go module. `VersionFormat` and
`VersionPrefix` select the production identifier grammar. A source-only check
needs no `go.mod` or Go toolchain, and its automatic file inputs include nested
`go.mod` files as data. The candidate reports its source scope and selection;
module fields are empty when Go is disabled.
When Go is selected, ReleaseKit runs one `go test -mod=readonly -count=1 ./...` suite from the
selected module directory with the available compatible local Go toolchain.
Set `Validation.Go.Race` to run that
suite with `-race`; set `Validation.Go.FullVet` to run
@@ -93,9 +103,9 @@ standard suite, selected vet/format/distribution checks, or Markdown navigation
checks in `AdditionalChecks` or profile `checks`. Keep release-note rules and
consumer-specific assertions—such as tests of maintained examples—in those
product-owned checks.
The `Candidate` supplies both `RepositoryDir` and `ModuleDir`, plus the declared
`ModulePath`, semantic `Version`, and full `Tag`; use its module directory for
module-local product checks. ReleaseKit calls `AdditionalChecks` once after
The `Candidate` supplies `RepositoryDir` and `SourceDir`, plus optional module
fields, the selected `Version`, and full `Tag`; use its source directory for
source-local product checks. ReleaseKit calls `AdditionalChecks` once after
shared validation when supplied.
For local token files, set `Validation.ForbiddenFiles` to the repository-relative

View File

@@ -31,6 +31,9 @@ physical location. `Version` remains the stable semantic version. The note is
the note path but is removed from the tag prefix only when the module path ends
in `/v2`. `PublicationResult` returns the absolute `ModuleDir`, declared
`ModulePath`, complete `Tag`, and existing commit and tag-object evidence.
For general source publication, set `Source` as described in the
[candidate check guide](check.md#local-candidate-check). `PublicationResult`
also reports the selected source directory and capabilities.
The optional `ValidationSpec.SharedFiles` selects additional committed files
for enabled file checks. Its nil and empty-slice behavior is described in the
@@ -44,7 +47,7 @@ when fetch and push URLs differ. A mismatch fails preflight before Go validation
callbacks, or tag creation; detect it with
`errors.Is(err, releasekit.ErrUnexpectedPushURL)`. `Check` ignores this
publication-only field.
It runs one `go test -mod=readonly -count=1 ./...` suite with the available
When Go is selected, it runs one `go test -mod=readonly -count=1 ./...` suite with the available
compatible local Go toolchain. Set `Validation.Go.Race` to run that suite with
`-race`. Set `Validation.Go.FullVet` to run `go vet -mod=readonly ./...` after
successful tests, with test-time vet disabled for that suite. The zero values

View File

@@ -149,6 +149,13 @@ compatibility. Test diagnostic construction through its supported domain seam.
## Stage 3: Generalize committed candidate and publication checks
**Completed:** Candidate checking and publication use the captured source
identity, run Go execution checks only when selected, retain source-scoped file
checks, and pass source context to product commands. A temporary source-only
repository was checked and published to a local Git remote with Go unavailable;
targeted tests, the offline `go test ./...` suite, and `go run ./internal/apicheck`
pass.
**Work:** adapt `internal/candidate`, `internal/validation`, `internal/publish`,
the `Check`/`Publish` facade bridge, and configured child checks.

View File

@@ -35,6 +35,7 @@ type Request struct {
RepositoryDir string
ModuleDir string
Source *releaseidentity.SourceSpec
BuildTargets bool
Product string
Version string
Validation validation.Settings
@@ -69,7 +70,7 @@ func Check(ctx context.Context, request Request) (Candidate, error) {
// including the note bytes from the captured commit. It does not run checks.
func Capture(ctx context.Context, request Request) (Candidate, error) {
captured := Candidate{Version: request.Version}
if !validStableVersion(request.Version) {
if request.Source == nil && !validStableVersion(request.Version) {
return captured, fmt.Errorf("%w: %q", ErrInvalidVersion, request.Version)
}
if strings.TrimSpace(request.Product) == "" {
@@ -99,10 +100,13 @@ func Capture(ctx context.Context, request Request) (Candidate, error) {
captured.ModulePath = identity.ModulePath
captured.Tag = identity.Tag
if err != nil {
if errors.Is(err, versioncontract.ErrInvalidIdentifier) {
return captured, fmt.Errorf("%w: %q", ErrInvalidVersion, request.Version)
}
return captured, fmt.Errorf("resolve selected module release identity: %w", err)
}
if identity.Publication == "source" {
return captured, fmt.Errorf("general source candidate validation is not yet supported")
if !identity.GoEnabled && request.BuildTargets {
return captured, errors.New("build targets require Go capability")
}
note, err := git.ReadCommitFile(ctx, identity.RepositoryDir, state.commit, identity.NotePath)
if err != nil {
@@ -121,6 +125,7 @@ func Capture(ctx context.Context, request Request) (Candidate, error) {
}
captured.Note = string(note)
captured.Identity.Note = captured.Note
return captured, nil
}
@@ -134,6 +139,8 @@ func Validate(ctx context.Context, request Request, captured Candidate) error {
if err := validation.Run(ctx, validation.Request{
RepositoryDir: captured.RepositoryDir,
ModuleDir: captured.ModuleDir,
SourceDir: captured.Identity.SourceDir,
SourceOnly: !captured.Identity.GoEnabled,
Commit: captured.Commit,
Output: request.Output,
Settings: request.Validation,

View File

@@ -46,6 +46,7 @@ type Request struct {
RepositoryDir string
ModuleDir string
Source *releaseidentity.SourceSpec
BuildTargets bool
Product string
Version string
Remote string
@@ -58,6 +59,7 @@ type Request struct {
}
type Result struct {
Identity releaseidentity.Identity
RepositoryDir string
ModuleDir string
ModulePath string
@@ -104,6 +106,7 @@ func Publish(ctx context.Context, request Request) (result Result, resultErr err
RepositoryDir: request.RepositoryDir,
ModuleDir: request.ModuleDir,
Source: request.Source,
BuildTargets: request.BuildTargets,
Product: request.Product,
Version: request.Version,
Validation: request.Validation,
@@ -111,6 +114,7 @@ func Publish(ctx context.Context, request Request) (result Result, resultErr err
Output: request.Output,
}
captured, captureErr := candidate.Capture(ctx, checks)
result.Identity = captured.Identity
result.RepositoryDir = captured.RepositoryDir
result.ModuleDir = captured.ModuleDir
result.ModulePath = captured.ModulePath

View File

@@ -178,7 +178,7 @@ func deriveSelected(ctx context.Context, source ResolvedSource, version, commit
return identity, err
}
if !versioncontract.ValidIdentifier(version, source.VersionFormat, source.VersionPrefix) {
return identity, fmt.Errorf("invalid %s release identifier %q", source.VersionFormat, version)
return identity, fmt.Errorf("%w: %q is not a valid %s identifier", versioncontract.ErrInvalidIdentifier, version, source.VersionFormat)
}
if source.Publication == "source" {
prefix := source.ModuleSubdir

View File

@@ -28,7 +28,7 @@ func BenchmarkSelectInputEntriesByModuleCount(b *testing.B) {
}
b.ReportAllocs()
for b.Loop() {
selected, err := selectInputEntries(entries, byPath, ".", []string{})
selected, err := selectInputEntries(entries, byPath, ".", []string{}, false)
if err != nil || len(selected) != retainedFiles {
b.Fatalf("selected %d files, error=%v; want %d", len(selected), err, retainedFiles)
}

View File

@@ -28,13 +28,14 @@ type CandidateTree struct {
closeErr error
}
// TreeScope selects the automatic input files for one physical module and
// optional repository-shared files. ModuleDir is an absolute path. A nil
// SharedFiles slice selects the optional default files; a non-nil slice
// replaces those defaults.
// TreeScope selects automatic input files under an absolute physical source
// directory and optional repository-shared files. A nil SharedFiles slice
// selects optional defaults; a non-nil slice replaces them. IncludeNestedModules
// treats nested module declarations as ordinary files.
type TreeScope struct {
ModuleDir string
SharedFiles []string
ModuleDir string
SharedFiles []string
IncludeNestedModules bool
}
// ReadCandidateTree enumerates the captured commit without reading from the
@@ -74,7 +75,7 @@ func ReadCandidateTreeForScope(ctx context.Context, repositoryDir, commit string
tree.directories[directory] = struct{}{}
}
}
tree.inputEntries, err = selectInputEntries(entries, tree.byPath, modulePath, scope.SharedFiles)
tree.inputEntries, err = selectInputEntries(entries, tree.byPath, modulePath, scope.SharedFiles, scope.IncludeNestedModules)
if err != nil {
_ = tree.Close()
return nil, err
@@ -94,17 +95,19 @@ func (tree *CandidateTree) InputEntries() []git.TreeEntry {
return append([]git.TreeEntry(nil), tree.inputEntries...)
}
func selectInputEntries(entries []git.TreeEntry, byPath map[string]int, modulePath string, sharedFiles []string) ([]git.TreeEntry, error) {
func selectInputEntries(entries []git.TreeEntry, byPath map[string]int, modulePath string, sharedFiles []string, includeNestedModules bool) ([]git.TreeEntry, error) {
boundaries := make(map[string]struct{})
for _, entry := range entries {
moduleRelative, ok := relativeToModule(entry.Path, modulePath)
if !ok || moduleRelative == "go.mod" || path.Base(moduleRelative) != "go.mod" {
continue
if !includeNestedModules {
for _, entry := range entries {
moduleRelative, ok := relativeToModule(entry.Path, modulePath)
if !ok || moduleRelative == "go.mod" || path.Base(moduleRelative) != "go.mod" {
continue
}
if insideVendor(moduleRelative) {
continue
}
boundaries[path.Dir(entry.Path)] = struct{}{}
}
if insideVendor(moduleRelative) {
continue
}
boundaries[path.Dir(entry.Path)] = struct{}{}
}
selected := make(map[string]git.TreeEntry)
for _, entry := range entries {

View File

@@ -151,6 +151,26 @@ func TestReadCandidateTreeForRootScopeExcludesNestedModules(t *testing.T) {
}
}
func TestSourceScopeIncludesNestedModuleFiles(t *testing.T) {
repository := newTreeRepository(t)
writeTreeFile(t, repository, "config/readme.md", []byte("# Configuration\n"))
writeTreeFile(t, repository, "config/nested/go.mod", []byte("data\n"))
writeTreeFile(t, repository, "config/nested/readme.md", []byte("# Nested\n"))
writeTreeFile(t, repository, "outside/readme.md", []byte("# Outside\n"))
commit := commitCandidateTree(t, repository)
tree, err := ReadCandidateTreeForScope(context.Background(), repository, commit, TreeScope{
ModuleDir: filepath.Join(repository, "config"), SharedFiles: []string{}, IncludeNestedModules: true,
})
if err != nil {
t.Fatal(err)
}
cleanupCandidateTree(t, tree)
want := "config/nested/go.mod\nconfig/nested/readme.md\nconfig/readme.md"
if got := strings.Join(inputPaths(tree), "\n"); got != want {
t.Fatalf("source inputs = %q, want %q", got, want)
}
}
func TestReadCandidateTreeSharedFilesReplaceDefaultsAndDeduplicate(t *testing.T) {
repository := newTreeRepository(t)
writeTreeFile(t, repository, "LICENSE", []byte("default\n"))

View File

@@ -55,6 +55,8 @@ type Target struct {
type Request struct {
RepositoryDir string
ModuleDir string
SourceDir string
SourceOnly bool
Commit string
Output io.Writer
Settings Settings
@@ -64,9 +66,14 @@ type Request struct {
// ReadCandidateTree loads the committed-file inventory when a selected check
// needs file-oriented input.
func (request Request) ReadCandidateTree(ctx context.Context) (*CandidateTree, error) {
directory := request.ModuleDir
if request.SourceOnly {
directory = request.SourceDir
}
return ReadCandidateTreeForScope(ctx, request.RepositoryDir, request.Commit, TreeScope{
ModuleDir: request.ModuleDir,
SharedFiles: request.Settings.SharedFiles,
ModuleDir: directory,
SharedFiles: request.Settings.SharedFiles,
IncludeNestedModules: request.SourceOnly,
})
}
@@ -89,8 +96,14 @@ func Run(ctx context.Context, request Request) error {
}
}
}
if err := runGoChecks(ctx, request); err != nil {
return err
if request.SourceOnly {
if request.Settings.Race || request.Settings.FullVet || len(request.Settings.CompileTargets) != 0 {
return fmt.Errorf("Go execution checks require Go capability")
}
} else {
if err := runGoChecks(ctx, request); err != nil {
return err
}
}
return runTreeChecks(ctx, request)
}

View File

@@ -1,11 +1,15 @@
package versioncontract
import (
"errors"
"strconv"
"strings"
"time"
)
// ErrInvalidIdentifier identifies a production identifier outside its grammar.
var ErrInvalidIdentifier = errors.New("invalid release identifier")
// ValidStableVersion reports whether version uses the selected vMAJOR.MINOR.PATCH form.
func ValidStableVersion(version string) bool {
return ValidIdentifier(version, "semver", "v")

View File

@@ -46,10 +46,16 @@ const (
// PublicationResult describes the publication state reached by this call.
type PublicationResult struct {
RepositoryDir string // absolute source repository path.
SourceDir string // absolute selected source directory.
SourceSubdir string // repository-relative source directory.
GoEnabled bool // whether Go capability was selected.
Publication PublicationMode // selected publication mode.
VersionFormat VersionFormat // selected production identifier format.
VersionPrefix string // selected production identifier prefix.
ModuleDir string // absolute selected module directory.
ModulePath string // selected module's declared Go path.
Tag string // complete selected Git tag.
Version string // selected stable version
Version string // selected production identifier
CandidateCommit string // captured main commit
Endpoint string // captured effective push URL, which may contain credentials
Phase PublicationPhase // last operation phase reached
@@ -60,8 +66,8 @@ type PublicationResult struct {
RecordError error // recording failure, separate from publication outcome and returned error
}
// After publication preflight succeeds, Publish runs one offline Go test suite
// for the captured candidate.
// After publication preflight succeeds, Publish runs the selected offline Go
// test suite when Go capability is enabled.
// Validation.Go.Race enables the race detector for that suite,
// Validation.Go.FullVet runs go vet afterward instead of test-time vet, and
// Validation.Go.CompileTargets compiles all packages for each selected target
@@ -93,6 +99,7 @@ func Publish(ctx context.Context, request ReleaseRequest) (PublicationResult, er
RepositoryDir: candidateInput.RepositoryDir,
ModuleDir: candidateInput.ModuleDir,
Source: candidateInput.Source,
BuildTargets: candidateInput.BuildTargets,
Product: candidateInput.Product,
Version: candidateInput.Version,
Remote: request.Remote,
@@ -105,6 +112,12 @@ func Publish(ctx context.Context, request ReleaseRequest) (PublicationResult, er
})
return PublicationResult{
RepositoryDir: result.RepositoryDir,
SourceDir: result.Identity.SourceDir,
SourceSubdir: result.Identity.SourceSubdir,
GoEnabled: result.Identity.GoEnabled,
Publication: PublicationMode(result.Identity.Publication),
VersionFormat: VersionFormat(result.Identity.VersionFormat),
VersionPrefix: result.Identity.VersionPrefix,
ModuleDir: result.ModuleDir,
ModulePath: result.ModulePath,
Tag: result.Tag,

79
source_publish_test.go Normal file
View File

@@ -0,0 +1,79 @@
package releasekit_test
import (
"context"
"errors"
"os"
"path/filepath"
"runtime"
"testing"
releasekit "go.maximumdirect.net/releasekit"
)
func TestSourceOnlyCheckAndPublish(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("POSIX Go shim")
}
base := t.TempDir()
work := filepath.Join(base, "work")
remote := filepath.Join(base, "remote.git")
gitRun(t, base, "init", "-b", "main", work)
gitRun(t, work, "config", "user.name", "ReleaseKit Test")
gitRun(t, work, "config", "user.email", "releasekit@example.invalid")
writeFile(t, work, "config/docs/releases/2026-12-01.md", "# Config 2026-12-01\n\nConfiguration release.\n")
writeFile(t, work, "config/README.md", "# Configuration\n\nSee [nested](nested/README.md).\n")
writeFile(t, work, "config/nested/go.mod", "data, not a module boundary\n")
writeFile(t, work, "config/nested/README.md", "# Nested\n")
gitRun(t, work, "add", ".")
gitRun(t, work, "commit", "-m", "configuration candidate")
commit := gitText(t, work, "rev-parse", "HEAD")
gitRun(t, base, "init", "--bare", remote)
gitRun(t, work, "remote", "add", "origin", remote)
gitRun(t, work, "push", "origin", "HEAD:refs/heads/main")
shim := t.TempDir()
if err := os.WriteFile(filepath.Join(shim, "go"), []byte("#!/bin/sh\nexit 99\n"), 0700); err != nil {
t.Fatal(err)
}
t.Setenv("PATH", shim+string(os.PathListSeparator)+os.Getenv("PATH"))
var seen releasekit.Candidate
request := releasekit.ReleaseRequest{
RepositoryDir: work, Product: "Config", Version: "2026-12-01",
Source: &releasekit.SourceSpec{Dir: "config", VersionFormat: releasekit.VersionDate},
Validation: releasekit.ValidationSpec{Markdown: &releasekit.MarkdownValidationSpec{}, ForbiddenFiles: []string{"secrets/token"}},
AdditionalChecks: func(_ context.Context, candidate releasekit.Candidate) error { seen = candidate; return nil },
}
checked, err := releasekit.Check(t.Context(), request)
if err != nil {
t.Fatal(err)
}
if checked.SourceDir != filepath.Join(work, "config") || checked.SourceSubdir != "config" || checked.ModuleDir != "" || checked.ModulePath != "" || checked.GoEnabled || checked.Tag != "config/2026-12-01" || checked.Commit != commit || seen != checked {
t.Fatalf("checked candidate = %+v, callback = %+v", checked, seen)
}
badBuild := request
badBuild.Build = &releasekit.BuildSpec{Targets: []releasekit.Target{{OS: "linux", Arch: "amd64"}}}
if _, err := releasekit.Check(t.Context(), badBuild); err == nil {
t.Fatal("source-only check accepted build targets")
}
badGoCheck := request
badGoCheck.Validation.Go.Race = true
if _, err := releasekit.Check(t.Context(), badGoCheck); err == nil {
t.Fatal("source-only check accepted Go execution checks")
}
badVersion := request
badVersion.Version = "2026-02-30"
if _, err := releasekit.Check(t.Context(), badVersion); !errors.Is(err, releasekit.ErrInvalidVersion) {
t.Fatalf("invalid calendar identifier error = %v", err)
}
result, err := releasekit.Publish(t.Context(), request)
if err != nil {
t.Fatal(err)
}
if result.State != releasekit.PublicationPublished || result.SourceDir != checked.SourceDir || result.Tag != checked.Tag || result.CandidateCommit != commit {
t.Fatalf("publication result = %+v", result)
}
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)
}
}