ci: a merge to main is the public release; every dev push dry-runs it (#8358)
release / web (push) Successful in 1m29s
release / go (push) Successful in 1m54s
release / govulncheck (push) Successful in 18s
release / integration (push) Successful in 2m44s
release / android (push) Successful in 2m9s
release / Build signed APK (push) Successful in 2m1s
release / Build + push container image (push) Failing after 4s
release / web (push) Successful in 1m29s
release / go (push) Successful in 1m54s
release / govulncheck (push) Successful in 18s
release / integration (push) Successful in 2m44s
release / android (push) Successful in 2m9s
release / Build signed APK (push) Successful in 2m1s
release / Build + push container image (push) Failing after 4s
Every push now builds its image from the git archive export, after the changelog and the leak gate have run on it, so a dev push is the public release's dry run. A push to main then also commits and tags the export on github.com/Fabled-Sword/minstrel as AmateurDungeoneer, publishes ghcr.io/fabled-sword/minstrel :<name> and :latest, and creates the release page on GitHub (public changelog) and on this forge (private changelog). The scripts are Librarian's (ci/changelog.sh, ci/leakgate.sh, ci/releases.mjs, with their tests), with Minstrel's false positives and a changelog that ignores the forge-only v* tags from before the public releases, so the first public release is the fixed note. The tag build, its APK attach and its verify job, and the manual GHCR dispatch are gone: phones get the app from the server image, and no release carries a file. The push trigger has no path filter, because the README, docs and tests ship in the public release too. The README's image tags now name what GHCR carries: :latest and :<version>. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -24,15 +25,14 @@ import (
|
||||
// require its success by name.
|
||||
var gateLanes = []string{"go", "integration", "web", "android", "govulncheck"}
|
||||
|
||||
// gatePublishers push something other people can pull: image tags (the
|
||||
// private channels, and the public release image on GHCR), and the APK +
|
||||
// sidecar attached to a Release.
|
||||
var gatePublishers = []string{"image-release", "release-assets", "ghcr-release"}
|
||||
// gatePublishers push something other people can pull: image-release pushes
|
||||
// the private channels and, on main, the whole public release.
|
||||
var gatePublishers = []string{"image-release"}
|
||||
|
||||
// gateOthers are the remaining jobs and why they sit outside the gate:
|
||||
// android-release only builds a workflow artifact (nothing outside the run can
|
||||
// pull it), and verify-release reports on a finished release.
|
||||
var gateOthers = []string{"android-release", "verify-release"}
|
||||
// pull it).
|
||||
var gateOthers = []string{"android-release"}
|
||||
|
||||
type workflowJob struct {
|
||||
Needs any `yaml:"needs"`
|
||||
@@ -120,47 +120,66 @@ func TestReleaseGate_PublishersNeedEveryLaneToSucceed(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The public release image has four properties a later edit could quietly
|
||||
// lose, each of which still builds and pushes a valid image:
|
||||
// - it runs only on a dispatch that asks for it, never on a push to dev;
|
||||
// - a GHCR dispatch moves no private channel;
|
||||
// - it builds from the `git archive` export, so export-ignored files never
|
||||
// reach its build context;
|
||||
// - it carries no provenance attestation, and its source label names the
|
||||
// public repo rather than this workbench.
|
||||
func TestGHCRRelease_OnlyOnRequestFromTheExportAndNamingThePublicRepo(t *testing.T) {
|
||||
jobs := releaseJobs(t)
|
||||
ghcr := strings.Join(strings.Fields(jobs["ghcr-release"].If), " ")
|
||||
for _, want := range []string{"github.event_name == 'workflow_dispatch'", "github.event.inputs.ghcr_release == 'true'"} {
|
||||
if !strings.Contains(ghcr, want) {
|
||||
t.Errorf("ghcr-release's if lacks %s, so it could run on a push\n if: %s", want, ghcr)
|
||||
}
|
||||
}
|
||||
private := strings.Join(strings.Fields(jobs["image-release"].If), " ")
|
||||
if !strings.Contains(private, "github.event.inputs.ghcr_release != 'true'") {
|
||||
t.Errorf("image-release does not stand aside on a GHCR dispatch, so a release would also move a private channel\n if: %s", private)
|
||||
}
|
||||
|
||||
// The public release has properties a later edit could quietly lose, each of
|
||||
// which still builds and pushes a valid release:
|
||||
// - only a push to main makes it, never a dev push or a dispatch;
|
||||
// - every image is built from the `git archive` export, so export-ignored
|
||||
// files never reach a build context, and the export and the public
|
||||
// changelog pass the leak gate before anything is built or pushed;
|
||||
// - the public image carries no provenance attestation, and its labels name
|
||||
// the public repository and commit rather than this workbench;
|
||||
// - the public commit is the family's public identity, dated in UTC.
|
||||
func TestPublicRelease_OnlyFromAMainPushBuiltFromTheGatedExport(t *testing.T) {
|
||||
yaml := releaseYAML(t)
|
||||
i := strings.Index(yaml, "\n ghcr-release:")
|
||||
i := strings.Index(yaml, "\n image-release:")
|
||||
if i < 0 {
|
||||
t.Fatal("no ghcr-release job")
|
||||
t.Fatal("no image-release job")
|
||||
}
|
||||
job := yaml[i:]
|
||||
if j := jobBoundary.FindStringIndex(job[1:]); j != nil {
|
||||
job = job[:j[0]+1]
|
||||
|
||||
tags := stepBody(t, job, "Compute image tags")
|
||||
public := regexp.MustCompile(`if \[ "\$\{GITHUB_EVENT_NAME\}" = "push" \] && \[ "\$\{GITHUB_REF\}" = "refs/heads/main" \]; then\s+echo "PUBLIC=true"\s+else\s+echo "PUBLIC=false"`)
|
||||
if !public.MatchString(tags) {
|
||||
t.Errorf("PUBLIC is not true for a push to main alone, so another run could publish the release\n%s", tags)
|
||||
}
|
||||
export := stepBody(t, job, "Export the public tree and match it to the public tag")
|
||||
if !strings.Contains(export, "git archive HEAD") {
|
||||
t.Errorf("the export step does not use git archive, so export-ignored files could reach the image\n%s", export)
|
||||
}
|
||||
build := stepBody(t, job, "Build the release image from the export")
|
||||
for _, want := range []string{"--provenance=false", `"${EXPORT}"`, "org.opencontainers.image.source=\"${PUBLIC_REPO}\""} {
|
||||
if !strings.Contains(build, want) {
|
||||
t.Errorf("the release image build lacks %s\n%s", want, build)
|
||||
for _, step := range []string{"Public commit and tag", "Public image", "Public and private releases"} {
|
||||
if !strings.Contains(stepBody(t, job, step), "if: env.PUBLIC == 'true'") {
|
||||
t.Errorf("%q does not wait for PUBLIC, so a dev push would publish it", step)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(job, "PUBLIC_REPO: https://github.com/Fabled-Sword/minstrel") {
|
||||
t.Error("ghcr-release's PUBLIC_REPO is not the public GitHub repo, so the image's source label points elsewhere")
|
||||
|
||||
export := stepBody(t, job, "Export, changelog and leak gate")
|
||||
for _, want := range []string{"git archive HEAD", "ci/changelog.sh", `ci/leakgate.sh "${EXPORT}" "${RUNNER_TEMP}/changelog/public.md"`} {
|
||||
if !strings.Contains(export, want) {
|
||||
t.Errorf("the export step lacks %s\n%s", want, export)
|
||||
}
|
||||
}
|
||||
gate := strings.Index(job, "- name: Export, changelog and leak gate")
|
||||
for _, step := range []string{"Build and push", "Public commit and tag"} {
|
||||
if at := strings.Index(job, "- name: "+step); at < gate {
|
||||
t.Errorf("%q runs before the leak gate, so a leak could be pushed before it is caught", step)
|
||||
}
|
||||
}
|
||||
for _, step := range []string{"Build and push", "Public image"} {
|
||||
if !strings.Contains(stepBody(t, job, step), `"${EXPORT}"`) {
|
||||
t.Errorf("%q does not build from the export, so export-ignored files reach its image", step)
|
||||
}
|
||||
}
|
||||
|
||||
image := stepBody(t, job, "Public image")
|
||||
for _, want := range []string{"--provenance=false", "org.opencontainers.image.source=https://github.com/${PUBLIC_REPO}", "org.opencontainers.image.revision=${REVISION}"} {
|
||||
if !strings.Contains(image, want) {
|
||||
t.Errorf("the public image build lacks %s\n%s", want, image)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(job, "PUBLIC_REPO: Fabled-Sword/minstrel") {
|
||||
t.Error("PUBLIC_REPO is not the public GitHub repository, so the release and its labels point elsewhere")
|
||||
}
|
||||
|
||||
commit := stepBody(t, job, "Public commit and tag")
|
||||
for _, want := range []string{"GIT_AUTHOR_EMAIL=amateurdungeoneer@fabledsword.com", "GIT_COMMITTER_EMAIL=amateurdungeoneer@fabledsword.com", "+0000", "git add -A -f"} {
|
||||
if !strings.Contains(commit, want) {
|
||||
t.Errorf("the public commit lacks %s\n%s", want, commit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,20 +220,18 @@ func releaseYAML(t *testing.T) string {
|
||||
return string(body)
|
||||
}
|
||||
|
||||
// imageTagArms splits "Compute image tags" into its three ref branches. The
|
||||
// whole tag policy lives in that if/elif/else, so the arms are the unit worth
|
||||
// asserting on — a tag published from the wrong arm reaches the wrong
|
||||
// imageTagArms splits "Compute image tags" into its two ref branches. The
|
||||
// whole private tag policy lives in that if/else, so the arms are the unit
|
||||
// worth asserting on — a tag published from the wrong arm reaches the wrong
|
||||
// audience, and every such mistake still builds and still pushes a valid
|
||||
// image.
|
||||
func imageTagArms(t *testing.T, yaml string) (tagArm, devArm, mainArm string) {
|
||||
func imageTagArms(t *testing.T, yaml string) (devArm, mainArm string) {
|
||||
t.Helper()
|
||||
const (
|
||||
tagMarker = `if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then`
|
||||
devMarker = `elif [[ "${GITHUB_REF}" == "refs/heads/dev" ]]; then`
|
||||
devMarker = `if [[ "${GITHUB_REF}" == "refs/heads/dev" ]]; then`
|
||||
mainMarker = "\n else"
|
||||
endMarker = "\n fi"
|
||||
)
|
||||
iTag := strings.Index(yaml, tagMarker)
|
||||
iDev := strings.Index(yaml, devMarker)
|
||||
iMain := -1
|
||||
if iDev >= 0 {
|
||||
@@ -241,8 +239,8 @@ func imageTagArms(t *testing.T, yaml string) (tagArm, devArm, mainArm string) {
|
||||
iMain = iDev + k
|
||||
}
|
||||
}
|
||||
if iTag < 0 || iDev < 0 || iMain < 0 {
|
||||
t.Fatal("Compute image tags no longer has a tag/dev/main arm — the tag policy has been restructured, so these guards are pinning nothing")
|
||||
if iDev < 0 || iMain < 0 {
|
||||
t.Fatal("Compute image tags no longer has a dev/main arm — the tag policy has been restructured, so these guards are pinning nothing")
|
||||
}
|
||||
iEnd := iMain
|
||||
if k := strings.Index(yaml[iMain:], endMarker); k >= 0 {
|
||||
@@ -250,7 +248,7 @@ func imageTagArms(t *testing.T, yaml string) (tagArm, devArm, mainArm string) {
|
||||
} else {
|
||||
t.Fatal("no closing fi after the main arm")
|
||||
}
|
||||
return yaml[iTag:iDev], yaml[iDev:iMain], yaml[iMain:iEnd]
|
||||
return yaml[iDev:iMain], yaml[iMain:iEnd]
|
||||
}
|
||||
|
||||
// The worst regression this wiring can produce: a dev push that also moves
|
||||
@@ -258,7 +256,7 @@ func imageTagArms(t *testing.T, yaml string) (tagArm, devArm, mainArm string) {
|
||||
// next pull. Nothing else in the suite would notice — the build stays green
|
||||
// and the image is valid, it is simply the wrong audience.
|
||||
func TestDevChannel_PublishesDevAloneAndNeverLatest(t *testing.T) {
|
||||
_, arm, _ := imageTagArms(t, releaseYAML(t))
|
||||
arm, _ := imageTagArms(t, releaseYAML(t))
|
||||
|
||||
if !strings.Contains(arm, "${IMAGE}:dev") {
|
||||
t.Errorf("dev arm does not publish :dev\n%s", arm)
|
||||
@@ -274,14 +272,14 @@ func TestDevChannel_PublishesDevAloneAndNeverLatest(t *testing.T) {
|
||||
|
||||
// A merge to main is enough to put a new app in front of stable phones: main
|
||||
// builds the signed APK from its own commit and bakes it into :latest, as dev
|
||||
// does for :dev. The regression to guard is main falling back to a tag-only
|
||||
// APK build, which leaves every merged app change waiting on a release while
|
||||
// each build stays green.
|
||||
// does for :dev. The regression to guard is main falling back to an APK built
|
||||
// somewhere else, which leaves every merged app change waiting while each build
|
||||
// stays green.
|
||||
func TestEveryBranchShipsTheAppBuiltFromItsOwnCommit(t *testing.T) {
|
||||
jobs := releaseJobs(t)
|
||||
|
||||
build := strings.Join(strings.Fields(jobs["android-release"].If), " ")
|
||||
for _, ref := range []string{"refs/heads/main", "refs/heads/dev", "refs/tags/v"} {
|
||||
for _, ref := range []string{"refs/heads/main", "refs/heads/dev"} {
|
||||
if !strings.Contains(build, ref) {
|
||||
t.Errorf("android-release does not build on %s, so that ref's image carries no app of its own\n if: %s", ref, build)
|
||||
}
|
||||
@@ -297,8 +295,7 @@ func TestEveryBranchShipsTheAppBuiltFromItsOwnCommit(t *testing.T) {
|
||||
t.Error("release.yml fetches the latest release; an image bundling a release's APK ships an app older than its own commit")
|
||||
}
|
||||
|
||||
// Both bundling steps run on every ref. Sliced from image-release on,
|
||||
// because release-assets has a step of the same name.
|
||||
// Both bundling steps run on every ref.
|
||||
i := strings.Index(yaml, "\n image-release:")
|
||||
if i < 0 {
|
||||
t.Fatal("no image-release job")
|
||||
@@ -319,7 +316,7 @@ func TestEveryBranchShipsTheAppBuiltFromItsOwnCommit(t *testing.T) {
|
||||
//
|
||||
// Rules 145 and 147: main push → :latest + :<sha>.
|
||||
func TestMainChannel_PublishesLatestAndTheRollbackUnit(t *testing.T) {
|
||||
_, _, arm := imageTagArms(t, releaseYAML(t))
|
||||
_, arm := imageTagArms(t, releaseYAML(t))
|
||||
|
||||
if !strings.Contains(arm, "${IMAGE}:latest") {
|
||||
t.Errorf("main arm does not move :latest — production would stop tracking main's tip\n%s", arm)
|
||||
@@ -334,38 +331,21 @@ func TestMainChannel_PublishesLatestAndTheRollbackUnit(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A release refreshes the CHANNEL and mints nothing else.
|
||||
// No version-numbered PRIVATE image tags, on either arm: the build's version
|
||||
// is self-reported, and the private tag map is :latest, :<sha> and :dev. (The
|
||||
// public image on GHCR is the one that carries the release's name.)
|
||||
//
|
||||
// The regression to guard: a :<sha> tag here. The tag build rebuilds the SAME
|
||||
// SOURCE as main's build minutes earlier, differing only in which APK is baked
|
||||
// in — so a :<sha> minted here would overwrite main's immutable rollback
|
||||
// target with different contents, under the same name.
|
||||
func TestReleaseBuild_RefreshesTheChannelAndMintsNothingElse(t *testing.T) {
|
||||
arm, _, _ := imageTagArms(t, releaseYAML(t))
|
||||
|
||||
if !strings.Contains(arm, "${IMAGE}:latest") {
|
||||
t.Errorf("tag arm does not refresh :latest — the server would hand out a different APK build from the one attached to the Release\n%s", arm)
|
||||
}
|
||||
if strings.Contains(arm, "GITHUB_SHA") {
|
||||
t.Errorf("tag arm mints a :<sha> image; that would re-push main's immutable rollback target with different bundled contents\n%s", arm)
|
||||
}
|
||||
}
|
||||
|
||||
// No version-numbered image tags anywhere, on any arm: the build's version is
|
||||
// self-reported, and the tag map is :latest, :<sha> and :dev.
|
||||
//
|
||||
// Asserted across the whole step rather than per-arm because the mistake this
|
||||
// catches is re-adding one ANYWHERE, and the tag arm is only the likeliest
|
||||
// spot. `${VERSION}` still legitimately appears in the step as the build's
|
||||
// Asserted on both arms because the mistake this catches is re-adding one
|
||||
// anywhere. `${VERSION}` still legitimately appears in the step as the build's
|
||||
// self-reported version, so the assertion has to name the image-tag form
|
||||
// specifically rather than the variable — otherwise it would fire on correct
|
||||
// code and get "fixed" by deleting the guard.
|
||||
func TestNoVersionNumberedImageTags(t *testing.T) {
|
||||
yaml := releaseYAML(t)
|
||||
tagArm, devArm, mainArm := imageTagArms(t, yaml)
|
||||
devArm, mainArm := imageTagArms(t, yaml)
|
||||
|
||||
for _, tc := range []struct{ name, arm string }{
|
||||
{"tag", tagArm}, {"dev", devArm}, {"main", mainArm},
|
||||
{"dev", devArm}, {"main", mainArm},
|
||||
} {
|
||||
for _, forbidden := range []string{
|
||||
"${IMAGE}:${VERSION}",
|
||||
@@ -380,25 +360,6 @@ func TestNoVersionNumberedImageTags(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The verify job asserted the :<version> image existed. With version tags
|
||||
// gone that assertion would fail every release for a tag nothing mints — so
|
||||
// this pins that it was re-pointed rather than deleted, since deleting it is
|
||||
// the tempting way to make a failing guard go green.
|
||||
func TestVerifyJob_ChecksTheRollbackImageNotAVersionTag(t *testing.T) {
|
||||
yaml := releaseYAML(t)
|
||||
|
||||
if !strings.Contains(yaml, "- name: Rollback image must exist for the tagged commit") {
|
||||
t.Fatal("the release-verification step that checks an image exists is gone; an image push that silently did not happen would now pass verification")
|
||||
}
|
||||
step := stepBody(t, yaml, "Rollback image must exist for the tagged commit")
|
||||
if !strings.Contains(step, "${IMAGE}:${GITHUB_SHA}") {
|
||||
t.Errorf("the verify step does not inspect the commit's rollback image\n%s", step)
|
||||
}
|
||||
if strings.Contains(step, "${IMAGE}:${TAG}") {
|
||||
t.Errorf("the verify step still inspects a version-numbered image, which is no longer published — this would fail every release\n%s", step)
|
||||
}
|
||||
}
|
||||
|
||||
// The server's self-reported version is the ONLY thing that identifies a
|
||||
// build, so a lane that stamps a channel word instead of a version silently
|
||||
// removes that ability.
|
||||
@@ -418,7 +379,7 @@ func TestImageBuild_StampsADerivedVersionAndAChannel(t *testing.T) {
|
||||
// The version must come from the shared derivation, not from the ref.
|
||||
// Reading it off GITHUB_REF is what produced "main" and "dev" as version
|
||||
// strings, which is the regression this pins.
|
||||
_, _, mainArm := imageTagArms(t, yaml)
|
||||
_, mainArm := imageTagArms(t, yaml)
|
||||
if strings.Contains(mainArm, `version=main`) {
|
||||
t.Errorf("the main arm stamps the literal string \"main\" as a version; two images months apart would be indistinguishable\n%s", mainArm)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user