Documentation
¶
Overview ¶
Package registry provides transport-layer primitives for downloading, verifying, and extracting artifacts from GitHub Releases. It is consumed by both the plugin system and the workflow pack system.
Index ¶
- Constants
- func CheckVersionConstraint(constraintStr, versionStr string) (bool, error)
- func Download(ctx context.Context, client httpx.HTTPDoer, url string) ([]byte, error)
- func ExtractChecksumForAsset(content, assetName string) string
- func ExtractTarGz(data []byte, targetDir string) error
- func NormalizeTag(tag string) string
- func ValidateOwnerRepo(ownerRepo string) error
- func VerifyChecksum(data []byte, checksum string) error
- type Asset
- type Constraint
- type Constraints
- type GitHubAPIDoer
- type GitHubReleaseClient
- type Release
- type Version
Constants ¶
const ( OpEqual = "==" OpNotEqual = "!=" OpGreater = ">" OpGreaterOrEqual = ">=" OpLess = "<" OpLessOrEqual = "<=" OpTilde = "~" OpCaret = "^" )
Variables ¶
This section is empty.
Functions ¶
func CheckVersionConstraint ¶
CheckVersionConstraint checks if a version string satisfies a constraint string. This is the main entry point for version compatibility checking.
func Download ¶
Download downloads a file from a URL using the provided HTTP client. The caller is responsible for verifying the returned content with VerifyChecksum. Returns downloaded bytes, limited to 100MB.
func ExtractChecksumForAsset ¶
ExtractChecksumForAsset parses a checksum file and returns the SHA-256 hex string for the given assetName. The checksum file format is:
<hex> <filename>
Each line contains a checksum followed by two spaces and the filename. Returns empty string if the asset is not found.
func ExtractTarGz ¶
ExtractTarGz extracts a tar.gz archive to targetDir with path traversal protection.
func NormalizeTag ¶
NormalizeTag strips a leading "v" prefix from a GitHub release tag.
func ValidateOwnerRepo ¶
ValidateOwnerRepo validates that the input is a valid GitHub repository reference in owner/repo format.
func VerifyChecksum ¶
VerifyChecksum verifies that data matches the expected SHA-256 checksum (hex string).
Types ¶
type Asset ¶
type Asset struct {
Name string `json:"name"`
DownloadURL string `json:"browser_download_url"`
Size int `json:"size"`
}
Asset represents a release asset (binary, archive, etc).
type Constraint ¶
Constraint represents a single version constraint (e.g., ">=0.4.0").
func ParseConstraint ¶
func ParseConstraint(s string) (Constraint, error)
ParseConstraint parses a constraint string into a Constraint struct. Accepts formats: ">=0.4.0", "~1.2.0", "^2.0.0", "1.0.0" (implies ==)
func (Constraint) Check ¶
func (c Constraint) Check(v Version) bool
type Constraints ¶
type Constraints []Constraint
Constraints represents multiple version constraints that all must be satisfied.
func ParseConstraints ¶
func ParseConstraints(s string) (Constraints, error)
ParseConstraints parses a constraint string that may contain multiple constraints. Constraints are separated by spaces or commas. Examples: ">=0.4.0 <1.0.0", ">=0.4.0, <1.0.0"
func (Constraints) Check ¶
func (cs Constraints) Check(v Version) bool
Check tests if a version satisfies all constraints.
func (Constraints) String ¶
func (cs Constraints) String() string
String returns the string representation of the constraints.
type GitHubAPIDoer ¶
type GitHubAPIDoer struct {
// contains filtered or unexported fields
}
GitHubAPIDoer wraps an HTTP client to redirect api.github.com requests to a custom base URL. This enables test isolation via GITHUB_API_URL without modifying GitHubReleaseClient.
func NewGitHubAPIDoer ¶
func NewGitHubAPIDoer(apiBase string, inner httpx.HTTPDoer) *GitHubAPIDoer
NewGitHubAPIDoer creates a doer that redirects https://api.github.com requests to apiBase when apiBase is non-empty. Falls back to standard http.Client behavior.
type GitHubReleaseClient ¶
type GitHubReleaseClient struct {
// contains filtered or unexported fields
}
GitHubReleaseClient fetches and resolves releases from GitHub.
func NewGitHubReleaseClient ¶
func NewGitHubReleaseClient(doer httpx.HTTPDoer) *GitHubReleaseClient
NewGitHubReleaseClient creates a new GitHub release client. If doer is nil, uses http.DefaultClient.
func (*GitHubReleaseClient) ListReleases ¶
func (c *GitHubReleaseClient) ListReleases(ctx context.Context, ownerRepo string) ([]Release, error)
ListReleases fetches all releases for an owner/repo from GitHub API.
func (*GitHubReleaseClient) ResolveVersion ¶
func (c *GitHubReleaseClient) ResolveVersion(ctx context.Context, ownerRepo, constraintStr string, includePrerelease bool) (Version, error)
ResolveVersion resolves the best matching version from available releases.
type Release ¶
type Release struct {
TagName string `json:"tag_name"`
Prerelease bool `json:"prerelease"`
URL string `json:"url"`
Assets []Asset `json:"assets"`
}
Release represents a GitHub release.
type Version ¶
Version represents a parsed semantic version.
func ParseVersion ¶
ParseVersion parses a version string into a Version struct. Accepts formats: "1.0.0", "1.0.0-alpha.1", "v1.0.0", "v1.0.0-alpha.1"
func (Version) Compare ¶
Compare compares this version to another. Returns -1 if v < other, 0 if v == other, 1 if v > other.