Documentation
¶
Overview ¶
Package ci generates a repository's Forgejo Actions workflows from one small declaration, yawn.json, and runs its tasks the same way locally and in CI.
{
"version": 1,
"yawn": {"version": "0.3.0-dev.21", "sha256": {"linux_amd64": "…", "linux_arm64": "…"}},
"tasks": {
"test": {"description": "Unit tests", "run": ["go vet ./...", "go test ./..."]}
},
"workflows": [
{"file": "ci.yml", "name": "CI",
"on": {"pull_request": {"branches": ["main"]}, "push": {"branches": ["main"]}},
"jobs": [{"id": "checks", "task": "test"}, {"id": "release-check", "uses": "release-check"}]}
]
}
`yawn ci generate` writes .forgejo/workflows/<file> for every workflow; `yawn ci verify` fails when a committed file differs from what generate would write. A task job installs the pinned yawn (checksum-verified) and runs `yawn run <task>`, the same command a developer runs locally, so a check means the same thing on a laptop and on a runner.
Generated workflows hold no infrastructure secret. Privileged steps (sign, deploy) are `yawn request` calls to xyOps, which verifies the caller. Workflows that do not fit this shape stay hand-written next to the generated ones; verify only owns files that carry the generated marker.
Index ¶
- Constants
- Variables
- func Drift(root string, c *Config) ([]string, error)
- func Format(c *Config) ([]byte, error)
- func Generate(c *Config) (map[string][]byte, error)
- func Script(t *Task) string
- func Write(root string, c *Config) ([]string, error)
- type Checkout
- type Concurrency
- type Config
- type Defaults
- type Dispatch
- type Filter
- type Input
- type Job
- type On
- type Pin
- type Request
- type Runner
- type Step
- type Task
- type Workflow
Constants ¶
const ( // File is the declaration, at the repository root. File = "yawn.json" // Dir holds the generated workflows. Dir = ".forgejo/workflows" // Marker starts every generated file. verify uses it to find stale files. Marker = "# Generated by yawn from yawn.json" // DefaultImage is the job container unless a job or the defaults say otherwise. DefaultImage = "code.yawn.dev/john/runner-images:ubuntu-24.04" // DefaultFallback is the runner label used when vars.CI_GENERAL_RUNNER is unset. DefaultFallback = "ci-linux" // DefaultTimeout is a job's timeout in minutes. DefaultTimeout = 30 // NoContainer as a job image runs the job directly on the runner host. NoContainer = "none" // SourcePin builds yawn from the checkout instead of installing a release // (only for john/cdk, where yawn itself lives). SourcePin = "source" // ReleaseBase serves yawn release binaries and their SHA256SUMS. ReleaseBase = "https://code.yawn.dev/john/cdk/releases/download" )
const ReleaseRef = "715ae71a91aeca3d53cc36dfa63c2f55bf1fd7f4"
ReleaseRef pins the john/release reusable workflows and actions that generated workflows call. john/release is public, so private repositories can call it. Bump it here, in one place, and regenerate.
Variables ¶
var ( // DigestPattern is a sha256 content digest. DigestPattern = regexp.MustCompile(`^sha256:[0-9a-f]{64}$`) // SlotPattern is a john/arch slot id. SlotPattern = regexp.MustCompile(`^[a-z][a-z0-9-]{0,62}$`) )
var Platforms = []string{"linux_amd64", "linux_arm64"}
Platforms are the release binaries a pin must name.
Functions ¶
func Drift ¶
Drift compares the generated workflows with the files under root. It reports files that differ, are missing, or carry the generated marker but are no longer declared. Hand-written workflows (no marker) are left alone.
Types ¶
type Checkout ¶
type Checkout struct {
Skip bool `json:"skip,omitempty"`
FetchDepth *int `json:"fetch_depth,omitempty"`
Ref string `json:"ref,omitempty"`
}
Checkout tunes the job's checkout step.
type Concurrency ¶
Concurrency is a workflow concurrency group.
type Config ¶
type Config struct {
Version int `json:"version"`
Yawn Pin `json:"yawn"`
Defaults Defaults `json:"defaults,omitzero"`
Tasks map[string]*Task `json:"tasks,omitempty"`
Workflows []*Workflow `json:"workflows"`
}
Config is the parsed yawn.json.
func Parse ¶
Parse validates a declaration. Unknown fields are refused, so a typo never silently drops a check.
type Defaults ¶
type Defaults struct {
Runner string `json:"runner,omitempty"` // fallback runner label
Image string `json:"image,omitempty"`
Timeout int `json:"timeout,omitempty"`
}
Defaults apply to every job that does not set its own value.
type Dispatch ¶
type Dispatch struct {
Inputs []Input `json:"inputs,omitempty"`
}
Dispatch is a manual (or API) trigger.
type Filter ¶
type Filter struct {
Branches []string `json:"branches,omitempty"`
Tags []string `json:"tags,omitempty"`
Paths []string `json:"paths,omitempty"`
}
Filter narrows a pull_request or push trigger.
type Input ¶
type Input struct {
ID string `json:"id"`
Description string `json:"description"`
Type string `json:"type"` // string, boolean or choice
Default string `json:"default,omitempty"`
Options []string `json:"options,omitempty"`
Required bool `json:"required,omitempty"`
}
Input is a workflow_dispatch input.
type Job ¶
type Job struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Task string `json:"task,omitempty"`
Uses string `json:"uses,omitempty"`
With map[string]string `json:"with,omitempty"`
Needs []string `json:"needs,omitempty"`
If string `json:"if,omitempty"`
Runner string `json:"runner,omitempty"` // runs-on, verbatim
Image string `json:"image,omitempty"`
Timeout int `json:"timeout,omitempty"`
Env map[string]string `json:"env,omitempty"`
Outputs map[string]string `json:"outputs,omitempty"`
Matrix map[string][]string `json:"matrix,omitempty"`
Checkout *Checkout `json:"checkout,omitempty"`
Setup []Step `json:"setup,omitempty"`
Steps []Step `json:"steps,omitempty"`
}
Job runs a task, calls a john/release built-in (Uses), or runs raw steps. A task job may add Setup steps (before yawn) and Steps (after the task).
type On ¶
type On struct {
PullRequest *Filter `json:"pull_request,omitempty"`
Push *Filter `json:"push,omitempty"`
Schedule []string `json:"schedule,omitempty"`
Dispatch *Dispatch `json:"workflow_dispatch,omitempty"`
}
On selects triggers. A present but empty filter means "every branch".
type Pin ¶
type Pin struct {
Version string `json:"version"`
SHA256 map[string]string `json:"sha256,omitempty"`
// Build, for Version "source": commands that leave the binary at
// $RUNNER_TEMP/yawn-bin/yawn.
Build []string `json:"build,omitempty"`
}
Pin selects the yawn that generated workflows install.
type Request ¶
type Request struct {
// XyopsURL is the xyOps base URL, e.g. https://ops.yawn.dev.
XyopsURL string
// Key is the magic-link key. It starts the event and grants nothing else.
Key string
// Audience is the ID token audience, e.g. yawn-attest:website.
Audience string
// Fields are extra event parameters (digest).
Fields map[string]string
// Result is the key under data that the event reports (attest, deploy).
Result string
Timeout time.Duration
// TokenURL / TokenAuth are ACTIONS_ID_TOKEN_REQUEST_URL / _TOKEN.
TokenURL, TokenAuth string
Client *http.Client
Out io.Writer
}
Request asks an xyOps event, through its magic link, to do something the runner cannot: sign a digest, deploy it, or plan/apply a stack. The runner sends only a Forgejo Actions ID token (audience names the slot and the action) and the digest; the event verifies everything else itself.
type Runner ¶
type Runner struct {
Root string
Stdout io.Writer
Stderr io.Writer
// DryRun prints each task's script instead of running it.
DryRun bool
// Only skips the named task's dependencies.
Only bool
}
Runner executes tasks. Stdout/Stderr receive the commands' output.
type Step ¶
type Step struct {
Name string `json:"name,omitempty"`
ID string `json:"id,omitempty"`
If string `json:"if,omitempty"`
Uses string `json:"uses,omitempty"`
With map[string]string `json:"with,omitempty"`
Run string `json:"run,omitempty"`
Yawn string `json:"yawn,omitempty"`
Shell string `json:"shell,omitempty"`
Dir string `json:"dir,omitempty"`
Env map[string]string `json:"env,omitempty"`
ContinueOnError bool `json:"continue_on_error,omitempty"`
}
Step is one raw step: exactly one of Uses, Run or Yawn (arguments to the pinned yawn). Uses accepts "release:NAME" (a john/release action at ReleaseRef) and "action:NAME" (a pinned third-party action).
type Task ¶
type Task struct {
Description string `json:"description,omitempty"`
Run []string `json:"run"`
Needs []string `json:"needs,omitempty"`
Dir string `json:"dir,omitempty"`
Env map[string]string `json:"env,omitempty"`
}
Task is a named shell script: its commands run in order in one `bash -euo pipefail` process, after the tasks it needs.
type Workflow ¶
type Workflow struct {
File string `json:"file"`
Name string `json:"name"`
Comment []string `json:"comment,omitempty"`
On On `json:"on"`
Concurrency *Concurrency `json:"concurrency,omitempty"`
OIDC bool `json:"oidc,omitempty"`
Jobs []*Job `json:"jobs"`
}
Workflow is one generated file.