cli

package
v0.0.0-...-2b1ef52 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Overview

Package cli provides a unified command-line interface for the runtime download system. It supports YAML configuration files and integrates with all runtime providers.

Package cli provides command-line interface components with testable abstractions.

Package cli provides the command-line interface for the runtime download system.

Package cli provides release functionality integrated with the download command.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrResolvePackagingTargetsNilConfig = errors.New("config is required")
	ErrResolvePackagingTargetsNilDB     = errors.New("database is required")
	ErrResolvePackagingTargetsNilRunID  = errors.New("run_id is required")
)

Functions

func BuildPromotionUploader

func BuildPromotionUploader(configPath, token string, manifest PackageManifest) (promotion.ReleaseAssetUploader, error)

func NewApp

func NewApp() *cli.App

NewApp creates and configures the main CLI application.

func NewAuditLogger

func NewAuditLogger() (*slog.Logger, func(), error)

NewAuditLogger creates a dedicated logger for verification audit trails. Returns the logger, cleanup function, and error. NOTE: Audit logging configuration was removed, this function is deprecated

func NewLoggers

func NewLoggers(level slog.Level) (*slog.Logger, *slog.Logger)

NewLoggers creates default loggers with JSON output.

func NewLoggersWithOutputFormat

func NewLoggersWithOutputFormat(level slog.Level, outputFormat string) (*slog.Logger, *slog.Logger)

NewLoggersWithOutputFormat creates loggers with awareness of output format. All logs are sent to stderr to keep stdout clean for JSON output. The outputFormat parameter is kept for backward compatibility but all output will be JSON formatted.

func ParseLogLevelOrDefault

func ParseLogLevelOrDefault(levelStr string) slog.Level

ParseLogLevelOrDefault parses a log level string or returns a default level.

func PromoteTestedPackagesFromFiles

func PromoteTestedPackagesFromFiles(
	db promotion.Store,
	manifestPath string,
	testResultsPath string,
) (promotion.Summary, error)

PromoteTestedPackagesFromFiles promotes tested package entries from files.

It reads a manifest + test-result file, validates all entries up front, then updates release artifacts and package records only if all entries are eligible.

func PromoteTestedPackagesFromFilesWithUploader

func PromoteTestedPackagesFromFilesWithUploader(
	db promotion.Store,
	manifestPath string,
	testResultsPath string,
	uploader promotion.ReleaseAssetUploader,
) (promotion.Summary, error)

PromoteTestedPackagesFromFilesWithUploader promotes tested package entries and optionally uploads package assets to releases when URLs are missing.

func ReadPackageTestResultsFile

func ReadPackageTestResultsFile(path string) (promotion.TestResultsFile, error)

ReadPackageTestResultsFile reads package test results JSON from disk.

func UploadPromotionEvidenceFiles

func UploadPromotionEvidenceFiles(
	uploader promotion.ReleaseAssetUploader,
	releaseTagsByRuntime map[string]string,
	testResultsPath string,
) error

func WritePackageManifest

func WritePackageManifest(path string, manifest PackageManifest) error

WritePackageManifest writes a manifest as formatted JSON and ensures parent directories exist for predictable CI/local behavior.

Types

type DatabaseStore

type DatabaseStore interface {
	// CreateRelease inserts a new release record into the database.
	CreateRelease(release *storage.Release) error

	// GetRelease retrieves a release by runtime name and version.
	GetRelease(runtime, version string) (*storage.Release, error)

	// ListByVersion returns all downloads for a specific runtime and version.
	ListByVersion(runtime, version string) ([]*storage.Download, error)

	// Close closes the database connection.
	Close() error
}

DatabaseStore abstracts database operations for testing.

type DownloadResult

type DownloadResult struct {
	Runtime    string `json:"runtime"`
	Version    string `json:"version"`
	Platform   string `json:"platform"`
	URL        string `json:"url"`
	LocalPath  string `json:"local_path"`
	FileSize   int64  `json:"file_size"`
	Success    bool   `json:"success"`
	Error      string `json:"error,omitempty"`
	DurationMs int64  `json:"duration_ms"`
}

DownloadResult represents a download operation result for JSON output

type DownloadSummary

type DownloadSummary struct {
	Runtime    string           `json:"runtime"`
	Version    string           `json:"version"`
	TotalFiles int              `json:"total_files"`
	Successful int              `json:"successful"`
	Failed     int              `json:"failed"`
	OutputDir  string           `json:"output_dir"`
	Results    []DownloadResult `json:"results"`
}

DownloadSummary represents the summary of download operations for JSON output

type GitHubReleaser

type GitHubReleaser interface {
	// CreateRelease creates a new GitHub release with the given parameters.
	CreateRelease(tag, name, body string, draft bool) (*github.RepositoryRelease, error)

	// UploadAsset uploads a file to an existing GitHub release.
	UploadAsset(releaseID int64, filePath string) (*github.ReleaseAsset, error)

	// GetAssetDownloadURL returns the public download URL for a release asset.
	GetAssetDownloadURL(asset *github.ReleaseAsset) string

	// GetReleaseURL returns the HTML URL for a GitHub release.
	GetReleaseURL(release *github.RepositoryRelease) string
}

GitHubReleaser abstracts GitHub release operations for testing. Following Dave Cheney's principle: "Accept interfaces, return structs"

type LoggerConfig

type LoggerConfig struct {
	Level slog.Level
}

LoggerConfig contains configuration for setting up loggers.

type PackageManifest

type PackageManifest struct {
	RunID       string                 `json:"run_id"`
	Stage       string                 `json:"stage"`
	GeneratedAt time.Time              `json:"generated_at"`
	Targets     []PackageManifestEntry `json:"targets"`
	Skipped     []PackagingResolveSkip `json:"skipped"`
}

PackageManifest captures package orchestration state for a run. In Phase 1 this is emitted at the "resolved" stage and becomes the handoff contract for subsequent build/test/promotion phases.

func NewResolvedPackageManifest

func NewResolvedPackageManifest(runID string, result PackagingResolveResult) PackageManifest

NewResolvedPackageManifest converts resolver output into a stage-scoped manifest.

func ReadPackageManifest

func ReadPackageManifest(path string) (PackageManifest, error)

ReadPackageManifest reads a package manifest JSON from disk.

type PackageManifestEntry

type PackageManifestEntry struct {
	Runtime       string                `json:"runtime"`
	Version       string                `json:"version"`
	Target        string                `json:"target"`
	InputMode     string                `json:"input_mode"`
	InputPlatform string                `json:"input_platform"`
	InputArch     string                `json:"input_arch"`
	InputPath     string                `json:"input_path"`
	InputSHA256   string                `json:"input_sha256"`
	InputRunID    string                `json:"input_run_id,omitempty"`
	PackageName   string                `json:"package_name"`
	InstallPrefix string                `json:"install_prefix"`
	Status        PackageManifestStatus `json:"status"`
}

PackageManifestEntry represents one packaging unit of work for a runtime/version/target. Status fields are placeholders for upcoming phases.

type PackageManifestStatus

type PackageManifestStatus struct {
	Resolved bool `json:"resolved"`
	Built    bool `json:"built"`
	Tested   bool `json:"tested"`
	Promoted bool `json:"promoted"`
}

PackageManifestStatus tracks state transitions for one target.

type PackagingResolveOptions

type PackagingResolveOptions struct {
	// RunID limits results to downloads from a specific run.
	RunID string
}

type PackagingResolveResult

type PackagingResolveResult struct {
	Targets []PackagingResolveTarget `json:"targets"`
	Skipped []PackagingResolveSkip   `json:"skipped"`
}

func ResolvePackagingTargets

func ResolvePackagingTargets(cfg *config.Config, db packagingDownloadsStore, opts PackagingResolveOptions) (PackagingResolveResult, error)

ResolvePackagingTargets converts current-run download records into package build targets.

Bigger picture: - Download stage writes verified artifacts into downloads.db with a run_id. - Resolver stage reads only that run_id and prepares package work items. - Build/test/promotion stages consume these targets without re-discovering inputs.

type PackagingResolveSkip

type PackagingResolveSkip struct {
	Runtime string                     `json:"runtime"`
	Reason  PackagingResolveSkipReason `json:"reason"`
	Detail  string                     `json:"detail,omitempty"`
}

type PackagingResolveSkipReason

type PackagingResolveSkipReason string
const (
	ResolveSkipPackagingDisabled PackagingResolveSkipReason = "packaging_disabled"
	ResolveSkipTargetNotEnabled  PackagingResolveSkipReason = "target_not_enabled"
	ResolveSkipNoVerifiedInput   PackagingResolveSkipReason = "no_verified_download"
)

type PackagingResolveTarget

type PackagingResolveTarget struct {
	Runtime       string                `json:"runtime"`
	Version       string                `json:"version"`
	Target        packaging.PackageType `json:"target"`
	InputMode     packaging.InputMode   `json:"input_mode"`
	InputPlatform string                `json:"input_platform"`
	InputArch     string                `json:"input_arch"`
	InputPath     string                `json:"input_path"`
	InputSHA256   string                `json:"input_sha256"`
	InputRunID    string                `json:"input_run_id,omitempty"`
	PackageName   string                `json:"package_name"`
	InstallPrefix string                `json:"install_prefix"`
}

type ReleaseManager

type ReleaseManager struct {
	// contains filtered or unexported fields
}

ReleaseManager handles the GitHub release process after successful downloads. It accepts interfaces for testability (Dave Cheney's "accept interfaces, return structs").

func NewReleaseManager

func NewReleaseManager(cfg *config.ReleaseConfig, github GitHubReleaser, db DatabaseStore, stdout, stderr *slog.Logger) (*ReleaseManager, error)

NewReleaseManager creates a new release manager with the provided dependencies. Returns nil if auto_release is disabled in the configuration. GitHub client and database are passed as interfaces for testability.

func (*ReleaseManager) CreateAggregatedRelease

func (rm *ReleaseManager) CreateAggregatedRelease(
	runtimeName string,
	versions []string,
	downloadResults []runtime.DownloadResult,
	outputDir string,
	releaseConfig *config.ReleaseConfig,
) (*storage.Release, error)

CreateAggregatedRelease creates a single GitHub release with artifacts from multiple versions. This is called after successful downloads for multiple runtime versions.

type RuntimeManager

type RuntimeManager interface {
	// GetProvider returns the runtime provider for the given runtime name.
	GetProvider(name string) (runtime.RuntimeProvider, error)

	// DownloadRuntime downloads runtime binaries for the specified platforms.
	DownloadRuntime(
		ctx context.Context,
		runtimeName string,
		version endoflife.VersionInfo,
		platforms []platform.Platform,
		outputDir string,
		concurrency int,
	) ([]runtime.DownloadResult, error)
}

RuntimeManager abstracts runtime download operations for testing. This interface mirrors the key methods from runtime.Manager that the CLI needs.

Jump to

Keyboard shortcuts

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