Files
releasekit/publish.go

135 lines
7.3 KiB
Go
Raw Permalink Normal View History

2026-10-05 18:24:37 +00:00
package releasekit
import (
"context"
"go.maximumdirect.net/releasekit/internal/publish"
2026-10-05 18:24:37 +00:00
)
2026-11-02 19:37:29 +00:00
// PublicationState describes one publication attempt or a later observation.
2026-10-05 18:24:37 +00:00
type PublicationState string
const (
// PublicationNotAttempted means no tag push was attempted.
PublicationNotAttempted PublicationState = PublicationState(publish.NotAttempted)
2026-11-02 19:37:29 +00:00
// PublicationNotPublished means the operation established that its tag was
// not published or was absent at observation time. It does not establish that
// the version was never published.
2026-10-05 18:24:37 +00:00
PublicationNotPublished PublicationState = PublicationState(publish.NotPublished)
2026-11-02 19:37:29 +00:00
// PublicationPublished means the intended tag object was pushed successfully
// or observed remotely.
2026-10-05 18:24:37 +00:00
PublicationPublished PublicationState = PublicationState(publish.Published)
2026-11-02 19:37:29 +00:00
// PublicationConflict means an authoritative guard or later observation found
// conflicting state.
2026-10-05 18:24:37 +00:00
PublicationConflict PublicationState = PublicationState(publish.Conflict)
2026-11-02 19:37:29 +00:00
// PublicationUnknown means publication could not be determined from the available evidence.
2026-10-05 18:24:37 +00:00
PublicationUnknown PublicationState = PublicationState(publish.Unknown)
)
type PublicationPhase string
const (
// PublicationPreflight identifies local and remote candidate inspection.
PublicationPreflight PublicationPhase = PublicationPhase(publish.Preflight)
2026-10-06 17:15:46 +00:00
// PublicationValidation identifies the standard suite and additional checks.
2026-10-05 18:24:37 +00:00
PublicationValidation PublicationPhase = PublicationPhase(publish.Validation)
// PublicationTagCreation identifies creation and inspection of the local annotated tag.
PublicationTagCreation PublicationPhase = PublicationPhase(publish.TagCreation)
// PublicationPush identifies the remote tag push attempt.
PublicationPush PublicationPhase = PublicationPhase(publish.Push)
2026-11-02 19:37:29 +00:00
// PublicationReconciliation identifies immediate observation after a push error.
2026-10-05 18:53:44 +00:00
PublicationReconciliation PublicationPhase = PublicationPhase(publish.Reconciliation)
2026-10-05 18:24:37 +00:00
// PublicationComplete identifies a successful tag push.
PublicationComplete PublicationPhase = PublicationPhase(publish.Complete)
)
// PublicationResult describes the publication state reached by this call.
type PublicationResult struct {
2026-11-02 19:03:24 +00:00
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.
2026-11-02 19:03:24 +00:00
ModuleDir string // absolute selected module directory.
ModulePath string // selected module's declared Go path.
Tag string // complete selected Git tag.
Version string // selected production identifier
2026-11-02 19:03:24 +00:00
CandidateCommit string // captured main commit
Endpoint string // captured effective push URL, which may contain credentials
Phase PublicationPhase // last operation phase reached
TagObject string // local annotated tag object ID, when established; a local ref may remain even when empty
State PublicationState // publication outcome for this invocation
Evidence PublicationEvidence // typed evidence for later reconciliation; Endpoint may contain credentials
2026-11-02 19:37:29 +00:00
RecordPath string // absolute private record path when recording succeeds
RecordError error // recording failure, separate from publication outcome and returned error
2026-10-05 18:24:37 +00:00
}
// After publication preflight succeeds, Publish runs the selected offline Go
// test suite when Go capability is enabled.
2026-10-07 22:31:58 +00:00
// Validation.Go.Race enables the race detector for that suite,
2026-10-07 22:27:31 +00:00
// Validation.Go.FullVet runs go vet afterward instead of test-time vet, and
// Validation.Go.CompileTargets compiles all packages for each selected target
// with cgo disabled after tests and vet. Compilation produces no artifacts and
2026-10-07 23:26:48 +00:00
// does not execute target binaries. The selected formatting, distribution,
// file-size, and Markdown checks then run before AdditionalChecks. Markdown is
// disabled when nil and enabled by a non-nil specification; outside-checkout
// destinations are reported as out of scope unless boundary enforcement is
// selected. Submodule contents remain out of scope. ExpectedPushURL, when
// nonempty, is compared exactly with the resolved effective push URL before
// validation; a mismatch returns ErrUnexpectedPushURL. It then calls
// AdditionalChecks when supplied.
2026-10-07 22:31:58 +00:00
// It optionally builds selected targets in temporary storage outside the
// worktree and pushes the exact annotated tag object to the selected remote.
// It returns a result with errors: preflight failures are not_attempted, failed
// authoritative guards are conflict, and errors after local tag creation but
// before push are not_published. A failed push gets one bounded authoritative
// tag query: an exact object match confirms publication, absence is
// not_published, a different object is conflict, and an unreadable result is
// unknown. A nil error means publication is confirmed by the successful push
2026-11-02 19:37:29 +00:00
// or an exact remote object match. Publish records available attempt evidence
// before the tag push when local storage is available; recording failure is
// reported separately in PublicationResult.RecordError and does not change the
// publication outcome. PublicationResult.Evidence can be passed directly to
// ReconcilePublication even when no record was saved.
2026-10-05 18:24:37 +00:00
func Publish(ctx context.Context, request ReleaseRequest) (PublicationResult, error) {
2026-10-07 18:41:29 +00:00
candidateInput := candidateRequest(request)
2026-10-05 18:24:37 +00:00
result, err := publish.Publish(ctx, publish.Request{
2026-10-07 18:41:29 +00:00
RepositoryDir: candidateInput.RepositoryDir,
ModuleDir: candidateInput.ModuleDir,
Source: candidateInput.Source,
BuildTargets: candidateInput.BuildTargets,
2026-10-07 18:41:29 +00:00
Product: candidateInput.Product,
Version: candidateInput.Version,
2026-10-06 17:15:46 +00:00
Remote: request.Remote,
2026-10-07 22:31:58 +00:00
ExpectedPushURL: request.ExpectedPushURL,
RecordDir: request.PublicationRecordDir,
2026-10-07 22:10:34 +00:00
Validation: candidateInput.Validation,
2026-10-07 18:41:29 +00:00
AdditionalChecks: candidateInput.AdditionalChecks,
AfterValidate: candidateInput.AfterValidate,
Output: candidateInput.Output,
2026-10-05 18:24:37 +00:00
})
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,
2026-10-05 18:24:37 +00:00
Version: result.Version,
CandidateCommit: result.CandidateCommit,
Endpoint: result.Endpoint,
Phase: PublicationPhase(result.Phase),
TagObject: result.TagObject,
State: PublicationState(result.State),
Evidence: publicEvidence(result.Evidence),
RecordPath: result.RecordPath,
RecordError: publicRecoveryError(result.RecordError, ""),
}, convertValidationError(err)
2026-10-05 18:24:37 +00:00
}