actions

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// GitHubTokenEnvVar is the environment variable for GitHub authentication.
	GitHubTokenEnvVar = "GITHUB_TOKEN" //nolint:gosec // Not a credential, just env var name
)

Variables

This section is empty.

Functions

func IsCommitHash

func IsCommitHash(ref string) bool

IsCommitHash checks if a reference is a 40-char hex commit hash.

func IsMajorVersionOnly

func IsMajorVersionOnly(ref string) bool

IsMajorVersionOnly checks if ref is only a major version (e.g., "v3" or "3").

Types

type ActionInfo

type ActionInfo struct {
	Owner string
	Repo  string
	Path  string // Subdirectory path for composite actions (e.g., "upload-sarif")
	Ref   string // Git reference: tag (e.g., "v2"), commit hash, or branch name
}

ActionInfo represents a parsed GitHub Action reference.

func ParseActionUses

func ParseActionUses(uses string) (*ActionInfo, error)

ParseActionUses parses "owner/repo@ref" or "owner/repo/path@ref" into ActionInfo. For composite actions like "github/codeql-action/upload-sarif@v2", the repo is extracted as "codeql-action" and path as "upload-sarif".

func (*ActionInfo) FormatUses

func (a *ActionInfo) FormatUses(ref string) string

FormatUses returns the action uses string with the given ref (e.g., "owner/repo@ref").

func (*ActionInfo) IsAtLatest

func (a *ActionInfo) IsAtLatest(latestTag, latestHash string) bool

IsAtLatest checks if the current ref points to the latest version. Works for hashes, tags, and major versions.

func (*ActionInfo) Name

func (a *ActionInfo) Name() string

Name returns the normalized action name (owner/repo or owner/repo/path).

func (*ActionInfo) NeedsFormatChange

func (a *ActionInfo) NeedsFormatChange(desiredFormat string) bool

NeedsFormatChange checks if the current ref format differs from the desired format.

type Cache

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

Cache stores cached results for version lookups to avoid duplicate API calls when the same action appears in multiple workflows.

func NewCache

func NewCache() *Cache

NewCache creates a new Cache instance.

func (*Cache) Clear

func (c *Cache) Clear()

Clear clears all cached version lookup results. This is useful for testing or when you want to force fresh API calls.

func (*Cache) GetConstrained

func (c *Cache) GetConstrained(key VersionKey) (VersionResult, bool)

GetConstrained retrieves a cached version result for a constrained lookup. Returns the cached result and true if found, or zero result and false if not cached.

func (*Cache) GetUnconstrained

func (c *Cache) GetUnconstrained(key VersionKey) (VersionResult, bool)

GetUnconstrained retrieves a cached version result for an unconstrained lookup. Returns the cached result and true if found, or zero result and false if not cached.

func (*Cache) SetConstrained

func (c *Cache) SetConstrained(key VersionKey, result VersionResult)

SetConstrained stores a version result in the cache for a constrained lookup.

func (*Cache) SetUnconstrained

func (c *Cache) SetUnconstrained(key VersionKey, result VersionResult)

SetUnconstrained stores a version result in the cache for an unconstrained lookup.

func (*Cache) Stats

func (c *Cache) Stats() CacheStats

Stats returns the current cache statistics.

type CacheStats

type CacheStats struct {
	Hits   int64 // Number of cache hits
	Misses int64 // Number of cache misses (API calls made)
}

CacheStats holds statistics about cache usage.

type Client

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

Client implements the Resolver interface.

func NewClient

func NewClient() *Client

NewClient creates a new Client instance with background context.

func NewClientWithCache

func NewClientWithCache(ctx context.Context, cache *Cache) *Client

NewClientWithCache creates a Client with a shared cache.

func NewClientWithContext

func NewClientWithContext(ctx context.Context) *Client

NewClientWithContext creates a new Client instance with the provided context.

func (*Client) ClearCache

func (c *Client) ClearCache()

ClearCache clears the version lookup cache.

func (*Client) GetCacheStats

func (c *Client) GetCacheStats() CacheStats

GetCacheStats returns the cache usage statistics.

func (*Client) GetCommitHash

func (c *Client) GetCommitHash(owner, repo, ref string) (string, error)

GetCommitHash resolves a Git reference to its commit hash.

func (*Client) GetLatestMinorVersion

func (c *Client) GetLatestMinorVersion(owner, repo, majorVersion string) (string, string, error)

GetLatestMinorVersion finds the latest minor version for a major version. For example, "v3" might return "v3.5.2".

func (*Client) GetLatestVersion

func (c *Client) GetLatestVersion(owner, repo, currentVersion, versionConstraint string) (string, string, error)

GetLatestVersion fetches the latest compatible tag and commit hash. Results are cached.

func (*Client) GetLatestVersionUnconstrained

func (c *Client) GetLatestVersionUnconstrained(owner, repo string) (string, string, error)

GetLatestVersionUnconstrained fetches the semantically latest version. First tries GitHub Releases API (single call), then falls back to tag pagination. Results are cached.

func (*Client) GetTagForCommit

func (c *Client) GetTagForCommit(owner, repo, commitHash string) (string, error)

GetTagForCommit finds which tag points to the given commit hash.

type MockResolver

type MockResolver struct {
	GetCommitHashFunc            func(owner, repo, ref string) (string, error)
	GetLatestVersionFunc         func(owner, repo, currentVersion, versionConstraint string) (string, string, error)
	GetLatestVersionUnconstrFunc func(owner, repo string) (string, string, error)
	GetTagForCommitFunc          func(owner, repo, commitHash string) (string, error)
	GetLatestMinorVersionFunc    func(owner, repo, majorVersion string) (string, string, error)
}

MockResolver is a mock implementation of the Resolver interface for testing.

func (*MockResolver) GetCacheStats

func (m *MockResolver) GetCacheStats() CacheStats

func (*MockResolver) GetCommitHash

func (m *MockResolver) GetCommitHash(owner, repo, ref string) (string, error)

func (*MockResolver) GetLatestMinorVersion

func (m *MockResolver) GetLatestMinorVersion(owner, repo, majorVersion string) (string, string, error)

func (*MockResolver) GetLatestVersion

func (m *MockResolver) GetLatestVersion(owner, repo, currentVersion, versionConstraint string) (string, string, error)

func (*MockResolver) GetLatestVersionUnconstrained

func (m *MockResolver) GetLatestVersionUnconstrained(owner, repo string) (string, string, error)

func (*MockResolver) GetTagForCommit

func (m *MockResolver) GetTagForCommit(owner, repo, commitHash string) (string, error)

type Resolver

type Resolver interface {
	GetCommitHash(owner, repo, ref string) (string, error)
	GetLatestVersion(owner, repo, currentVersion, versionConstraint string) (string, string, error)
	GetLatestVersionUnconstrained(owner, repo string) (string, string, error)
	GetTagForCommit(owner, repo, commitHash string) (string, error)
	GetLatestMinorVersion(owner, repo, majorVersion string) (string, string, error)
	GetCacheStats() CacheStats
}

Resolver defines the interface for GitHub Actions operations.

type VersionKey

type VersionKey struct {
	Owner      string
	Repo       string
	Ref        string // Current version reference (e.g., "v1.2.0"); empty for unconstrained
	Constraint string // Version constraint (e.g., "^1.0.0"); empty for unconstrained
}

VersionKey represents a cache key for version lookups.

func NewConstrainedKey

func NewConstrainedKey(owner, repo, ref, constraint string) VersionKey

NewConstrainedKey creates a key for constrained version lookups.

func NewUnconstrainedKey

func NewUnconstrainedKey(owner, repo string) VersionKey

NewUnconstrainedKey creates a key for unconstrained version lookups. Unconstrained lookups get the absolute latest version for a repo.

func (VersionKey) IsConstrained

func (k VersionKey) IsConstrained() bool

IsConstrained returns true if this is a constrained key.

func (VersionKey) String

func (k VersionKey) String() string

String returns the string representation of the cache key.

type VersionResult

type VersionResult struct {
	Tag  string
	Hash string
	Err  error
}

VersionResult represents a cached version lookup result.

func NewVersionResult

func NewVersionResult(tag, hash string, err error) VersionResult

NewVersionResult creates a new VersionResult.

func (VersionResult) IsError

func (r VersionResult) IsError() bool

IsError returns true if the result contains an error.

Jump to

Keyboard shortcuts

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