Add reusable CI preparation operations
This commit is contained in:
43
internal/preparation/preparation.go
Normal file
43
internal/preparation/preparation.go
Normal file
@@ -0,0 +1,43 @@
|
||||
// Package preparation coordinates explicit local checkout and Go module
|
||||
// preparation operations for consumers and CI adapters.
|
||||
package preparation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/ReleaseKit/internal/candidate"
|
||||
"gitea.maximumdirect.net/eric/ReleaseKit/internal/git"
|
||||
"gitea.maximumdirect.net/eric/ReleaseKit/internal/gotool"
|
||||
"gitea.maximumdirect.net/eric/ReleaseKit/internal/versioncontract"
|
||||
)
|
||||
|
||||
type TaggedCheckoutRequest struct {
|
||||
RepositoryDir string
|
||||
Version string
|
||||
Remote string
|
||||
ExpectedCommit string
|
||||
}
|
||||
|
||||
func PrepareTaggedCheckout(ctx context.Context, request TaggedCheckoutRequest) error {
|
||||
if !versioncontract.ValidStableVersion(request.Version) {
|
||||
return fmt.Errorf("%w: %q", candidate.ErrInvalidVersion, request.Version)
|
||||
}
|
||||
if strings.TrimSpace(request.ExpectedCommit) == "" {
|
||||
return errors.New("expected commit is required")
|
||||
}
|
||||
remote := request.Remote
|
||||
if remote == "" {
|
||||
remote = "origin"
|
||||
}
|
||||
return git.PrepareTaggedCheckout(ctx, request.RepositoryDir, request.Version, remote, request.ExpectedCommit)
|
||||
}
|
||||
|
||||
func PrepareBuildDependencies(ctx context.Context, repositoryDir string) error {
|
||||
if strings.TrimSpace(repositoryDir) == "" {
|
||||
return errors.New("repository directory is required")
|
||||
}
|
||||
return gotool.PrepareBuildDependencies(ctx, repositoryDir)
|
||||
}
|
||||
Reference in New Issue
Block a user