registry

package
v0.11.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: EUPL-1.2 Imports: 20 Imported by: 0

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

View Source
const (
	OpEqual          = "=="
	OpNotEqual       = "!="
	OpGreater        = ">"
	OpGreaterOrEqual = ">="
	OpLess           = "<"
	OpLessOrEqual    = "<="
	OpTilde          = "~"
	OpCaret          = "^"
)

Variables

This section is empty.

Functions

func CheckVersionConstraint

func CheckVersionConstraint(constraintStr, versionStr string) (bool, error)

CheckVersionConstraint checks if a version string satisfies a constraint string. This is the main entry point for version compatibility checking.

func Download

func Download(ctx context.Context, client httpx.HTTPDoer, url string) ([]byte, error)

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

func ExtractChecksumForAsset(content, assetName string) string

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

func ExtractTarGz(data []byte, targetDir string) error

ExtractTarGz extracts a tar.gz archive to targetDir with path traversal protection.

func NormalizeTag

func NormalizeTag(tag string) string

NormalizeTag strips a leading "v" prefix from a GitHub release tag.

func ValidateOwnerRepo

func ValidateOwnerRepo(ownerRepo string) error

ValidateOwnerRepo validates that the input is a valid GitHub repository reference in owner/repo format.

func VerifyChecksum

func VerifyChecksum(data []byte, checksum string) error

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).

func FindPlatformAsset

func FindPlatformAsset(assets []Asset, goos, goarch string) (Asset, error)

FindPlatformAsset finds the .tar.gz asset matching goos/goarch from a release's asset list.

type Constraint

type Constraint struct {
	Operator string
	Version  Version
}

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.

func (*GitHubAPIDoer) Do

func (d *GitHubAPIDoer) Do(req *http.Request) (*http.Response, error)

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

type Version struct {
	Major      int
	Minor      int
	Patch      int
	Prerelease string
}

Version represents a parsed semantic version.

func ParseVersion

func ParseVersion(s string) (Version, error)

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

func (v Version) Compare(other Version) int

Compare compares this version to another. Returns -1 if v < other, 0 if v == other, 1 if v > other.

func (Version) IsPrerelease

func (v Version) IsPrerelease() bool

func (Version) String

func (v Version) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL