Validate selected release configuration during readiness
This commit is contained in:
@@ -14,12 +14,16 @@ import (
|
||||
"go.maximumdirect.net/releasekit/internal/git"
|
||||
"go.maximumdirect.net/releasekit/internal/gotool"
|
||||
"go.maximumdirect.net/releasekit/internal/releaseidentity"
|
||||
"go.maximumdirect.net/releasekit/internal/validation"
|
||||
"golang.org/x/mod/modfile"
|
||||
"golang.org/x/mod/module"
|
||||
)
|
||||
|
||||
type Request struct {
|
||||
RepositoryDir, ModuleDir, Product, Remote, ExpectedPushURL, Context string
|
||||
Validation validation.Settings
|
||||
Selector string
|
||||
CIConfigured bool
|
||||
Commit string
|
||||
Source *releaseidentity.SourceSpec
|
||||
Operations []string
|
||||
@@ -102,6 +106,20 @@ func Run(ctx context.Context, request Request) Report {
|
||||
} else {
|
||||
report.note("source", "configuration", "skipped", "dependency", "repository unavailable")
|
||||
}
|
||||
if repoErr == nil && sourceErr == nil && (selected["publication"] || selected["go"]) {
|
||||
report.record("candidate-configuration", "publication", "configuration", validation.ValidateConfiguration(request.Validation, source.GoEnabled))
|
||||
}
|
||||
if selected["rehearsal"] {
|
||||
report.record("ci-credential-declaration", "rehearsal", "configuration", CheckCIConfigured(request.CIConfigured))
|
||||
if repoErr == nil {
|
||||
selector := request.Selector
|
||||
if selector == "" {
|
||||
selector = "root"
|
||||
}
|
||||
report.record("rehearsal-selector", "rehearsal", "configuration", releaseidentity.ValidateDiagnosticSelector(ctx, repository, selector))
|
||||
}
|
||||
}
|
||||
|
||||
if selected["go"] && sourceErr == nil && repoErr == nil && !source.GoEnabled {
|
||||
report.record("go-selection", "go", "configuration", errors.New("Go capability is not declared"))
|
||||
}
|
||||
@@ -406,3 +424,11 @@ func validateBuildSettings(build artifact.Settings) error {
|
||||
func localMainPackage(source releaseidentity.ResolvedSource, name string) bool {
|
||||
return name == "." || strings.HasPrefix(name, "./") || name == source.ModulePath || strings.HasPrefix(name, source.ModulePath+"/")
|
||||
}
|
||||
|
||||
// CheckCIConfigured validates the declaration independently of job secret injection.
|
||||
func CheckCIConfigured(configured bool) error {
|
||||
if !configured {
|
||||
return errors.New("committed profile must declare CI delivery credentials")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -66,8 +66,8 @@ func Start(ctx context.Context, request StartRequest) (Outcome, error) {
|
||||
if request.ObservationTimeout < 0 {
|
||||
return result, errors.New("observation timeout cannot be negative")
|
||||
}
|
||||
if !request.CIConfigured {
|
||||
return result, errors.New("committed profile must declare CI delivery credentials")
|
||||
if err := readiness.CheckCIConfigured(request.CIConfigured); err != nil {
|
||||
return result, err
|
||||
}
|
||||
if request.Backend == nil {
|
||||
return result, errors.New("delivery backend is required")
|
||||
@@ -134,6 +134,7 @@ func Start(ctx context.Context, request StartRequest) (Outcome, error) {
|
||||
return errors.New("delivery settings cannot be validated")
|
||||
},
|
||||
Credential: func() error { return nil }, Delivery: request.Backend.Preflight, RehearsalConfig: wood.ValidateConfiguration, Rehearsal: wood.CheckRepository}
|
||||
input.CIConfigured, input.Selector = request.CIConfigured, selector
|
||||
checked := readiness.Run(ctx, input)
|
||||
var failures []error
|
||||
for _, check := range checked.Checks {
|
||||
|
||||
@@ -33,9 +33,6 @@ func DiagnosticFromAttempt(ctx context.Context, source ResolvedSource, selector,
|
||||
if source.RepositoryDir == "" || source.ModuleDir == "" || source.ModuleSubdir == "" {
|
||||
return identity, fmt.Errorf("incomplete source selection")
|
||||
}
|
||||
if selector == "" || strings.Contains(selector, "/") {
|
||||
return identity, fmt.Errorf("diagnostic selector must be one Git ref component")
|
||||
}
|
||||
if len(attempt) != 32 || strings.ToLower(attempt) != attempt {
|
||||
return identity, fmt.Errorf("invalid diagnostic attempt ID")
|
||||
}
|
||||
@@ -51,8 +48,16 @@ func DiagnosticFromAttempt(ctx context.Context, source ResolvedSource, selector,
|
||||
identity.Tag = "releasekit-test/" + selector + "/" + attempt
|
||||
identity.Version = "releasekit-test-" + attempt
|
||||
identity.Note = fmt.Sprintf("# ReleaseKit diagnostic %s\n\nSelector: %s\nCommit: %s\n", attempt, selector, commit)
|
||||
if err := git.CheckTagRef(ctx, source.RepositoryDir, identity.Tag); err != nil {
|
||||
if err := ValidateDiagnosticSelector(ctx, source.RepositoryDir, selector); err != nil {
|
||||
return identity, fmt.Errorf("invalid diagnostic selector %q: %w", selector, err)
|
||||
}
|
||||
return identity, nil
|
||||
}
|
||||
|
||||
// ValidateDiagnosticSelector checks the selector using the diagnostic ref grammar.
|
||||
func ValidateDiagnosticSelector(ctx context.Context, repository, selector string) error {
|
||||
if selector == "" || strings.Contains(selector, "/") {
|
||||
return fmt.Errorf("diagnostic selector must be one Git ref component")
|
||||
}
|
||||
return git.CheckTagRef(ctx, repository, "releasekit-test/"+selector+"/"+strings.Repeat("0", 32))
|
||||
}
|
||||
|
||||
@@ -79,13 +79,26 @@ func (request Request) ReadCandidateTree(ctx context.Context) (*CandidateTree, e
|
||||
|
||||
// Run executes shared validation for the captured candidate.
|
||||
func Run(ctx context.Context, request Request) error {
|
||||
if request.Settings.FileSize != nil && request.Settings.FileSize.LimitBytes != nil && *request.Settings.FileSize.LimitBytes < 0 {
|
||||
if err := ValidateConfiguration(request.Settings, !request.SourceOnly); err != nil {
|
||||
return err
|
||||
}
|
||||
if !request.SourceOnly {
|
||||
if err := runGoChecks(ctx, request); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return runTreeChecks(ctx, request)
|
||||
}
|
||||
|
||||
// ValidateConfiguration checks selections without executing checks.
|
||||
func ValidateConfiguration(settings Settings, goEnabled bool) error {
|
||||
if settings.FileSize != nil && settings.FileSize.LimitBytes != nil && *settings.FileSize.LimitBytes < 0 {
|
||||
return &Failure{
|
||||
Check: FileSize,
|
||||
Findings: []Finding{{Message: "file size limit must not be negative"}},
|
||||
}
|
||||
}
|
||||
for _, target := range request.Settings.CompileTargets {
|
||||
for _, target := range settings.CompileTargets {
|
||||
if strings.TrimSpace(target.OS) == "" || strings.TrimSpace(target.Arch) == "" || strings.Contains(target.OS, "/") || strings.Contains(target.Arch, "/") {
|
||||
return &Failure{
|
||||
Check: PackageCompile,
|
||||
@@ -96,16 +109,10 @@ func Run(ctx context.Context, request Request) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
if !goEnabled && (settings.Race || settings.FullVet || len(settings.CompileTargets) != 0) {
|
||||
return fmt.Errorf("Go execution checks require Go capability")
|
||||
}
|
||||
return runTreeChecks(ctx, request)
|
||||
return nil
|
||||
}
|
||||
|
||||
func runGoChecks(ctx context.Context, request Request) error {
|
||||
|
||||
Reference in New Issue
Block a user