cicontext

package
v1.0.0-alpha.21 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cicontext reads what the CI system says about a run.

Everything here is a claim. The CI environment is writable by whatever ran earlier in the job, so a row that carries these values stays unverified and unattributed until a server has checked them against the job's OIDC token.

Index

Constants

View Source
const ResourceAttributesVariable = "OTEL_RESOURCE_ATTRIBUTES"

ResourceAttributesVariable is the variable OpenTelemetry SDKs read.

Variables

View Source
var ErrNoEventFile = errors.New("GITHUB_EVENT_PATH is not set")

ErrNoEventFile is why a run on GitHub Actions has no event to read.

Functions

This section is empty.

Types

type Context

type Context struct {
	// Repository is host and path in lower case, the form of costroid/repo.
	Repository string
	// RepositoryURL is the repository's address, for vcs.repository.url.full.
	RepositoryURL string
	PullRequest   string
	Head          string
	Base          string
	Run           string
	Task          string
	// Visibility is who can read the repository, as the CI system states it:
	// one of focus.VisibilityPublic, focus.VisibilityPrivate and
	// focus.VisibilityInternal, or empty when the system did not state it.
	Visibility string
}

Context is one CI run's stated facts. A zero Context means no CI system was found, and adds nothing to a row or to the agent's environment.

func Read

func Read(getenv func(string) string) (Context, error)

Read reads the run from the CI system's variables. An error means the system was found and its event could not be read: the Context still holds what the variables said, without a head that might name a merge commit.

func (Context) ResourceAttributes

func (c Context) ResourceAttributes(existing string) string

ResourceAttributes merges the run's vcs.* and cicd.* attributes into the value of OTEL_RESOURCE_ATTRIBUTES the job already set, and returns the result. Costroid's value replaces one the job set under the same key. Empty means there is nothing to set.

func (Context) Tags

func (c Context) Tags() map[string]string

Tags returns the join keys a row states.

type Event

type Event struct {
	// Issue is set on issue_comment. Its pull_request field is set when the
	// issue is a pull request.
	Issue *struct {
		Number      int       `json:"number"`
		PullRequest *struct{} `json:"pull_request"`
	} `json:"issue"`
	PullRequest *struct {
		Number int `json:"number"`
		Head   struct {
			SHA string `json:"sha"`
		} `json:"head"`
		Base struct {
			SHA string `json:"sha"`
		} `json:"base"`
	} `json:"pull_request"`
	// Repository is the repository the workflow runs in. It is read only for
	// its visibility, and a field of a shape Costroid does not expect states
	// none rather than making the rest of the event unreadable.
	Repository json.RawMessage `json:"repository"`
}

Event is the part of a GitHub event file Costroid reads.

func ReadEvent

func ReadEvent(path string) (Event, error)

ReadEvent reads the event file at path. On a pull request GITHUB_SHA names the test merge commit, so this file is the only place the head appears.

type System

type System int

System names a CI system.

const (
	NoSystem System = iota
	GitHubActions
	GitLabCI
)

The zero value means no system was found.

func Detect

func Detect(getenv func(string) string) System

Detect finds the CI system from its own variables.

Jump to

Keyboard shortcuts

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