actions

package
v1.28.0-dev Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 54 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

This section is empty.

Functions

func ApproveRuns

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

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 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

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

func DownloadArtifactV4ReadStorage

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

func DownloadArtifactV4ServeDirect

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

func EmitJobsIfReadyByJobs

func EmitJobsIfReadyByJobs(jobs []*actions_model.ActionRunJob)

func EmitJobsIfReadyByRun

func EmitJobsIfReadyByRun(runID int64) error

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

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

func GetFailedJobsForRerun

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

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

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

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

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

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

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

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 ScopedWorkflowContent

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 StartScheduleTasks

func StartScheduleTasks(ctx context.Context) error

StartScheduleTasks start the task

func StopEndlessTasks

func StopEndlessTasks(ctx context.Context) error

StopEndlessTasks stops tasks in running/cancelling status with continuous updates that don't end for a long time

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 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 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