Files
releasekit/preparation.go

77 lines
3.0 KiB
Go
Raw Normal View History

2026-10-06 18:59:29 +00:00
package releasekit
import (
"context"
2026-10-10 03:30:34 +00:00
"errors"
"fmt"
"strings"
2026-10-06 18:59:29 +00:00
"go.maximumdirect.net/releasekit/internal/git"
internalpreparation "go.maximumdirect.net/releasekit/internal/preparation"
"go.maximumdirect.net/releasekit/internal/releaseidentity"
2026-10-06 18:59:29 +00:00
)
2026-10-10 03:40:10 +00:00
// TaggedCheckoutRequest selects a full Git tag and the Git object ID expected
// by an external build or CI event. An empty Remote selects origin.
2026-10-06 18:59:29 +00:00
type TaggedCheckoutRequest struct {
RepositoryDir string
2026-10-10 03:40:10 +00:00
Tag string
2026-10-06 18:59:29 +00:00
Remote string
ExpectedCommit string
2026-10-10 03:40:10 +00:00
// VerifyOnly checks an already prepared checkout without fetching or checking out.
VerifyOnly bool
2026-10-06 18:59:29 +00:00
}
2026-10-10 03:40:10 +00:00
// PrepareTaggedCheckout fetches Tag from Remote, verifies that its peeled
// commit matches ExpectedCommit, and checks out that commit detached. When
// VerifyOnly is true, it performs the same tag, HEAD, and cleanliness checks
// without fetching or changing the checkout. It does not publish a tag or
// hosted content.
2026-10-06 18:59:29 +00:00
func PrepareTaggedCheckout(ctx context.Context, request TaggedCheckoutRequest) error {
return internalpreparation.PrepareTaggedCheckout(ctx, internalpreparation.TaggedCheckoutRequest{
RepositoryDir: request.RepositoryDir,
2026-10-10 03:40:10 +00:00
Tag: request.Tag,
2026-10-06 18:59:29 +00:00
Remote: request.Remote,
ExpectedCommit: request.ExpectedCommit,
2026-10-10 03:40:10 +00:00
VerifyOnly: request.VerifyOnly,
2026-10-06 18:59:29 +00:00
})
}
2026-10-10 03:30:34 +00:00
// DependencyPreparationRequest selects the repository module whose dependencies
// should be prepared. Within a checkout, RepositoryDir may name any directory
// in it; ModuleDir is resolved from the checkout root. Outside a checkout,
// ModuleDir is resolved from RepositoryDir.
2026-10-10 03:30:34 +00:00
type DependencyPreparationRequest struct {
RepositoryDir string
// ModuleDir selects a directory relative to the checkout root or standalone
// RepositoryDir; empty selects that base.
2026-10-10 03:30:34 +00:00
ModuleDir string
}
// PrepareBuildDependencies runs `go mod download` in the selected module with
2026-10-06 18:59:29 +00:00
// workspace discovery disabled and the locally available compatible Go
// toolchain selected. Alternate module files selected by GOFLAGS are overridden
// for this download; other effective Go settings remain available. It may
// access module networks and updates the Go module cache using the caller's Go
// proxy, private-module, credential, and cache settings. If required checksums
// are missing, the Go command may update
2026-10-06 18:59:29 +00:00
// go.sum. Cancellation and Go command failures are returned to the caller.
2026-10-10 03:30:34 +00:00
func PrepareBuildDependencies(ctx context.Context, request DependencyPreparationRequest) error {
if strings.TrimSpace(request.RepositoryDir) == "" {
return errors.New("repository directory is required")
}
base := request.RepositoryDir
root, found, err := git.DiscoverRepositoryRoot(ctx, base)
if err != nil {
return fmt.Errorf("discover dependency preparation repository: %w", err)
}
if found {
base = root
}
selection, err := releaseidentity.ResolveSelection(base, request.ModuleDir)
2026-10-10 03:30:34 +00:00
if err != nil {
return fmt.Errorf("resolve dependency preparation module: %w", err)
}
return internalpreparation.PrepareBuildDependencies(ctx, selection.ModuleDir)
2026-10-06 18:59:29 +00:00
}