13 Design workflows
Forgejo Actions edited this page 2026-11-25 15:00:54 +00:00

Workflows

Status: NewPipeline composes native xyOps deployment orchestration. Native permissions and audit authorize and record Suspend/Resume.

Package workflow has two constructs: NewXyopsWorkflow (a validated native graph) and NewPipeline (the deployment pipeline below). The older XyopsPipeline (three-event approval protocol with an embedded runtime) and the abstract workflow.New document model were removed in 0.3.0-dev.29.

Naming

Every xyOps object a stack owns is titled <stack>-<id> (xyops.Title), so names in the UI match the code: deployer-arch_deploy, deployer-arch_deploy_plan. IDs keep xyOps' [a-z0-9_] (it refuses hyphens), so the hyphen marks the stack. A different title is refused at synthesis. Secrets follow the rule too; a UI-created secret adopted by import may keep its title.

Native deployment pipeline

workflow.NewPipeline takes an ordered []workflow.Step. The arch example owns three events; neither approval nor deployment is implicit:

trigger → plan (<id>_plan) → changes? ─ yes → approval (<id>_approval) → deploy (<id>_deploy)
                                       └ no  → run ends
  • plan emits data.changes only after successful planning; false ends the run (xyOps has no exit node; a decision with no matching wire is the end).
  • approval is its own event: a no-op job with two actions at start: the step's optional web hook (e.g. ntfy, "waiting for approval") and a suspend. An authorized Resume lets it run and the graph continues to deploy; Abort declines. Because both fire at start, they only happen when the plan has changes.
  • deploy must enforce pinned intent, expiry, replay protection and disruption guards itself. The graph is not that policy.

Node IDs are the step names (plan, changes, approval, deploy); trigger nodes are manual / magic.

Runs and queueing

MaxRuns limits concurrent runs of the workflow; Queue holds further runs in xyOps' native FIFO queue for up to TimeoutSeconds. A workflow job stays active for its whole life, including while approval is suspended, so with MaxRuns: 1, Queue: n exactly one run is in progress (planning, waiting or deploying) and the rest wait without starting any step. A queued run therefore holds no credentials and cannot age a token: authenticate before the pipeline, in an intake event that launches it.

Intake: authenticate first, then launch

xyops.EventProps.OnSuccess adds a native Run Event action: on success, xyOps launches the referenced event or workflow (XyopsWorkflow.Ref()) with the intake job's output data as its input, records the intake job as its parent, and the launcher depends on the launched resource:

CI → magic link → intake event (no queue; verifies the CI token while fresh,
                                 outputs verified facts only, never the token)
         └─ on success → pipeline (MaxRuns 1, queue) → plan → changes? → approval → deploy

Steps must not take deployment intent from caller-mutable data (Resume input, redirects). Read the intake job record from xyOps (get_job on the run's parent.job) and re-check what xyOps cannot vouch for (commit on main, CI green, newer than the last deploy).

Steps: owned or shared events

Steps: []workflow.Step{
    workflow.Task("plan", planScript, 1800),
    workflow.Gate("changes", "data.changes == true"),
    workflow.ApprovalStep("approval", "ntfy_ops"),
    workflow.Task("deploy", deployScript, 1800),
},

Tasks (Task or PluginTask) and approvals create <pipeline id>_<step id>; pipeline.Owned[stepID] is the resource for grants. Run reuses an event by reference without installing it again. For instance, Run("verify", child.Workflow.Ref()) waits for that child workflow's result before the next step; the child needs a manual trigger. OnSuccess launches a separate job without waiting for completion. Use NewXyopsWorkflow directly for fan-out and joins.

Custom Event Plugins

A Task's inline Script runs on the stock Shell Plugin as an event parameter. xySat copies every job parameter into the job environment and drops a variable above 64 KiB, and each event stores its own copy, so large or shared programs belong in a custom Event Plugin, as xyOps recommends:

release := xyops.NewPlugin(stack, "service_release", xyops.PluginProps{
    ID: "service_release", Command: "/usr/bin/python3 -I", Script: releaseProgram,
})
Steps: []workflow.Step{
    workflow.PluginTask("plan", release, 1800),
    workflow.ApprovalStep("approval", "ntfy_ops"),
    workflow.PluginTask("deploy", release, 1800),
},
  • How it runs. The satellite writes Script to <temp>/plugins/<id> and runs Command <file> in the job directory, with the job as one JSON line on STDIN (wire protocol). The script never enters the environment (job.script is "(File)").
  • No secrets in plugin code. xyOps sends every Event Plugin's script to every satellite when it joins and whenever a plugin changes. Grant secrets to the events (xyops.SecretProps.Events) instead.
  • No parameters. The plugin declares params: [] and its events pass {}, so a magic link or API caller can supply only an event's declared Fields. A program shared by several steps must take its role from the scheduler-asserted job.event, never from job.params.
  • What is enforced. IDs are [a-z0-9_], never a stock ID (or anything ending in plug), and claimed app-wide in their own namespace. Command is an absolute path plus fixed words; quotes, $, globs and other shell metacharacters are refused, since xySat expands $VARS in arguments. Kill defaults to all. The plugin and its events must be in one stack: each event depends on its plugin, and the plugin refuses destroy.
  • xyops.EventProps.Plugin takes a plugin directly; exactly one of Script or Plugin is set.

To keep large inline scripts from returning, add xyops.CheckInlineScripts(stack, xyops.MaxInlineScript) (16 KiB) to a consumer test. It returns the addresses of Shell Plugin events whose script exceeds the limit; plugin events are never reported.

Uniqueness

xyOps events and workflows share one ID namespace.

  • Within an app: every xyops.NewEvent, NewXyopsWorkflow and NewPipeline claims its IDs across all stacks; secrets claim theirs separately. A second declaration fails synthesis and names the first owner. Refusals leave no partial resources.
  • On the instance: synthesis cannot see objects other apps or the UI created. yawn id-guard -existing ids.json < plan.json refuses a plan that would create an event or workflow whose ID already exists on the instance (ids.json = every ID from xyOps get_events). Imports and updates are not creations. Deploy engines run it between plan and apply.

Concurrency

  • MaxRuns / Queue: concurrent and waiting runs of the workflow (a run waiting for approval still counts).
  • StepConcurrency: job limit on events the pipeline owns (defaults to MaxRuns). Shared events keep their own limits.
  • Target locking: runs mutating the same infrastructure must be serialized by the handlers (a lock keyed by target). The graph cannot know which runs overlap.

Authorization and audit

Entirely native xyOps: Resume requires run_jobs and applicable category/target access; API keys with the same privileges can resume. There is no per-pipeline username allowlist, audit-text parsing, or UI-only claim. Handlers must not use Resume input or redirects to select deployment intent. Administrators and event editors are trusted.

Arch CI uses release:submit-release and links the admitted intake. Admission is not deployment.

Application worker graphs

Register each logical pipeline/environment once in a platform-owned workload.Registry. Its immutable key survives moving an executor, replacing a worker event, renaming a release entry, or deploying another revision. The service manifest names only its service and operations; it cannot select a tenant, host, state path, worker or secret. Existing v1 workload.Bind remains available for older site-bound releases; it does not acquire these guarantees automatically.

// Handle each error before proceeding. Registration and worker bindings are platform code.
registry, err := workload.NewRegistry(workload.Registration{
    EntryKey: workload.EntryKey{RepositoryID: 17, Entry: "orders_release"},
    PipelineID: "orders", Environment: "prod", Service: "orders",
    Grants: []workload.Capability{workload.WorkflowDeploy, workload.Docker,
        workload.GetState, workload.RecordSuccess},
})
ctx, err := registry.Admit(verifiedEntry) // verified repo ID + release entry, not HTTP/job input
steps, err := ctx.BindRelease([]byte(`{"version":2,"service":"orders","steps":["deploy_docker"]}`))
call, err := ctx.Call(workload.Docker)
params, err := call.Params() // literal graph labels for the platform's worker node

The platform maps each admitted operation to its own reviewed worker and builds the body with workflow.NewPipeline (an owned pipeline reaches shared workers through workflow.CallStep). The manifest cannot invoke get_state or fake a record_success; the reviewed worker calls those operations only at the appropriate phases.

A receiving worker checks its expected operation and the graph hints with registry.Authorize(verifiedEntry, workload.Docker, params). It uses the resulting call.Call(workload.GetState) and, only after successful deployment and health checks, call.Call(workload.RecordSuccess). Each nested call inherits exactly call.Tenant(); it has no tenant override and checks the grant again. For nested dispatch, send the child's Params() and re-authorize at the receiving worker, rather than forwarding parent or user input. Adapters resolve resources and storage by this opaque logical key. Moving a worker or its state transport is a site binding change, not a manifest edit or a new namespace.

Trust boundary: graph parameters are labels, not signed credentials. Before each side effect, trusted handlers must independently verify authoritative job ancestry (including the permitted parent/node and selected worker), repository identity, entry and release evidence. Reject missing lineage, mismatched labels or direct starts. Never admit from request data, Resume input, or a claimed tenant ID. The library does not verify job records, perform storage I/O, apply policy to existing installations, or grant infrastructure credentials.

Portable pipeline contracts

The additive pipeline package is for app-owned, data-only pipelines.json files. A file contains one or more named entries, each with a versioned input record type and a serial list of named capability references. Real inputs are produced and verified by trusted handlers; declarations do not supply data, scripts, destination, credentials or event refs. yawn pipeline check -catalog capability-catalog.json checks names, versions and type compatibility offline. It does not authorize a release.

A platform builds a read-only pipeline.Catalog from Go declarations and keeps registrations and worker refs private. (immutable repository ID, entry name) selects a registration, with its own logical pipeline/environment, workflow path, branch-or-tag policy, allowed capabilities, and required input and final output. Two entries in one repository can have separate policies; another repository can reuse the same entry name. Physical workflow IDs and logical tenants remain unique. Each tenant in a repository must use a distinct workflow path or a disjoint ref policy; an Actions job can ask for any audience, so an audience alone cannot separate grants. Published catalog entries are not grants.

After authenticating the request and verifying the authoritative ref, exact revision and CI, bind only the selected entry with Registry.Bind; Bound.Steps lists its admitted steps for the platform to lower into its own body. Binding never starts a job or writes credentials. The adapter must verify the submitted manifest bytes are from that revision, reconcile only the registered body, serialize definition updates against active runs, and bind execution to trusted run ancestry and the installed definition. Node parameters do not confer authority. The pipeline package does not perform any of those privileged operations; existing release entries and workload v1/v2 remain unchanged.

Returning admission to CI

Use the pinned release:submit-release action with Forgejo OIDC enabled. It selects the audience for the registered repository and entry, submits one versioned release_request, and reads the intake's terminal SSE update using its job-scoped token. Optional digest binds the staged artifact manifest; CI does not wait for downstream execution or approval.

The installed, trusted intake verifies OIDC, protected ref, exact commit, and completed build/check evidence independently of the waiting submit job. After checking the entry's capability requirements against installed bindings, it emits this bounded data.admission result for the authenticated repo, entry and SHA, e.g.:

{"version":1,"repository_id":13,"entry":"apps","sha":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","status":"compatible"}

An incompatible result uses status: incompatible, a nonzero job exit, and a bounded reason and required capability. Supported reasons: missing_capability, not_granted, and incompatible_version (also includes provided, of the same capability name). A refused intake must not launch the release. Do not emit bearer tokens, internal bindings, or raw scheduler diagnostics in the result. An older intake with no verdict is not a success; neither are a wrong job, entry or commit, a timeout, or a disconnect. CI links the intake if it has an ID and does not submit again; the original request may still run. The trusted runtime still has to pin and recheck the admitted binding before writes.

Install and validate the matching receiver before enabling a caller. The action is not a server implementation or a grant.

Backend boundary

workflow.NewXyopsWorkflow(stack, name, props) creates a xyops_workflow resource from native Nodes, Connections, Triggers, Actions, Limits and Tags; imports and destroy protection are supported. It is installed when its stack is applied, never executed during synthesis. A suspend action must carry sources, users, email, web_hook and text, or the xyOps 1.1.17 map renderer shows a blank map.

References: xyOps workflow model, data model, job API.

Release-controller boundary

Agreed entry point: successful main CI → OIDC request → independently verify CI → decide version/tag → dispatch runner publication → verify build/artifact identity → sign → optional deployment pipeline. No repository webhook is needed. Never build application source on the signing executor.

Not yet implemented here: reusable release-version/tag/dispatch/signing handlers, runner provenance verification or migration from john/release. OIDC proves identity, not test success.