Documentation
¶
Index ¶
- Variables
- func EvaluateWorkflowCallOutputs(callerWorkflow *SingleWorkflow, gitCtx *model.GithubContext, ...) map[string]string
- func EvaluateWorkflowCallSecrets(args *EvaluateWorkflowCallSecretsArgs) map[string]string
- func EvaluateWorkflowConcurrency(rc *model.RawConcurrency, gitCtx *model.GithubContext, vars map[string]string, ...) (string, *bool, error)
- type ContainerSpec
- type Defaults
- type EvaluateWorkflowCallSecretsArgs
- type Event
- type ExpressionEvaluator
- type ExternalWorkflowFetcher
- type IncompleteMatrix
- type IncompleteNeeds
- type InstanceWorkflowFetcher
- type Job
- type JobResult
- type LocalWorkflowFetcher
- type ParseOption
- func ExpandExternalReusableWorkflows(externalWorkflowFetcher ExternalWorkflowFetcher) ParseOption
- func ExpandInstanceReusableWorkflows(instanceWorkflowFetcher InstanceWorkflowFetcher) ParseOption
- func ExpandLocalReusableWorkflows(localWorkflowFetcher LocalWorkflowFetcher) ParseOption
- func SupportIncompleteRunsOn() ParseOption
- func WithGitContext(context *model.GithubContext) ParseOption
- func WithInputs(inputs map[string]any) ParseOption
- func WithJobOutputs(outputs map[string]map[string]string) ParseOption
- func WithJobResults(results map[string]string) ParseOption
- func WithVars(vars map[string]string) ParseOption
- func WithWorkflowNeeds(needs []string) ParseOption
- type RunDefaults
- type SingleWorkflow
- type SingleWorkflowMetadata
- type Step
- type Strategy
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupportedReusableWorkflowFetch = errors.New("unable to support reusable workflow fetch")
Functions ¶
func EvaluateWorkflowCallOutputs ¶ added in v12.2.0
func EvaluateWorkflowCallOutputs(callerWorkflow *SingleWorkflow, gitCtx *model.GithubContext, vars map[string]string, needs []string, jobResults map[string]string, jobOutputs map[string]map[string]string) map[string]string
Outputs from a reusable workflow are translated into outputs on the caller job, which is transformed into a placeholder job that is never really executed. Because it isn't executed, special handling for evaluating its outputs is required, which `EvaluateWorkflowCallOutputs` provides.
func EvaluateWorkflowCallSecrets ¶ added in v12.3.0
func EvaluateWorkflowCallSecrets(args *EvaluateWorkflowCallSecretsArgs) map[string]string
`jobs.<job_id>.secrets` may be a map of evaluatable expressions that will be put into the `secrets` context when a reusable workflow is executed. When using workflow expansion, Forgejo is responsible for scheduling reusable workflow jobs and needs to be able to evaluate the secrets that will be passed into the reusable workflows' jobs; `EvaluateWorkflowCallSecrets` provides that capability.
func EvaluateWorkflowConcurrency ¶
func EvaluateWorkflowConcurrency(rc *model.RawConcurrency, gitCtx *model.GithubContext, vars map[string]string, inputs map[string]any) (string, *bool, error)
Convert the raw YAML from the `concurrency` block on a workflow into the evaluated concurrency group and cancel-in-progress value. This implementation only supports workflow-level concurrency definition, where we expect expressions to be able to access only the github, inputs and vars contexts. If RawConcurrency is empty, then the returned concurrency group will be "" and cancel-in-progress will be nil -- this can be used to distinguish from an explicit cancel-in-progress choice even if a group isn't specified.
Types ¶
type ContainerSpec ¶
type ContainerSpec struct {
Image string `yaml:"image,omitempty"`
Env map[string]string `yaml:"env,omitempty"`
Ports []string `yaml:"ports,omitempty"`
Volumes []string `yaml:"volumes,omitempty"`
Options string `yaml:"options,omitempty"`
Credentials map[string]string `yaml:"credentials,omitempty"`
Cmd []string `yaml:"cmd,omitempty"`
}
type Defaults ¶
type Defaults struct {
Run RunDefaults `yaml:"run,omitempty"`
}
type EvaluateWorkflowCallSecretsArgs ¶ added in v12.3.0
type Event ¶
type Event struct {
Name string
// contains filtered or unexported fields
}
func (*Event) IsSchedule ¶
type ExpressionEvaluator ¶
type ExpressionEvaluator struct {
// contains filtered or unexported fields
}
ExpressionEvaluator is copied from runner.expressionEvaluator, to avoid unnecessary dependencies
func (ExpressionEvaluator) EvaluateYamlNode ¶
func (ee ExpressionEvaluator) EvaluateYamlNode(node *yaml.Node) error
func (ExpressionEvaluator) Interpolate ¶
func (ee ExpressionEvaluator) Interpolate(in string) string
type ExternalWorkflowFetcher ¶ added in v12.3.1
type ExternalWorkflowFetcher func(job *Job, ref *model.ExternalReusableWorkflowReference) ([]byte, error)
type IncompleteMatrix ¶ added in v12.1.1
type IncompleteMatrix struct {
Dimension string `yaml:"dimension,omitempty"` // if ${{ matrix.some-dimension }} was incomplete, this will contain "some-dimension"
}
type IncompleteNeeds ¶ added in v12.1.1
type InstanceWorkflowFetcher ¶ added in v12.3.1
type InstanceWorkflowFetcher func(job *Job, ref *model.NonLocalReusableWorkflowReference) ([]byte, error)
type Job ¶
type Job struct {
Name string `yaml:"name,omitempty"`
RawNeeds yaml.Node `yaml:"needs,omitempty"`
RawRunsOn yaml.Node `yaml:"runs-on,omitempty"`
Env yaml.Node `yaml:"env,omitempty"`
If yaml.Node `yaml:"if,omitempty"`
Steps []*Step `yaml:"steps,omitempty"`
TimeoutMinutes string `yaml:"timeout-minutes,omitempty"`
Services map[string]*ContainerSpec `yaml:"services,omitempty"`
Strategy Strategy `yaml:"strategy,omitempty"`
RawContainer yaml.Node `yaml:"container,omitempty"`
Defaults Defaults `yaml:"defaults,omitempty"`
Outputs map[string]string `yaml:"outputs,omitempty"`
Uses string `yaml:"uses,omitempty"`
With map[string]any `yaml:"with,omitempty"`
RawSecrets yaml.Node `yaml:"secrets,omitempty"`
RawConcurrency *model.RawConcurrency `yaml:"concurrency,omitempty"`
}
func (*Job) EraseNeeds ¶
func (*Job) InheritSecrets ¶ added in v12.3.0
type LocalWorkflowFetcher ¶ added in v12.3.0
type ParseOption ¶
type ParseOption func(c *parseContext)
func ExpandExternalReusableWorkflows ¶ added in v12.3.1
func ExpandExternalReusableWorkflows(externalWorkflowFetcher ExternalWorkflowFetcher) ParseOption
Allows the job parser to read a workflow job that references an external reusable workflow with a fully-qualified URL (eg. `uses: https://example.com/some-org/some-repo/.forgejo/workflows/reusable.yml`). The workflow is converted into one-or-more jobs contained within the external workflow file.
The `externalWorkflowFetcher` can return the error ErrUnsupportedReusableWorkflowFetch if the fetcher doesn't support the target workflow for job parsing. The job will go to the "fallback" mode of operation where its internal jobs are not expanded into the parsed workflow, and it can still be executed as a single monolithic job. All other errors are considered fatal for job parsing.
func ExpandInstanceReusableWorkflows ¶ added in v12.3.1
func ExpandInstanceReusableWorkflows(instanceWorkflowFetcher InstanceWorkflowFetcher) ParseOption
Allows the job parser to read a workflow job that references a reusable workflow on the same Forgejo instance, but not in the same repository (eg. `uses: some-org/some-repo/.forgejo/workflows/reusable.yml`). The workflow is converted into one-or-more jobs contained within the workflow.
The `instanceWorkflowFetcher` can return the error ErrUnsupportedReusableWorkflowFetch if the fetcher doesn't support the target workflow for job parsing. The job will go to the "fallback" mode of operation where its internal jobs are not expanded into the parsed workflow, and it can still be executed as a single monolithic job. All other errors are considered fatal for job parsing.
func ExpandLocalReusableWorkflows ¶ added in v12.2.0
func ExpandLocalReusableWorkflows(localWorkflowFetcher LocalWorkflowFetcher) ParseOption
Allows the job parser to convert a workflow job that references a local reusable workflow (eg. `uses: ./.forgejo/workflows/reusable.yml`) into one-or-more jobs contained within the local workflow. The `localWorkflowFetcher` function allows jobparser to read the target workflow file.
The `localWorkflowFetcher` can return the error ErrUnsupportedReusableWorkflowFetch if the fetcher doesn't support the target workflow for job parsing. The job will go to the "fallback" mode of operation where its internal jobs are not expanded into the parsed workflow, and it can still be executed as a single monolithic job. All other errors are considered fatal for job parsing.
func SupportIncompleteRunsOn ¶ added in v12.1.1
func SupportIncompleteRunsOn() ParseOption
func WithGitContext ¶
func WithGitContext(context *model.GithubContext) ParseOption
func WithInputs ¶
func WithInputs(inputs map[string]any) ParseOption
func WithJobOutputs ¶ added in v12.1.0
func WithJobOutputs(outputs map[string]map[string]string) ParseOption
func WithJobResults ¶
func WithJobResults(results map[string]string) ParseOption
func WithVars ¶
func WithVars(vars map[string]string) ParseOption
func WithWorkflowNeeds ¶ added in v12.1.0
func WithWorkflowNeeds(needs []string) ParseOption
`WithWorkflowNeeds` allows overridding the `needs` field for a job being parsed.
In the case that a `SingleWorkflow`, returned from `Parse`, is passed back into `Parse` later in order to expand its IncompleteMatrix, then the jobs that it needs will not be present in the workflow (because `SingleWorkflow` only has one job in it). The `needs` field on the job itself may also be absent (Forgejo truncates the `needs` so that it can coordinate dispatching the jobs one-by-one without the runner panicing over missing jobs). However, the `needs` field is needed in order to populate the `needs` variable context. `WithWorkflowNeeds` can be used to indicate the needs exist and are fulfilled.
type RunDefaults ¶
type SingleWorkflow ¶
type SingleWorkflow struct {
Name string `yaml:"name,omitempty"`
RawOn yaml.Node `yaml:"on,omitempty"`
Env map[string]string `yaml:"env,omitempty"`
RawJobs yaml.Node `yaml:"jobs,omitempty"`
Defaults Defaults `yaml:"defaults,omitempty"`
EnableOpenIDConnect bool `yaml:"enable-openid-connect,omitempty"`
// IncompleteMatrix flag indicates that it wasn't possible to evaluate the `strategy.matrix` section of the job
// because it references a job output that is currently undefined. The workflow that this job came from will need
// to be reparsed using the `WithJobOutputs()` option, and it may result in this job being expanded into multiple
// jobs.
IncompleteMatrix bool `yaml:"incomplete_matrix,omitempty"`
IncompleteMatrixNeeds *IncompleteNeeds `yaml:"incomplete_matrix_needs,omitempty"`
// IncompleteRunsOn indicates that it wasn't possible to evaluate the `runs_on` section of the job
// because it references a job output that is currently undefined.
IncompleteRunsOn bool `yaml:"incomplete_runs_on,omitempty"`
IncompleteRunsOnNeeds *IncompleteNeeds `yaml:"incomplete_runs_on_needs,omitempty"`
IncompleteRunsOnMatrix *IncompleteMatrix `yaml:"incomplete_runs_on_matrix,omitempty"`
// IncompleteWith indicates that it wasn't possible to evaluate the `with` section of a job that is calling a
// reusable workflow because it references a job output that is currently undefined.
IncompleteWith bool `yaml:"incomplete_with,omitempty"`
IncompleteWithNeeds *IncompleteNeeds `yaml:"incomplete_with_needs,omitempty"`
IncompleteWithMatrix *IncompleteMatrix `yaml:"incomplete_with_matrix,omitempty"`
// Contains optional data that may be persisted alongside a workflow for internal use, but should not be subject to
// schema validation as it isn't user-entered. Unlike the `Incomplete...` fields, these fields will not be
// removed/resolved before transmission to a runner.
Metadata SingleWorkflowMetadata `yaml:"__metadata,omitempty"`
}
SingleWorkflow is a workflow with single job and single matrix
func Parse ¶
func Parse(content []byte, validate bool, options ...ParseOption) ([]*SingleWorkflow, error)
func (*SingleWorkflow) Job ¶
func (w *SingleWorkflow) Job() (string, *Job)
func (*SingleWorkflow) Marshal ¶
func (w *SingleWorkflow) Marshal() ([]byte, error)
type SingleWorkflowMetadata ¶ added in v12.3.0
type SingleWorkflowMetadata struct {
IncompleteRecursionDepth int `yaml:"incomplete_recursion_depth,omitempty"`
// When this workflow is a placeholder job that has been expanded into a reusable workflow, the inputs to the
// reusable workflow are stored here so that they can be used as a valid evaluation context in the reusable
// workflow's outputs later.
WorkflowCallInputs map[string]any `yaml:"workflow_call_inputs,omitempty"`
// When expanding reusable workflows, it is sometimes necessary to identify if a job was expanded into other jobs,
// and for those jobs to know which job was expanded. `WorkflowCallID` will be populated for a job that is
// expanded, and it is guaranteed to be unique within a workflow (unlike the job ID, which may be repeated for
// matrix evaluation). `WorkflowCallParent` indicates a job has a "parent" which was expanded to create it. Both
// may be populated if a reusable workflow is used within a reusable workflow.
WorkflowCallID string `yaml:"workflow_call_id,omitempty"`
WorkflowCallParent string `yaml:"workflow_call_parent,omitempty"`
}
type Step ¶
type Step struct {
ID string `yaml:"id,omitempty"`
If yaml.Node `yaml:"if,omitempty"`
Name string `yaml:"name,omitempty"`
Uses string `yaml:"uses,omitempty"`
Run string `yaml:"run,omitempty"`
WorkingDirectory string `yaml:"working-directory,omitempty"`
Shell string `yaml:"shell,omitempty"`
Env yaml.Node `yaml:"env,omitempty"`
With map[string]string `yaml:"with,omitempty"`
ContinueOnError bool `yaml:"continue-on-error,omitempty"`
TimeoutMinutes string `yaml:"timeout-minutes,omitempty"`
}