50 lines
1.5 KiB
Go
50 lines
1.5 KiB
Go
// 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
|
|
Tag string
|
|
Remote string
|
|
ExpectedCommit string
|
|
VerifyOnly bool
|
|
}
|
|
|
|
func PrepareTaggedCheckout(ctx context.Context, request TaggedCheckoutRequest) error {
|
|
lastSlash := strings.LastIndex(request.Tag, "/")
|
|
version := request.Tag[lastSlash+1:]
|
|
if !versioncontract.ValidStableVersion(version) {
|
|
return fmt.Errorf("%w: tag %q must end in a stable semantic version", candidate.ErrInvalidVersion, request.Tag)
|
|
}
|
|
if strings.TrimSpace(request.ExpectedCommit) == "" {
|
|
return errors.New("expected commit is required")
|
|
}
|
|
if request.VerifyOnly {
|
|
return git.VerifyTaggedCheckout(ctx, request.RepositoryDir, request.Tag, request.ExpectedCommit)
|
|
}
|
|
remote := request.Remote
|
|
if remote == "" {
|
|
remote = "origin"
|
|
}
|
|
return git.PrepareTaggedCheckout(ctx, request.RepositoryDir, request.Tag, remote, request.ExpectedCommit)
|
|
}
|
|
|
|
func PrepareBuildDependencies(ctx context.Context, moduleDir string) error {
|
|
if strings.TrimSpace(moduleDir) == "" {
|
|
return errors.New("module directory is required")
|
|
}
|
|
return gotool.PrepareBuildDependencies(ctx, moduleDir)
|
|
}
|