scaffold

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 13 Imported by: 0 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 scaffold renders and writes the changelog-driven release machinery — release.yml, auto-release.yml, and the adr-37 runbook — into a managed repo that lacks it (itd-93, spc-14).

Self-scaffold parity (one template, one artifact)

The three files ship as embedded templates. abcd-cli's OWN release workflows are regenerated from these same templates with the abcd fact set (AbcdSubstitutions): TestSelfScaffoldParity asserts the rendered output is byte-identical to the committed .github/workflows/*.yml, so the proven pattern and the shipped template can never drift — every abcd release exercises the exact machinery a managed repo receives.

A bare managed repo passes a degraded fact set (BareSubstitutions): no semantic detectors, a generic Go build, and only the deterministic verify gates. The template's abcd-specific regions are guarded so the bare rendering omits them cleanly and still parses, arms GITHUB_TOKEN-only, and injects nothing.

Why custom template delimiters

A GitHub Actions workflow is dense with `${{ … }}` expressions, which collide with text/template's default `{{ … }}`. The templates therefore use `<%` / `%>` (which never appear in a workflow) as delimiters, so every `${{ … }}` passes through as literal text and only the scaffold's own directives are evaluated.

Index

Constants

View Source
const (
	// GateWorkflowName is the gate workflow's file name.
	GateWorkflowName = "abcd-release-gate.yml"
	// GateWorkflowPath is where the gate workflow is written.
	GateWorkflowPath = ".github/workflows/" + GateWorkflowName
	// ChangelogPath is the release record the changelog-driven path reads.
	ChangelogPath = "CHANGELOG.md"
	// ChangelogAnchor is the changelog a repository with none receives: the
	// empty [Unreleased] anchor and nothing else (decision 7). History before
	// adoption is not represented.
	ChangelogAnchor = "# Changelog\n\n## [Unreleased]\n"
)

The non-plugin kind's files.

View Source
const (
	ReleaseYMLPath     = ".github/workflows/release.yml"
	AutoReleaseYMLPath = ".github/workflows/auto-release.yml"
	RunbookPath        = ".abcd/development/release-gate/README.md"
	// CheckReviewsPath is the scaffolded reviews-charter check (RD001, with the
	// sha-keyed receipt directories exempt). It sits beside the runbook, in the
	// release-gate directory the scaffold already owns, rather than in a scripts
	// directory the managed repository may lay out its own way.
	CheckReviewsPath = ".abcd/development/release-gate/check-reviews.sh"
	// ReauthorYMLPath is the dependency-bump re-authoring workflow.
	ReauthorYMLPath = ".github/workflows/dependency-reauthor.yml"
	// ReauthorScriptPath is its script in a managed repository, beside the
	// reviews-charter check; AbcdReauthorScriptPath is abcd's own copy.
	ReauthorScriptPath     = ".abcd/development/release-gate/dependency-reauthor.sh"
	AbcdReauthorScriptPath = "scripts/dependency-reauthor.sh"
	// ReauthorConfPath is the declaration: its presence is the repository's
	// opt-in, and its owner and ecosystem rows are the repository's to set.
	ReauthorConfPath = ".abcd/config/dependency-reauthor.conf"
)

Repo-relative destinations the scaffold writes. Fixed by the GitHub Actions discovery rule (workflows) and mirrored from abcd-cli's own layout (runbook).

Variables

View Source
var ErrScaffoldBlocked = errors.New("scaffold refused: an existing file was hand-edited (pass --confirm to overwrite)")

ErrScaffoldBlocked is returned when a scaffold run refuses because an existing file differs from the machinery and --confirm was not given.

Functions

func AuditProfiles added in v0.12.0

func AuditProfiles() map[string]Substitutions

AuditProfiles is every profile the scaffold's templates render, by name, each with a fact set that exercises its guarded regions: abcd's own, a bare managed repository with and without derived CI checks and semantic gates, and the gate profile with and without an own release workflow. The in-repo workflow audit (TestScaffoldedWorkflowsPassTheWorkflowAudit) and CI's zizmor audit of the rendered profiles (cmd/scaffold-render, iss-2609251939472371) read this one set, so neither can audit a profile the other does not.

func DeriveCIChecks added in v0.11.0

func DeriveCIChecks(repoRoot string) []string

DeriveCIChecks reads repoRoot's own CI workflows and returns the check names its pull requests report, sorted and de-duplicated. Only workflows triggered by `pull_request`, `pull_request_target` or `merge_group` gate a merge, and the scaffold's own workflows (the release pair and the dependency re-authoring) are never counted. An unreadable or absent workflows directory yields nil: the runbook then says no merge gate was found.

func DeriveRepoFacts

func DeriveRepoFacts(repoRoot string) (branch, goVersion string)

DeriveRepoFacts reads the target repo's own default branch and Go version, both validated against an injection-safe allowlist. Anything malformed or absent falls back to a safe default, so a hostile ref name can never inject workflow content.

Only the branch reaches the rendered YAML. The Go version is reported to the adopter — it is the toolchain their scaffolded workflows will resolve, since those point setup-go at go.mod — and is validated on the same terms anyway, because a report line is a place a hostile go.mod could otherwise write.

func SafeBranchName added in v0.11.1

func SafeBranchName(name string) bool

SafeBranchName reports whether name is a default-branch name the rendered workflows may carry: the allowlist deriveBranch holds a local ref to, for a name read from elsewhere (the forge).

func SyncRepoPins

func SyncRepoPins(repoRoot string, write bool) ([]string, error)

SyncRepoPins propagates the action pins in the committed workflows into the templates they were rendered from. It returns the repo-relative paths of the templates that differ, newest state applied only when write is true.

With write=false it is a pure report and touches nothing — the mode CI uses to decide whether a dependabot bump needs a follow-up commit, and the mode a contributor's test run uses to fail loudly rather than silently rewriting a tracked file underneath them.

func WriteAuditProfiles added in v0.12.0

func WriteAuditProfiles(dir string) ([]string, error)

WriteAuditProfiles renders every AuditProfiles profile and writes its workflows under dir/<profile>/.github/workflows/, the layout a workflow auditor discovers, returning the files written in a stable order. dir is a scratch directory the caller owns; nothing outside it is written. The opt-in dependency-reauthor workflow is written with them, so zizmor audits the rendering a managed repository receives when it opts in.

Types

type FileOutcome

type FileOutcome struct {
	Path   string     `json:"path"`
	Status FileStatus `json:"status"`
	// Detail explains a refusal (why the file was left alone).
	Detail string `json:"detail,omitempty"`
}

FileOutcome is the per-file result of a scaffold run.

func WriteFiles added in v0.11.1

func WriteFiles(repoRoot string, planned []PlannedFile, confirm bool) (outcomes []FileOutcome, wrote, refused int, err error)

WriteFiles is the scaffold's writer, shared with every verb that lays machinery into a managed repository (`abcd site setup` is the second). It is idempotent and fail-safe:

  • a file absent on disk is written;
  • a file byte-identical to the planned bytes is a no-op (StatusCurrent);
  • a machinery file that exists and DIFFERS is REFUSED and left untouched unless confirm is set, in which case it is overwritten;
  • a seed file that exists is kept (StatusKept) whatever it holds.

A run that refuses any file writes NOTHING and returns ErrScaffoldBlocked with the outcomes, so the caller can render exactly what was and was not touched — no partial half-write.

type FileStatus

type FileStatus string

FileStatus is one scaffolded file's disposition in the report. Every value means what it says on disk: "written" is written, never merely planned.

const (
	// StatusWritten — the file was actually written (created, or overwritten under
	// confirm). Only set AFTER the write succeeds.
	StatusWritten FileStatus = "written"
	// StatusCurrent — the file already matches the machinery; nothing was written.
	StatusCurrent FileStatus = "current"
	// StatusRefused — the file exists and differs, and --confirm was not given, so
	// it was left untouched.
	StatusRefused FileStatus = "refused"
	// StatusKept — a file that belongs to the repository, not to abcd, left
	// exactly as it is: a seed file (PlannedFile.Seed) that already exists, or a
	// file the run never opened — an existing CHANGELOG.md, or the repository's
	// own release workflow beside the gate. Detail says why it was left alone.
	StatusKept FileStatus = "kept"
	// StatusSkipped — the file WOULD have been written, but the run refused (a
	// sibling was hand-edited) or a write faulted first, so it was NOT written. The
	// scaffold is all-or-nothing, so this reports honestly that nothing landed.
	StatusSkipped FileStatus = "skipped"
)

type Gate

type Gate struct {
	Name string
	Run  string
}

Gate is one named verify-job step: a display name and the shell it runs. The deterministic gates a managed repo inherits beyond the generic Go leg are expressed as data so the runbook's numbered list and the workflow's steps are rendered from one source (the gate_lockstep invariant, in-template).

type PlannedFile added in v0.11.1

type PlannedFile struct {
	Path string
	Data []byte
	// Seed marks a file the repository owns once it exists: written when
	// absent, and otherwise left exactly as it is (StatusKept), never refused
	// and never overwritten, --confirm or not. Machinery is the opposite: abcd
	// owns its bytes, so a copy that differs is refused or, confirmed, replaced.
	Seed bool
}

PlannedFile is one file a WriteFiles run places, at a slash-separated repo-relative Path.

type Rendered

type Rendered struct {
	ReleaseYML     []byte
	AutoReleaseYML []byte
	Runbook        []byte
	// CheckReviews is the reviews-charter check (RD001) the bare verify job runs.
	CheckReviews []byte
	// ReauthorYML, ReauthorScript and ReauthorConf are the opt-in
	// dependency-bump re-authoring (itd-2609221842494980): the workflow, the
	// bound-and-push script it runs, and the declaration a repository seeds
	// once and then owns.
	ReauthorYML    []byte
	ReauthorScript []byte
	ReauthorConf   []byte
}

Rendered is the file set a scaffold run produces, keyed by repo-relative path.

func Render

func Render(subs Substitutions) (Rendered, error)

Render binds the templates against subs and returns their bytes. A template parse or execute fault is a programming error in the embedded templates, surfaced as an error rather than a panic.

type Report

type Report struct {
	Substitutions Substitutions `json:"-"`
	// Kind is the declared artefact kind the file set was chosen by.
	Kind launch.ArtefactKind `json:"kind"`
	// CallStanza is what to add to the repository's own release workflow to
	// call the gate; present only when such a workflow was left alone.
	CallStanza    string `json:"call_stanza,omitempty"`
	DefaultBranch string `json:"default_branch"`
	// GoVersion is what the scaffolded workflows will RESOLVE, not a value written
	// into them: they point setup-go at go.mod, so this reports the go directive
	// the run read. It is reported because an adopter should see which toolchain
	// their release lane is about to use, and see it before the first tag.
	// Empty, and absent from the JSON, for a repository with no go.mod: there is
	// no toolchain its release resolves, so none is named.
	GoVersion string `json:"go_version,omitempty"`
	// CIChecks are the managed repo's own pull-request check names the
	// scaffolded files were wired to (DeriveCIChecks); empty when none was found.
	CIChecks []string      `json:"ci_checks"`
	Files    []FileOutcome `json:"files"`
	Wrote    int           `json:"wrote"`
	Refused  int           `json:"refused"`
	// NoOp is true when every file was already current (the idempotent re-run).
	NoOp bool `json:"no_op"`
	// DependencyReauthor reports whether the repository is opted in to the
	// dependency-bump re-authoring, by the flag or by its declaration.
	DependencyReauthor bool `json:"dependency_reauthor"`
}

Report is the outcome of a scaffold run.

func Scaffold

func Scaffold(req Request) (Report, error)

Scaffold writes the changelog-driven release machinery into RepoRoot: a generic (bare-repo) release.yml, auto-release.yml, the adr-37 runbook and the reviews-charter check, wired to the repo's own default branch and to the check names its own pull-request CI reports. The Go toolchain is not wired in: the workflows point setup-go at the repo's go.mod, so they follow its go directive with no re-scaffold. It is idempotent and fail-safe:

  • a file absent on disk is written;
  • a file byte-identical to the machinery is a no-op (StatusCurrent);
  • a file that exists and DIFFERS (hand-edited, or a stale scaffold) is REFUSED and left untouched unless Confirm is set, in which case it is overwritten.

A run that refuses any file returns ErrScaffoldBlocked with the report, so the caller can render exactly what was and was not touched — no partial half-write.

type Request

type Request struct {
	RepoRoot string
	// Confirm overwrites a file that exists and differs from the machinery (the
	// transparent-confirm on a hand-edited workflow). Absent, such a file is
	// refused and left untouched, and the run reports ErrScaffoldBlocked.
	Confirm bool
	// DependencyReauthor opts the repository in to the dependency-bump
	// re-authoring (itd-2609221842494980): the run seeds the declaration at
	// ReauthorConfPath when it is absent. A repository whose declaration exists
	// is opted in whether or not this is set, so a later plain run keeps the
	// workflow current; one with neither receives none of it.
	DependencyReauthor bool
}

Request is the input to a scaffold run.

type Substitutions

type Substitutions struct {
	// DefaultBranch is the branch auto-release triggers on and the no-branch-commit
	// tripwire guards — derived from the target repo, never hard-coded.
	DefaultBranch string
	// (There is deliberately no Go version here. The rendered workflows point
	// setup-go at go.mod with `go-version-file`, so the go directive is the only
	// place the toolchain is written — see the field's removal in
	// iss-2609090951291799. A substituted literal was a scaffold-time snapshot of
	// that directive, which went stale the moment the adopter bumped it, and it
	// was a value derived from a file that had to be validated against an
	// injection-safe allowlist before it could be written into YAML.)
	//
	// Abcd selects abcd-cli's full rendering: the extra deterministic verify gates,
	// the semantic release gate, and the four-binary cross-compile + attest build.
	// A bare managed repo sets it false and gets a generic Go build with no semantic
	// detectors.
	Abcd bool
	// ExtraGates are the deterministic verify steps beyond the generic Go leg
	// (gofmt/build/vet/test/race). Rendered into both the workflow's verify job and
	// the runbook's numbered gate list, so the two stay in lockstep by construction.
	ExtraGates []Gate
	// SemanticGates are the required host-run detectors the release gate arms
	// (`--require-gate <name>`). Empty means no semantic detector is configured and
	// the deterministic gates alone admit the release (spc-14 clean degradation).
	SemanticGates []string
	// ReleaseWorkflow is the file name of the workflow that verifies, tags and
	// publishes — release.yml for a plugin, abcd-release-gate.yml for any other
	// artefact kind — so auto-release calls it, the runbook names it and a
	// receipt attestation names it as its signer by the name it has.
	ReleaseWorkflow string
	// Gate renders the release template as the gate workflow a non-plugin kind
	// receives (itd-2609150819432059, decisions 5 and 6): no tag-push trigger of
	// its own, so it never races a repository's own tag-driven workflow, and a
	// `publish` input its caller turns off when it builds and publishes itself.
	Gate bool
	// OwnReleaseWorkflow is the repository's own release workflow, repo-relative,
	// when it has one; the runbook then describes the gate as called from it.
	OwnReleaseWorkflow string
	// GoModule reports that the repository is a Go module (it carries a go.mod).
	// The verify job's Go leg — setup-go, gofmt, build, vet, test and the race
	// leg — and the rehearsal's build render only for one: a repository that is
	// not a Go module would fail setup-go on the go.mod it does not have.
	GoModule bool
	// CallStanza is what a repository whose own release workflow stays in
	// charge adds to it to call the gate; the runbook carries it, and the
	// scaffold report prints it.
	CallStanza string
	// CIChecks are the check names the managed repo's own pull-request CI
	// reports (DeriveCIChecks): the merge gate the release roll passes through.
	// The bare rendering names them in release.yml's verify header and lists them
	// in the runbook as the contexts to require on DefaultBranch. Each is held to
	// an injection-safe allowlist before it gets here. abcd's own rendering
	// leaves this empty; its merge gate is ci.yml, described in its own runbook.
	CIChecks []string
}

Substitutions is the fact set a rendering binds against. AbcdSubstitutions reproduces abcd-cli's live workflows byte-for-byte; BareSubstitutions degrades to the deterministic gates alone.

func AbcdSubstitutions

func AbcdSubstitutions() Substitutions

AbcdSubstitutions is abcd-cli's own fact set: the fixed inputs that regenerate its live release.yml / auto-release.yml byte-for-byte (self-scaffold parity, spc-14 decision b). It is deliberately hard-coded, not derived — it is the reference rendering the parity test pins, and deriving it would let the pin track the derivation rather than the proven workflow.

func BareSubstitutions

func BareSubstitutions(defaultBranch string) Substitutions

BareSubstitutions is the degraded fact set a managed repo with no semantic detectors receives: the deterministic Go gates and the reviews-charter shape, a generic build, and no host-run semantic gate (spc-14 clean degradation). CIChecks is the caller's to set from DeriveCIChecks. DefaultBranch is the repo's own fact, derived by the caller; the Go toolchain is not a substitution at all, because the rendered workflows read it out of the adopter's go.mod.

func GateSubstitutions added in v0.11.1

func GateSubstitutions(defaultBranch, own string) Substitutions

GateSubstitutions is the fact set a non-plugin kind's gate renders with: the bare profile rendered as the gate workflow. own names the repository's own release workflow when it has one, which the runbook then describes as the gate's caller.

func (Substitutions) ExtraBase added in v0.11.1

func (s Substitutions) ExtraBase() int

ExtraBase is the number the runbook gives the first extra gate: it follows the five Go gates when the repository is a Go module, and leads otherwise.

func (Substitutions) ReauthorScript added in v0.12.0

func (s Substitutions) ReauthorScript() string

ReauthorScript is where the dependency-reauthor workflow finds its script: abcd keeps its shell gates under scripts/, and a managed repository receives it beside the runbook, in the release-gate directory the scaffold already owns.

Jump to

Keyboard shortcuts

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