gocto

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: Apache-2.0 Imports: 8 Imported by: 2

README

gocto

Generate/Manage Github Workflow's with Go

Documentation

Index

Constants

View Source
const (
	DefaultPathToWorkflows = "./.github/workflows"
)

Variables

This section is empty.

Functions

func FilenameFor

func FilenameFor(w Workflow) string

Types

type AccessLevel

type AccessLevel string
const (
	AccessLevelWrite AccessLevel = "write"
	AccessLevelRead  AccessLevel = "read"
	AccessLevelNone  AccessLevel = "none"
)

type CallInput

type CallInput struct {
	Description string        `json:"description,omitempty,omitzero"`
	Default     string        `json:"default,omitempty,omitzero"`
	Required    bool          `json:"required,omitempty,omitzero"`
	Type        CallInputType `json:"type,omitempty,omitzero"`
}

type CallInputType

type CallInputType string
const (
	CallInputTypeString  CallInputType = "string"
	CallInputTypeBoolean CallInputType = "boolean"
	CallInputTypeNumber  CallInputType = "number"
)

type CallOutput

type CallOutput struct {
	Description string `json:"description,omitempty,omitzero"`
	Value       string `json:"value,omitempty,omitzero"`
}

type CallSecrets

type CallSecrets struct {
	Description string `json:"description,omitempty,omitzero"`
	Required    bool   `json:"required,omitempty,omitzero"`
}

type Concurrency

type Concurrency struct {
	Group            string `json:"group,omitempty,omitzero"`
	CancelInProgress bool   `json:"cancel-in-progress,omitempty,omitzero"`
}

Concurrency https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#concurrency

type Container

type Container struct {
	Image       string               `json:"image,omitempty,omitzero"`
	Env         map[string]string    `json:"env,omitempty,omitzero"`
	Ports       map[string]int       `json:"ports,omitempty,omitzero"`
	Volumes     []string             `json:"volumes,omitempty,omitzero"`
	Credentials ContainerCredentials `json:"credentials,omitempty,omitzero"`
	Options     string               `json:"options,omitempty,omitzero"`
}

type ContainerCredentials

type ContainerCredentials struct {
	Username string `json:"username,omitempty,omitzero"`
	Password string `json:"password,omitempty,omitzero"`
}

type Defaults

type Defaults struct {
	Run DefaultsRun `json:"run,omitempty,omitzero"`
}

type DefaultsRun

type DefaultsRun struct {
	Shell            Shell  `json:"shell,omitempty,omitzero"`
	WorkingDirectory string `json:"working-directory,omitempty,omitzero"`
}

type Environment

type Environment struct {
	Name string `json:"name,omitempty,omitzero"`
	URL  string `json:"url,omitempty,omitzero"`
}

type Job

type Job struct {
	Name            string            `json:"name,omitempty,omitzero"`
	Permissions     Permissions       `json:"permissions,omitempty,omitzero"`
	Needs           StringOrSlice     `json:"needs,omitempty,omitzero"`
	If              string            `json:"if,omitempty,omitzero"`
	RunsOn          StringOrSlice     `json:"runs-on,omitempty,omitzero"`
	Environment     Environment       `json:"environment,omitempty,omitzero"`
	Concurrency     Concurrency       `json:"concurrency,omitempty,omitzero"`
	Outputs         map[string]string `json:"outputs,omitempty,omitzero"`
	Env             map[string]string `json:"env,omitempty,omitzero"`
	Defaults        Defaults          `json:"defaults,omitempty,omitzero"`
	Steps           []Step            `json:"steps,omitempty,omitzero"`
	TimeoutMinutes  int               `json:"timeout-minutes,omitempty,omitzero"`
	ContinueOnError bool              `json:"continue-on-error,omitempty,omitzero"`
	Uses            string            `json:"uses,omitempty,omitzero"`
	With            map[string]string `json:"with,omitempty,omitzero"`
	Secrets         *Secrets          `json:"secrets,omitempty,omitzero"`
	Container       Container         `json:"container,omitempty,omitzero"`
	Strategy        Strategy          `json:"strategy,omitempty,omitzero"`
}

type Matrix

type Matrix struct {
	Map     map[string][]StringOrInt
	Include []map[string]StringOrInt
	Exclude []map[string]StringOrInt
}

func (*Matrix) MarshalJSON

func (m *Matrix) MarshalJSON() ([]byte, error)

func (*Matrix) UnmarshalJSON

func (m *Matrix) UnmarshalJSON(data []byte) error

type OnBranches

type OnBranches struct {
	Branches       []string `json:"branches,omitempty,omitzero"`
	BranchesIgnore []string `json:"branches-ignore,omitempty,omitzero"`
}

type OnCall

type OnCall struct {
	Inputs  map[string]CallInput  `json:"inputs,omitempty,omitzero"`
	Outputs map[string]CallOutput `json:"outputs,omitempty,omitzero"`
}

type OnDispatch

type OnDispatch struct {
	Inputs map[string]OnDispatchInput `json:"inputs,omitempty,omitzero"`
}

type OnDispatchInput

type OnDispatchInput struct {
	Description string              `json:"description,omitempty,omitzero"`
	Required    bool                `json:"required"`
	Default     string              `json:"default,omitempty,omitzero"`
	Type        OnDispatchInputType `json:"type,omitempty,omitzero"`
	Options     []string            `json:"options,omitempty,omitzero"`
}

type OnDispatchInputType

type OnDispatchInputType string
const (
	OnDispatchInputTypeString      OnDispatchInputType = "string"
	OnDispatchInputTypeBoolean     OnDispatchInputType = "boolean"
	OnDispatchInputTypeNumber      OnDispatchInputType = "number"
	OnDispatchInputTypeEnvironment OnDispatchInputType = "environment"
	OnDispatchInputTypeChoice      OnDispatchInputType = "choice"
)

type OnPaths

type OnPaths struct {
	Paths       []string `json:"paths,omitempty,omitzero"`
	PathsIgnore []string `json:"paths-ignore,omitempty,omitzero"`
}

type OnPullRequest

type OnPullRequest struct {
	*OnPaths    `json:",inline"`
	*OnBranches `json:",inline"`
}

type OnPush

type OnPush struct {
	*OnPaths    `json:",inline"`
	*OnBranches `json:",inline"`
	*OnTags     `json:",inline"`
}

type OnSchedule

type OnSchedule struct{}

type OnTags

type OnTags struct {
	Tags       []string `json:"tags,omitempty,omitzero"`
	TagsIgnore []string `json:"tags-ignore,omitempty,omitzero"`
}

type OnWorkflowRun

type OnWorkflowRun struct {
	Workflows   []string `json:"workflows,omitempty,omitzero"`
	Types       []string `json:"types,omitempty,omitzero"`
	*OnBranches `json:",inline"`
}

type Permissions

type Permissions struct {
	Actions        AccessLevel `json:"actions,omitempty,omitzero"`
	Attestations   AccessLevel `json:"attestations,omitempty,omitzero"`
	Checks         AccessLevel `json:"checks,omitempty,omitzero"`
	Contents       AccessLevel `json:"contents,omitempty,omitzero"`
	Deployments    AccessLevel `json:"deployments,omitempty,omitzero"`
	Discussions    AccessLevel `json:"discussions,omitempty,omitzero"`
	IDToken        AccessLevel `json:"id-token,omitempty,omitzero"`
	Issues         AccessLevel `json:"issues,omitempty,omitzero"`
	Models         AccessLevel `json:"models,omitempty,omitzero"`
	Packages       AccessLevel `json:"packages,omitempty,omitzero"`
	Pages          AccessLevel `json:"pages,omitempty,omitzero"`
	PullRequests   AccessLevel `json:"pull-requests,omitempty,omitzero"`
	SecurityEvents AccessLevel `json:"security-events,omitempty,omitzero"`
	Statuses       AccessLevel `json:"statuses,omitempty,omitzero"`
}

type Secrets

type Secrets struct {
	Inherit bool              `json:"-"`
	Map     map[string]string `json:"-"`
}

func (*Secrets) MarshalJSON

func (s *Secrets) MarshalJSON() ([]byte, error)

func (*Secrets) UnmarshalJSON

func (s *Secrets) UnmarshalJSON(data []byte) error

type Shell

type Shell string
const (
	ShellBash Shell = "bash"
)

type Step

type Step struct {
	ID               string            `json:"id,omitempty,omitzero"`
	Name             string            `json:"name,omitempty,omitzero"`
	If               string            `json:"if,omitempty,omitzero"`
	Uses             string            `json:"uses,omitempty,omitzero"`
	Run              string            `json:"run,omitempty,omitzero"`
	WorkingDirectory string            `json:"working-directory,omitempty,omitzero"`
	Shell            Shell             `json:"shell,omitempty,omitzero"`
	With             map[string]any    `json:"with,omitempty,omitzero"`
	Env              map[string]string `json:"env,omitempty,omitzero"`
	ContinueOnError  bool              `json:"continue-on-error,omitempty,omitzero"`
	TimeoutMinutes   int               `json:"timeout-minutes,omitempty,omitzero"`
}

func TernaryExpressionStep

func TernaryExpressionStep(stepID, bashCond, thenVal, elseVal string) Step

TernaryExpressionStep is a better way to do if/else than with pure expressions, because of the pitfalls of truthy and falsy values

https://github.com/orgs/community/discussions/26738 Ternary Expressions suck in GitHub Actions, don't use them, instead use a bash expression more about all the pitfalls of trying to use || && here: https://7tonshark.com/posts/github-actions-ternary-operator/

the output name is "value", e.g. steps.my-step-id.outputs.value

func (Step) WithEnv

func (s Step) WithEnv(key, value string) Step

func (Step) WithID

func (s Step) WithID(id string) Step

func (Step) WithName

func (s Step) WithName(name string) Step

type Strategy

type Strategy struct {
	Matrix      *Matrix `json:"matrix,omitempty,omitzero"`
	FailFast    bool    `json:"fail-fast,omitempty,omitzero"`
	MaxParallel int     `json:"max-parallel,omitempty,omitzero"`
}

type StringOrInt

type StringOrInt struct {
	StringValue *string
	IntValue    *int
}

func (*StringOrInt) GetIntValue

func (x *StringOrInt) GetIntValue() int

func (*StringOrInt) GetStringValue

func (x *StringOrInt) GetStringValue() string

func (*StringOrInt) MarshalJSON

func (x *StringOrInt) MarshalJSON() ([]byte, error)

func (*StringOrInt) TryGetIntValue

func (x *StringOrInt) TryGetIntValue() (int, error)

func (*StringOrInt) TryGetStringValue

func (x *StringOrInt) TryGetStringValue() (string, error)

func (*StringOrInt) UnmarshalJSON

func (x *StringOrInt) UnmarshalJSON(data []byte) error

type StringOrSlice added in v0.6.0

type StringOrSlice []string

func (StringOrSlice) MarshalJSON added in v0.6.0

func (j StringOrSlice) MarshalJSON() ([]byte, error)

func (*StringOrSlice) UnmarshalJSON added in v0.6.0

func (j *StringOrSlice) UnmarshalJSON(data []byte) error

type Workflow

type Workflow struct {
	Name        string            `json:"name"`
	RunName     string            `json:"run-name,omitempty,omitzero"`
	On          WorkflowOn        `json:"on"`
	Concurrency Concurrency       `json:"concurrency,omitempty,omitzero"`
	Defaults    Defaults          `json:"defaults,omitempty,omitzero"`
	Env         map[string]string `json:"env,omitempty,omitzero"`
	Permissions Permissions       `json:"permissions,omitempty,omitzero"`
	Jobs        map[string]Job    `json:"jobs"`
	// contains filtered or unexported fields
}

Workflow https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#about-yaml-syntax-for-workflows

func (*Workflow) GetFilename added in v0.2.0

func (w *Workflow) GetFilename() string

func (*Workflow) GetRelativePathAndFilename added in v0.2.0

func (w *Workflow) GetRelativePathAndFilename() string

func (*Workflow) SetFilename added in v0.3.0

func (w *Workflow) SetFilename(value string)

type WorkflowOn

type WorkflowOn struct {
	Call              *OnCall        `json:"workflow_call,omitempty,omitzero"`
	Run               *OnWorkflowRun `json:"workflow_run,omitempty,omitzero"`
	Dispatch          *OnDispatch    `json:"workflow_dispatch,omitempty,omitzero"`
	Schedule          *OnSchedule    `json:"schedule,omitempty,omitzero"`
	PullRequest       *OnPullRequest `json:"pull_request,omitempty"`
	PullRequestTarget *OnPullRequest `json:"pull_request_target,omitempty,omitzero"`
	Push              *OnPush        `json:"push,omitempty,omitzero"`
}

WorkflowOn https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#on

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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