ci

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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"
)
View Source
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.

View Source
const ReviewRef = "88759cc604ee17cf62d9c3fa1d1f9d2a56100aaf"

ReviewRef pins the shared read-only analyzer and trusted posting workflow.

View Source
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.

View Source
const SubmitSigningRef = "fc11b5c2c280d16005e3d6c2625b643fbb6444e5"

Variables

View Source
var Platforms = []string{"linux_amd64", "linux_arm64"}

Platforms are the release binaries a pin must name.

Functions

func Drift

func Drift(root string, c *Config) ([]string, error)

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 Format

func Format(c *Config) ([]byte, error)

Format renders c as yawn.json (two-space indent, no HTML escaping).

func Generate

func Generate(c *Config) (map[string][]byte, error)

Generate renders every declared workflow: file name -> contents.

func Script

func Script(t *Task) string

Script is the shell a task runs: its commands, one per line.

func Synthesize

func Synthesize(root string, check bool, config Config, docs ...Document) error

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.

func Write

func Write(root string, c *Config) ([]string, error)

Write generates every workflow into root/.forgejo/workflows and removes generated files that are no longer declared. It returns the changed paths.

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

type Concurrency struct {
	Group  string `json:"group"`
	Cancel bool   `json:"cancel_in_progress"`
}

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 Load

func Load(root string) (*Config, error)

Load reads and validates root/yawn.json.

func Parse

func Parse(data []byte) (*Config, error)

Parse validates a declaration. Unknown fields are refused, so a typo never silently drops a check.

func (*Config) Plan

func (c *Config) Plan(names ...string) ([]string, error)

Plan returns the named tasks and everything they need, each once, every dependency before its dependents. It refuses unknown tasks and cycles.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the whole declaration and reports every problem at once.

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 Document

type Document struct {
	Path  string
	Value any
}

Document is a data-only release declaration, validated separately by its owner.

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.

func (Runner) Run

func (r Runner) Run(ctx context.Context, c *Config, names ...string) error

Run runs the named tasks and their dependencies, each once, in order. Every task is one `bash -euo pipefail` script started in its directory, so a failing command fails the task and later commands do not run.

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.

Jump to

Keyboard shortcuts

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