Make product checks additive

This commit is contained in:
2026-10-06 17:15:46 +00:00
parent 08093124af
commit 3e9b5c1b99
23 changed files with 368 additions and 169 deletions

View File

@@ -26,12 +26,12 @@ type Candidate struct {
}
type Request struct {
RepositoryDir string
Product string
Version string
Validate func(context.Context, Candidate) error
AfterValidate func(context.Context, Candidate) error
Output io.Writer
RepositoryDir string
Product string
Version string
AdditionalChecks func(context.Context, Candidate) error
AfterValidate func(context.Context, Candidate) error
Output io.Writer
}
func Check(ctx context.Context, request Request) (Candidate, error) {
@@ -95,18 +95,17 @@ func Capture(ctx context.Context, request Request) (Candidate, error) {
return Candidate{RepositoryDir: repositoryDir, Commit: state.commit, Version: request.Version, Note: string(note)}, nil
}
// Validate runs the complete selected validation once for the captured
// candidate. A supplied callback replaces the default offline Go validation.
// Validate runs the standard offline Go suite, followed by AdditionalChecks
// when supplied, for the captured candidate.
func Validate(ctx context.Context, request Request, captured Candidate) error {
var err error
if request.Validate == nil {
err = runDefaultValidation(ctx, captured.RepositoryDir, request.Output)
} else {
err = request.Validate(ctx, captured)
}
if err != nil {
if err := runDefaultValidation(ctx, captured.RepositoryDir, request.Output); err != nil {
return fmt.Errorf("validate candidate %s: %w", captured.Commit, err)
}
if request.AdditionalChecks != nil {
if err := request.AdditionalChecks(ctx, captured); err != nil {
return fmt.Errorf("validate candidate %s: %w", captured.Commit, err)
}
}
return nil
}