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) use the shared release manifest action; xyOps 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 Synthesize(root string, check bool, config Config, docs ...Document) error
- func Write(root string, c *Config) ([]string, error)
- type Checkout
- type Concurrency
- type Config
- type Defaults
- type Dispatch
- type Document
- type Filter
- type Input
- type Job
- type On
- type Pin
- 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 = "c9c4324606cebfccf8c2074ed2f0b809b34fac9d"
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.
const ReviewRef = "88759cc604ee17cf62d9c3fa1d1f9d2a56100aaf"
ReviewRef pins the shared read-only analyzer and trusted posting workflow.
const SubmitReleaseRef = "e3b07de98a1274c645a0c07bb2df600b962e7410"
releaseActions are the john/release actions a step may name as "release:NAME". Pin the independent transport action without rotating every existing release action.
const SubmitSigningRef = "fc11b5c2c280d16005e3d6c2625b643fbb6444e5"
Variables ¶
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.
func Synthesize ¶
Synthesize projects a repo's yawn/ Go app into Forgejo workflows, the task index for old yawn runners, and release declarations. Check mode never writes. The privileged deployer independently validates the generated declarations.
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 {
// GoSource identifies generated task metadata whose source is the Go app.
GoSource bool `json:"go_source,omitempty"`
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 {
Types []string `json:"types,omitempty"`
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"`
Secrets map[string]string `json:"secrets,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).
func ChangeImpactJob ¶
func ChangeImpactJob() *Job
ChangeImpactJob is a closed template: no PR checkout, arbitrary commands, environment, alternate runner/image, additional secrets or OIDC.
type On ¶
type On struct {
PullRequestTarget *Filter `json:"pull_request_target,omitempty"`
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 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.