Documentation
¶
Overview ¶
Package ghactx collects the CI identity of a GitHub Actions run.
In a runner the git checkout is a detached HEAD, so the local repository is not a usable source of branch or repo identity. The environment is, and the webhook payload GitHub writes to GITHUB_EVENT_PATH is richer still: it carries the repository's id, visibility, default branch and licence, and for a pull_request event the PR number and both refs — all without a network call.
Index ¶
Constants ¶
const Provider = "github-actions"
Provider identifies the CI system in the collected context.
Variables ¶
This section is empty.
Functions ¶
func Collect ¶
func Collect(ctx context.Context, opt Options) *vdb.CliCIContext
Collect builds the CI context, cheapest source first.
Tier 0 environment variables free Tier 1 GITHUB_EVENT_PATH free, on disk, and the richest source Tier 2 GitHub REST one call each, only for what is still missing
Returns nil outside a GitHub Actions runner.
Types ¶
type CollectorLookup ¶
type CollectorLookup struct {
Collector *github.ArtifactCollector
}
CollectorLookup adapts *github.ArtifactCollector to RESTLookup. It lives here rather than in the github package so ghactx owns the shape it needs and the artifact downloader stays unaware of CI context.
func (CollectorLookup) GetRepository ¶
func (l CollectorLookup) GetRepository(ctx context.Context) (*RepoInfo, error)
GetRepository implements RESTLookup.
func (CollectorLookup) GetWorkflowRun ¶
func (l CollectorLookup) GetWorkflowRun(ctx context.Context) (*RunInfo, error)
GetWorkflowRun implements RESTLookup.
func (CollectorLookup) ListPullsForCommit ¶
ListPullsForCommit implements RESTLookup.
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event is the webhook payload GitHub wrote to disk for this run, held as a generic tree because its shape depends on the event type and only a handful of paths are ever read.
func EventFromJSON ¶
EventFromJSON parses a payload from bytes. Used by tests and by --from-dir runs replaying a captured event.
func LoadEvent ¶
func LoadEvent() *Event
LoadEvent reads GITHUB_EVENT_PATH. Returns nil when the variable is unset or the file is unreadable — every accessor tolerates a nil receiver, so callers need no branch for it.
type Options ¶
type Options struct {
// NoAPI suppresses every network lookup. Environment variables and the
// event payload on disk are still read.
NoAPI bool
// Lookup performs the REST fallbacks. Nil disables them, same as NoAPI.
Lookup RESTLookup
// Warn receives a note whenever an optional lookup failed, so a degraded
// context is visible in the workflow log rather than silently thinner.
Warn func(format string, args ...any)
}
Options controls how much effort collection puts in.
type RESTLookup ¶
type RESTLookup interface {
GetWorkflowRun(ctx context.Context) (*RunInfo, error)
GetRepository(ctx context.Context) (*RepoInfo, error)
ListPullsForCommit(ctx context.Context, sha string) ([]PullInfo, error)
}
RESTLookup is the subset of the GitHub artifact collector this package uses to fill gaps. Declared as an interface so the collector stays testable and so this package does not depend on the artifact download machinery.
type RunInfo ¶
type RunInfo struct {
RunNumber int
RunAttempt int
Event string
HeadBranch string
HeadSHA string
HTMLURL string
Name string
Actor string
TriggeringActor string
PullRequest int
}
RunInfo, RepoInfo and PullInfo mirror the REST shapes without importing them, so a caller can adapt any client.