Help us shape the future of Go! Take the 2026 Go Developer Survey

actions

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 64 Imported by: 0

Documentation

Index

Constants

View Source
const MaxReusableCallLevels = 9

MaxReusableCallLevels caps how deep a reusable workflow can nest: a top-level caller may have at most MaxReusableCallLevels nested callers below it.

Variables

View Source
var EmitJobsIfReadyByRun = func(runID int64) error {
	err := jobEmitterQueue.Push(&jobUpdate{
		RunID: runID,
	})
	if errors.Is(err, queue.ErrAlreadyInQueue) {
		return nil
	}
	return err
}

Functions

func ApproveRuns added in v1.3.0

func ApproveRuns(ctx context.Context, repo *repo_model.Repository, doer *user_model.User, runIDs []int64) error

func BuiltinRunnerName added in v1.1.0

func BuiltinRunnerName() string

BuiltinRunnerName returns the reserved runner name for admin UI and diagnostics.

func BuiltinRunnerRunning added in v1.1.0

func BuiltinRunnerRunning() bool

BuiltinRunnerRunning reports whether the in-process runner poller is active.

func CancelAbandonedJobs

func CancelAbandonedJobs(ctx context.Context) error

CancelAbandonedJobs cancels jobs that have not been picked by any runner for a long time

func CancelPreviousJobs

func CancelPreviousJobs(ctx context.Context, repoID int64, ref, workflowID string, event webhook_module.HookEventType) error

func CleanRepoScheduleTasks

func CleanRepoScheduleTasks(ctx context.Context, repo *repo_model.Repository) error

func Cleanup

func Cleanup(ctx context.Context) error

Cleanup removes expired actions logs, data, artifacts and used ephemeral runners

func CleanupArtifacts

func CleanupArtifacts(taskCtx context.Context) error

CleanupArtifacts removes expired add need-deleted artifacts and set records expired status

func CleanupEphemeralRunners

func CleanupEphemeralRunners(ctx context.Context) error

CleanupEphemeralRunners removes used ephemeral runners which are no longer able to process jobs

func CleanupEphemeralRunnersByPickedTaskOfRepo

func CleanupEphemeralRunnersByPickedTaskOfRepo(ctx context.Context, repoID int64) error

CleanupEphemeralRunnersByPickedTaskOfRepo removes all ephemeral runners that have active/finished tasks on the given repository

func CleanupExpiredLogs

func CleanupExpiredLogs(ctx context.Context) error

CleanupExpiredLogs removes logs which are older than the configured retention time

func CreateAuthorizationToken

func CreateAuthorizationToken(taskID, runID, jobID int64) (string, error)

func CreateCommitStatusForRunJobs

func CreateCommitStatusForRunJobs(ctx context.Context, run *actions_model.ActionRun, jobs ...*actions_model.ActionRunJob)

CreateCommitStatusForRunJobs creates a commit status for the given job if it has a supported event and related commit. It won't return an error failed, but will log it, because it's not critical.

func CreateScheduleTask

func CreateScheduleTask(ctx context.Context, spec *actions_model.ActionScheduleSpec) error

CreateScheduleTask creates a scheduled task from a cron action schedule spec. It creates an action run based on the schedule, inserts it into the database, and creates commit statuses for each job.

func CreateSkippedCommitStatusForFilteredWorkflow added in v1.3.0

func CreateSkippedCommitStatusForFilteredWorkflow(ctx context.Context, repo *repo_model.Repository, event webhook_module.HookEventType, triggerEvent, workflowID string, content []byte, payload api.Payloader, scopedPrefix string, requiredGlobs []glob.Glob) error

CreateSkippedCommitStatusForFilteredWorkflow posts a skipped commit status for each job of a workflow that matched the triggering event but was excluded by a branch/paths filter. This lets a required status check tied to that context be satisfied without the workflow running. Only contexts matching requiredGlobs are posted; a non-required context gets no skipped status. No ActionRun is created, so the status has no target URL (there is no run/job to link to). A non-empty scopedPrefix prefixes each context with its source repo, matching scoped runs.

TODO: requiredGlobs over-approximates by including every protected branch rule's required contexts. If possible, the set should be narrowed to the required contexts of a specific branch protection rule (and the contexts from required scoped workflows). Currently, a `push` event must keep the repo-wide union since its future pull request base branch is unknown.

func CreateVariable

func CreateVariable(ctx context.Context, ownerID, repoID int64, name, data, description string) (*actions_model.ActionVariable, error)

func DeleteRun

func DeleteRun(ctx context.Context, run *actions_model.ActionRun) error

DeleteRun deletes workflow run, including all logs and artifacts.

func DeleteVariableByID

func DeleteVariableByID(ctx context.Context, variableID int64) error

func DeleteVariableByName

func DeleteVariableByName(ctx context.Context, ownerID, repoID int64, name string) error

func DetectAndHandleSchedules

func DetectAndHandleSchedules(ctx context.Context, repo *repo_model.Repository) error

DetectAndHandleSchedules detects the schedule workflows on the default branch and create schedule tasks

func DispatchActionWorkflow

func DispatchActionWorkflow(ctx reqctx.RequestContext, doer *user_model.User, repo *repo_model.Repository, gitRepo *git.Repository, workflowID, ref string, scopedWorkflowSourceRepoID int64, processInputs func(model *model.WorkflowDispatch, inputs map[string]any) error) (runID int64, _ error)

DispatchActionWorkflow manually triggers a workflow_dispatch run. scopedWorkflowSourceRepoID selects the workflow source: 0 means a repo-level workflow in this repo; a non-zero value is the source repo of a scoped workflow.

func DownloadArtifactV4 added in v1.3.0

func DownloadArtifactV4(ctx *context.Base, art *actions_model.ActionArtifact) error

func DownloadArtifactV4ReadStorage added in v1.3.0

func DownloadArtifactV4ReadStorage(ctx *context.Base, art *actions_model.ActionArtifact) error

func DownloadArtifactV4ServeDirect added in v1.3.0

func DownloadArtifactV4ServeDirect(ctx *context.Base, art *actions_model.ActionArtifact) bool

func EmitJobsIfReadyByJobs

func EmitJobsIfReadyByJobs(jobs []*actions_model.ActionRunJob)

func EnableOrDisableWorkflow

func EnableOrDisableWorkflow(ctx *context.APIContext, workflowID string, isEnable bool) error

func EvaluateJobConcurrencyFillModel

func EvaluateJobConcurrencyFillModel(ctx context.Context, run *actions_model.ActionRun, attempt *actions_model.ActionRunAttempt, actionRunJob *actions_model.ActionRunJob, vars map[string]string, inputs map[string]any) error

EvaluateJobConcurrencyFillModel evaluates the expressions in a job-level concurrency, and fills the job's model fields with `concurrency.group` and `concurrency.cancel-in-progress`. Job-level concurrency may depend on other job's outputs (via `needs`): `concurrency.group: my-group-${{ needs.job1.outputs.out1 }}` If the needed jobs haven't been executed yet, this evaluation will also fail. See https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#jobsjob_idconcurrency

func EvaluateRunConcurrencyFillModel

func EvaluateRunConcurrencyFillModel(ctx context.Context, run *actions_model.ActionRun, attempt *actions_model.ActionRunAttempt, wfRawConcurrency *act_model.RawConcurrency, vars map[string]string, inputs map[string]any) error

EvaluateRunConcurrencyFillModel evaluates the expressions in a run-level (workflow) concurrency, and fills the run attempt model with the evaluated `concurrency.group` and `concurrency.cancel-in-progress` values. Workflow-level concurrency doesn't depend on the job outputs, so it can always be evaluated if there is no syntax error. See https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#concurrency

func ExtractJobPermissionsFromWorkflow

func ExtractJobPermissionsFromWorkflow(flow *jobparser.SingleWorkflow, job *jobparser.Job) *repo_model.ActionsTokenPermissions

ExtractJobPermissionsFromWorkflow extracts permissions from an already parsed workflow/job. It returns nil if neither workflow nor job explicitly specifies permissions.

func FindTaskNeeds

func FindTaskNeeds(ctx context.Context, job *actions_model.ActionRunJob) (map[string]*TaskNeed, error)

FindTaskNeeds finds the `needs` for the task by the task's job. Lookup is scoped to the same ParentJobID.

func GetArtifactV4ServeDirectURL added in v1.3.0

func GetArtifactV4ServeDirectURL(art *actions_model.ActionArtifact, method string) (string, error)

func GetFailedJobsForRerun added in v1.3.0

func GetFailedJobsForRerun(allJobs []*actions_model.ActionRunJob) []*actions_model.ActionRunJob

GetFailedJobsForRerun returns the failed or cancelled jobs in a run.

func GetRunsFromCommitStatuses

func GetRunsFromCommitStatuses(ctx context.Context, statuses []*git_model.CommitStatus) ([]*actions_model.ActionRun, error)

func Init

func Init(ctx context.Context) error

func InsertRun

func InsertRun(ctx context.Context, run *actions_model.ActionRun, content []byte, vars map[string]string, inputs map[string]any, wfRawConcurrency *act_model.RawConcurrency) error

InsertRun inserts a run The title will be cut off at 255 characters if it's longer than 255 characters.

func IsArtifactV4 added in v1.3.0

func IsArtifactV4(art *actions_model.ActionArtifact) bool

IsArtifactV4 detects whether the artifact is likely from v4. V4 backend stores the files as a single combined zip file per artifact, and ensures ContentEncoding contains a slash (otherwise this uses application/zip instead of the custom mime type), which is not the case for the old backend.

func LoadParsedScopedWorkflows added in v1.3.0

func LoadParsedScopedWorkflows(ctx context.Context, sourceRepo *repo_model.Repository) (sha string, parsed []*actions_module.ParsedScopedWorkflow, err error)

LoadParsedScopedWorkflows returns the source repo's parsed scoped workflows at its current default-branch HEAD.

func NewNotifier

func NewNotifier() notify_service.Notifier

NewNotifier create a new actionsNotifier notifier

func NotifyWorkflowJobStatusUpdateWithTask added in v1.3.0

func NotifyWorkflowJobStatusUpdateWithTask(ctx context.Context, job *actions_model.ActionRunJob, task *actions_model.ActionTask)

NotifyWorkflowJobStatusUpdateWithTask notifies a single job status update when a concrete task is available. Use it for runner/task lifecycle callbacks so the notification includes the originating task context.

func NotifyWorkflowJobsAndRunsStatusUpdate added in v1.3.0

func NotifyWorkflowJobsAndRunsStatusUpdate(ctx context.Context, jobs []*actions_model.ActionRunJob)

NotifyWorkflowJobsAndRunsStatusUpdate notifies status changes for a batch of jobs and the runs they affect. Use it when a workflow operation updates multiple jobs and runs.

func NotifyWorkflowJobsStatusUpdate added in v1.3.0

func NotifyWorkflowJobsStatusUpdate(ctx context.Context, jobs ...*actions_model.ActionRunJob)

NotifyWorkflowJobsStatusUpdate notifies status updates for jobs without task. Use it for batch or single-job notifications after state changes.

func NotifyWorkflowRunStatusUpdate added in v1.3.0

func NotifyWorkflowRunStatusUpdate(ctx context.Context, run *actions_model.ActionRun)

NotifyWorkflowRunStatusUpdate notifies a run status update using the latest attempt trigger user when available. Use it for run-level notifications when the caller already has the run model loaded.

func NotifyWorkflowRunStatusUpdateWithReload

func NotifyWorkflowRunStatusUpdateWithReload(ctx context.Context, repoID, runID int64)

NotifyWorkflowRunStatusUpdateWithReload reloads the run before notifying its status update. Use it when only repo/run IDs are available or when the in-memory run may be stale after job updates.

func ParseAuthorizationToken

func ParseAuthorizationToken(req *http.Request) (int64, error)

func PickTask

func PickTask(ctx context.Context, runner *actions_model.ActionRunner) (*runnerv1.Task, bool, error)

func PrepareRunAndInsert

func PrepareRunAndInsert(ctx context.Context, content []byte, run *actions_model.ActionRun, inputsWithDefaults map[string]any) error

PrepareRunAndInsert prepares a run and inserts it into the database It parses the workflow content, evaluates concurrency if needed, and inserts the run and its jobs into the database. The title will be cut off at 255 characters if it's longer than 255 characters.

func PrepareToStartJobWithConcurrency

func PrepareToStartJobWithConcurrency(ctx context.Context, job *actions_model.ActionRunJob) (actions_model.Status, []*actions_model.ActionRunJob, error)

PrepareToStartJobWithConcurrency prepares a job to start by its evaluated concurrency group and cancelling previous jobs if necessary. It returns the new status of the job (either StatusBlocked or StatusWaiting), any cancelled jobs, and any error encountered during the process.

func PrepareToStartRunWithConcurrency

func PrepareToStartRunWithConcurrency(ctx context.Context, attempt *actions_model.ActionRunAttempt) (actions_model.Status, []*actions_model.ActionRunJob, error)

PrepareToStartRunWithConcurrency prepares a run attempt to start by its evaluated concurrency group and cancelling previous jobs if necessary. It returns the new status of the run attempt (either StatusBlocked or StatusWaiting), any cancelled jobs, and any error encountered during the process.

func RerunWorkflowRunJobs

func RerunWorkflowRunJobs(ctx context.Context, repo *repo_model.Repository, run *actions_model.ActionRun, triggerUser *user_model.User, jobsToRerun []*actions_model.ActionRunJob) (*actions_model.ActionRunAttempt, error)

RerunWorkflowRunJobs reruns the given jobs of a workflow run. An empty jobsToRerun means rerunning the whole run. Otherwise jobsToRerun contains only the user-requested target jobs; downstream dependent jobs are expanded internally while building the rerun plan.

The three stages below (legacy backfill, plan build, plan exec) deliberately run in separate DB transactions rather than one big outer transaction:

  • execRerunPlan performs slow work (loading variables, YAML unmarshal, concurrency expression evaluation) before opening its own transaction, so the tx stays focused on inserts/updates. (Exception: reusable workflow caller expansion runs inside the tx, see expandReusableWorkflowCaller's doc.)
  • The legacy backfill is idempotent-friendly: if it succeeds but a later stage fails, a subsequent rerun will observe run.LatestAttemptID != 0 and skip the backfill, continuing naturally. No data corruption or stuck state results from partial progress.

Fast validations that can catch failures early (workflow disabled, run not done, etc.) are therefore pushed into validateRerun so we rarely enter createOriginalAttemptForLegacyRun only to fail afterwards.

func ResolveUses added in v1.3.0

func ResolveUses(ctx context.Context, uses string) (*jobparser.UsesRef, error)

ResolveUses normalizes and parses a reusable workflow `uses:` value. It first rewrites an absolute URL pointing to this instance into the cross-repo form (rejecting external URLs), then validates the syntax via jobparser.ParseUses.

func RestartBuiltinRunner added in v1.1.0

func RestartBuiltinRunner(ctx context.Context) error

RestartBuiltinRunner replaces the server-owned runner registration and poller.

func ScopedWorkflowContent added in v1.3.0

func ScopedWorkflowContent(ctx context.Context, sourceRepo *repo_model.Repository, entryName string) ([]byte, error)

ScopedWorkflowContent returns one scoped workflow's raw content (by entry name) at the source repo's current default-branch HEAD, or nil if no such workflow exists there.

func StartBuiltinRunner added in v1.1.0

func StartBuiltinRunner(ctx context.Context) error

StartBuiltinRunner starts the server-owned Actions runner after routes are mounted. It is safe to call before the HTTP listener is ready; the runner retries declaration.

func StartScheduleTasks

func StartScheduleTasks(ctx context.Context) error

StartScheduleTasks start the task

func StopBuiltinRunner added in v1.1.0

func StopBuiltinRunner(ctx context.Context) error

StopBuiltinRunner stops the server-owned runner without changing its config.

func StopEndlessTasks

func StopEndlessTasks(ctx context.Context) error

StopEndlessTasks stops running tasks with continuous updates that don't end for a long time. StatusRunning only: the threshold is the task's *start* time, so including StatusCancelling would kill a task mid post-cancel cleanup. StopZombieTasks covers a stalled one, keying off the last update instead.

func StopZombieTasks

func StopZombieTasks(ctx context.Context) error

StopZombieTasks stops tasks in running/cancelling status that haven't been updated for a long time

func TokenToTaskID

func TokenToTaskID(token string) (int64, error)

TokenToTaskID returns the TaskID associated with the provided JWT token

func TryPickTask added in v1.3.0

func TryPickTask(ctx context.Context, runner *actions_model.ActionRunner) (task *runnerv1.Task, ok, throttled bool, err error)

TryPickTask attempts to assign a task to the runner, bounding the number of concurrent assignment transactions to avoid a thundering herd when many runners poll at once. When the concurrency limit is reached it returns throttled=true without touching the DB, so the caller can let the runner retry on its next poll instead of advancing its tasks version.

func UpdateVariableNameData

func UpdateVariableNameData(ctx context.Context, variable *actions_model.ActionVariable) (bool, error)

Types

type API

type API interface {
	// ListActionsSecrets list secrets
	ListActionsSecrets(*context.APIContext)
	// CreateOrUpdateSecret create or update a secret
	CreateOrUpdateSecret(*context.APIContext)
	// DeleteSecret delete a secret
	DeleteSecret(*context.APIContext)
	// ListVariables list variables
	ListVariables(*context.APIContext)
	// GetVariable get a variable
	GetVariable(*context.APIContext)
	// DeleteVariable delete a variable
	DeleteVariable(*context.APIContext)
	// CreateVariable create a variable
	CreateVariable(*context.APIContext)
	// UpdateVariable update a variable
	UpdateVariable(*context.APIContext)
	// CreateRegistrationToken get registration token
	CreateRegistrationToken(*context.APIContext)
	// ListRunners list runners
	ListRunners(*context.APIContext)
	// GetRunner get a runner
	GetRunner(*context.APIContext)
	// DeleteRunner delete runner
	DeleteRunner(*context.APIContext)
	// UpdateRunner update runner
	UpdateRunner(*context.APIContext)
	// ListWorkflowJobs list jobs
	ListWorkflowJobs(*context.APIContext)
	// ListWorkflowRuns list runs
	ListWorkflowRuns(*context.APIContext)
}

API for actions of a repository or organization

type DashboardStats added in v1.1.0

type DashboardStats struct {
	Items []*DashboardWorkerItem

	TotalRunners    int64
	ActiveRunners   int64
	IdleRunners     int64
	OfflineRunners  int64
	DisabledRunners int64
	RunningJobs     int64
	QueuedJobs      int64
	SuccessLastDay  int64
	FailureLastDay  int64
	LastCompleted   *actions_model.ActionRun
}

DashboardStats is the small, read-only Actions operations snapshot used by the home page.

func GetDashboardStats added in v1.1.0

func GetDashboardStats(ctx context.Context) (*DashboardStats, error)

GetDashboardStats returns a bounded, database-backed snapshot of runner activity. It deliberately keeps the query surface small and does not add a queue or metrics dependency.

type DashboardWorkerItem added in v1.1.0

type DashboardWorkerItem struct {
	Runner *actions_model.ActionRunner
	Job    *actions_model.ActionRunJob
	Run    *actions_model.ActionRun
	Repo   *repo_model.Repository

	Status    actions_model.Status
	IsQueued  bool
	IsRunning bool
	Search    string
	Updated   timeutil.TimeStamp
}

DashboardWorkerItem is an active or queued Actions job shown on the user dashboard. Completed jobs are intentionally excluded so the panel remains an operations view.

type GiteaContext

type GiteaContext map[string]any

func GenerateGiteaContext

GenerateGiteaContext generate the gitea context without token and gitea_runtime_token. attempt and job can be nil when generating a context for parsing workflow-level expressions.

The run_attempt value is resolved with the following precedence:

  1. attempt.Attempt - the explicit attempt argument, or run.GetLatestAttempt() as a fallback
  2. job.Attempt - only used when neither an explicit nor latest attempt is available
  3. "1" - when none of the above apply (first-run parse time, before the first attempt exists)

func (*GiteaContext) ToGitHubContext

func (g *GiteaContext) ToGitHubContext() *model.GithubContext

type TaskNeed

type TaskNeed struct {
	Result  actions_model.Status
	Outputs map[string]string
}

Jump to

Keyboard shortcuts

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