scaffold

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 11 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 (
	ReleaseYMLPath     = ".github/workflows/release.yml"
	AutoReleaseYMLPath = ".github/workflows/auto-release.yml"
	RunbookPath        = ".abcd/development/release-gate/README.md"
)

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

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.

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"
	// 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 Rendered

type Rendered struct {
	ReleaseYML     []byte
	AutoReleaseYML []byte
	Runbook        []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 three 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:"-"`
	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.
	GoVersion string        `json:"go_version"`
	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"`
}

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, and the adr-37 runbook, each wired to the repo's own default branch. 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
}

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
}

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 alone, a generic build, and no host-run semantic gate (spc-14 clean degradation). 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.

Jump to

Keyboard shortcuts

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