ghworkflow

package
v5.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package ghworkflow is Scorecard's model of a GitHub Actions workflow file.

Checks and probes consume only the types in this package. The YAML parsing itself is delegated to an external parser, which is confined to convert.go so it can be replaced without touching any consumer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(content []byte) (*Workflow, []*Error)

Parse parses the content of a workflow file.

A non-empty error list does not mean parsing failed: the workflow is returned whenever the file could be parsed at all, even if some parts of it are invalid. Callers should treat a nil workflow as a parse failure.

Types

type Defaults

type Defaults struct {
	Run *DefaultsRun
}

Defaults is a `defaults:` section.

type DefaultsRun

type DefaultsRun struct {
	Shell *String
}

DefaultsRun is the `defaults.run:` section.

type Env

type Env struct {
	Vars map[string]*EnvVar
}

Env is an `env:` section. Vars is keyed by the variable's name.

type EnvVar

type EnvVar struct {
	Name  *String
	Value *String
}

EnvVar is a single environment variable assignment.

type Error

type Error struct {
	Message  string
	Filepath string
	Kind     string
	Line     int
	Column   int
}

Error is a problem found while parsing a workflow. Line and Column are 1-based.

func (*Error) Error

func (e *Error) Error() string

type Event

type Event struct {
	Name string
}

Event is one trigger listed under `on:`.

func (*Event) EventName

func (e *Event) EventName() string

EventName returns the trigger's name, e.g. "pull_request_target".

type Exec

type Exec interface {
	Kind() ExecKind
}

Exec is what a step executes: either an *ExecAction or an *ExecRun.

type ExecAction

type ExecAction struct {
	Uses   *String
	Inputs map[string]*Input
}

ExecAction is a step that runs an action. Inputs holds its `with:` values, keyed by input name.

func (*ExecAction) Kind

func (e *ExecAction) Kind() ExecKind

Kind returns ExecKindAction.

type ExecKind

type ExecKind uint8

ExecKind says whether a step runs an action or a shell script.

const (
	// ExecKindAction is a step with `uses:`.
	ExecKindAction ExecKind = iota
	// ExecKindRun is a step with `run:`.
	ExecKindRun
)

type ExecRun

type ExecRun struct {
	Run   *String
	Shell *String
}

ExecRun is a step that runs a shell script.

func (*ExecRun) Kind

func (e *ExecRun) Kind() ExecKind

Kind returns ExecKindRun.

type Input

type Input struct {
	Name  *String
	Value *String
}

Input is a single `with:` entry of an action step.

type Job

type Job struct {
	ID           *String
	Name         *String
	RunsOn       *Runner
	Permissions  *Permissions
	Env          *Env
	Defaults     *Defaults
	Strategy     *Strategy
	WorkflowCall *WorkflowCall
	Pos          *Pos
	Steps        []*Step
}

Job is a single entry under `jobs:`.

type Matrix

type Matrix struct {
	Rows    map[string]*MatrixRow
	Include *MatrixCombinations
}

Matrix is a job's `strategy.matrix:` section.

type MatrixAssign

type MatrixAssign struct {
	Key   *String
	Value string
}

MatrixAssign is a single `key: value` pair in a matrix combination. Value follows the same rendering rules as MatrixRow.Values.

type MatrixCombination

type MatrixCombination struct {
	Assigns map[string]*MatrixAssign
}

MatrixCombination is one entry of a matrix `include:` list. Assigns is keyed by the assigned key's name.

type MatrixCombinations

type MatrixCombinations struct {
	Combinations []*MatrixCombination
}

MatrixCombinations is a matrix `include:` list.

type MatrixRow

type MatrixRow struct {
	Name   *String
	Values []string
}

MatrixRow is one matrix dimension, such as `os: [ubuntu-latest, windows-latest]`. String values are stored unquoted; arrays and objects are stored in a flow-style rendering.

type PermissionScope

type PermissionScope struct {
	Name  *String
	Value *String
}

PermissionScope is a single `<scope>: <level>` entry in a permissions mapping.

type Permissions

type Permissions struct {
	All    *String
	Scopes map[string]*PermissionScope
	Pos    *Pos
}

Permissions is a `permissions:` section. All is set when the section is a single string such as "read-all"; Scopes is set when it is a mapping.

type Pos

type Pos struct {
	Line int
	Col  int
}

Pos is a 1-based position in the workflow file.

type Runner

type Runner struct {
	LabelsExpr *String
	Labels     []*String
}

Runner is a job's `runs-on:` value. When it is a single `${{ }}` expression, LabelsExpr is set instead of Labels.

type Step

type Step struct {
	ID   *String
	If   *String
	Name *String
	Exec Exec
	Pos  *Pos
}

Step is a single entry under a job's `steps:`.

type Strategy

type Strategy struct {
	Matrix *Matrix
}

Strategy is a job's `strategy:` section.

type String

type String struct {
	Pos   *Pos
	Value string
}

String is a scalar value along with where it appears in the file.

type Workflow

type Workflow struct {
	Permissions *Permissions
	Env         *Env
	Jobs        map[string]*Job
	On          []*Event
}

Workflow is a parsed workflow file. Fields are nil when the corresponding section is absent.

type WorkflowCall

type WorkflowCall struct {
	Uses *String
}

WorkflowCall is a job that calls a reusable workflow with `uses:`.

Jump to

Keyboard shortcuts

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