Add local candidate validation
This commit is contained in:
64
check.go
Normal file
64
check.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package releasekit
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
|
||||
"gitea.maximumdirect.net/eric/ReleaseKit/internal/candidate"
|
||||
)
|
||||
|
||||
// ErrInvalidVersion reports a version that is not stable vMAJOR.MINOR.PATCH.
|
||||
var ErrInvalidVersion = candidate.ErrInvalidVersion
|
||||
|
||||
// Candidate identifies one committed local source revision selected for
|
||||
// validation.
|
||||
type Candidate struct {
|
||||
RepositoryDir string
|
||||
Commit string
|
||||
Version string
|
||||
}
|
||||
|
||||
// ReleaseRequest contains the local inputs used by Check. Remote is retained
|
||||
// for publication operations; Check makes no remote availability claim.
|
||||
type ReleaseRequest struct {
|
||||
RepositoryDir string
|
||||
Product string
|
||||
Version string
|
||||
Remote string
|
||||
Validate func(context.Context, Candidate) error
|
||||
Output io.Writer
|
||||
}
|
||||
|
||||
// Check validates one local, committed release candidate. It requires a clean
|
||||
// worktree and index on main, a committed note matching Product and Version,
|
||||
// and an unused local tag. If Validate is nil, the offline Go test suite runs.
|
||||
// It rechecks branch, HEAD, worktree, index, and local tag state after
|
||||
// validation. Success establishes local candidate evidence only; it does not
|
||||
// establish remote availability.
|
||||
func Check(ctx context.Context, request ReleaseRequest) (Candidate, error) {
|
||||
var validate func(context.Context, candidate.Candidate) error
|
||||
if request.Validate != nil {
|
||||
validate = func(ctx context.Context, captured candidate.Candidate) error {
|
||||
return request.Validate(ctx, Candidate{
|
||||
RepositoryDir: captured.RepositoryDir,
|
||||
Commit: captured.Commit,
|
||||
Version: captured.Version,
|
||||
})
|
||||
}
|
||||
}
|
||||
checked, err := candidate.Check(ctx, candidate.Request{
|
||||
RepositoryDir: request.RepositoryDir,
|
||||
Product: request.Product,
|
||||
Version: request.Version,
|
||||
Validate: validate,
|
||||
Output: request.Output,
|
||||
})
|
||||
if err != nil {
|
||||
return Candidate{}, err
|
||||
}
|
||||
return Candidate{
|
||||
RepositoryDir: checked.RepositoryDir,
|
||||
Commit: checked.Commit,
|
||||
Version: checked.Version,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user