ci(release): a dispatch builds the public release image for GHCR from the export (#8207)
release / web (push) Successful in 1m29s
release / go (push) Successful in 1m58s
release / govulncheck (push) Successful in 18s
release / integration (push) Successful in 4m17s
release / android (push) Successful in 4m49s
release / Build signed APK (push) Successful in 5m39s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Publish the release image to GHCR (dispatch only) (push) Skipped
release / Build + push container image (push) Successful in 14s
release / Verify release artifacts (tag releases only) (push) Skipped

A new publishing job, ghcr-release, runs only on a workflow_dispatch with
ghcr_release ticked, behind every verifying lane:

- names the release with ci/version.sh (tag v<name>);
- exports `git archive HEAD`, refuses it if it carries .gitea or ci,
  and matches its tree (staged with add -A -f) to the public repo's
  v<name> tag; a dry run tolerates a missing tag as revision=unreleased;
- stages the freshly built APK and sidecar into the export;
- builds with --provenance=false, labelled source=the GitHub repo,
  revision=the public commit, version=<name>;
- unless ghcr_dry_run (the default), logs in with vars.GHCR_USER and
  secrets.GHCR_TOKEN and pushes :<name> once and :latest. A real run
  must be on main.

image-release stands aside on a GHCR dispatch, so a release moves no
private channel. The concurrency group now includes the event, so a
dispatch and a push on one ref don't cancel each other. The gate test
counts ghcr-release as a publisher and pins its trigger, its export
build, its provenance flag and its source label.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-28 19:41:08 -05:00
co-authored by Claude Opus 5.5
parent e1f270362d
commit 143bb8561c
2 changed files with 244 additions and 7 deletions
+195 -4
View File
@@ -6,8 +6,12 @@ name: release
# push to main → :latest + :<sha> (freshly-built stable APK bundled) # push to main → :latest + :<sha> (freshly-built stable APK bundled)
# push tag vYYYY.MM.DD.HHMM → :latest (fresh APK bundled, and attached to the Release) # push tag vYYYY.MM.DD.HHMM → :latest (fresh APK bundled, and attached to the Release)
# workflow_dispatch → manual trigger (same rules based on the ref) # workflow_dispatch → manual trigger (same rules based on the ref)
# workflow_dispatch, ghcr_release → ghcr.io/fabled-sword/minstrel:<version> + :latest,
# built from the public export (ghcr-release),
# and nothing on the private registry
# #
# That is the whole tag map. # That is the whole tag map. The rest of this header is about the private
# registry; the public release image is described at ghcr-release.
# #
# :<sha> on main is the ROLLBACK UNIT — every production commit addressable # :<sha> on main is the ROLLBACK UNIT — every production commit addressable
# without a release ceremony. It is minted only on main, where rollback is # without a release ceremony. It is minted only on main, where rollback is
@@ -111,12 +115,21 @@ on:
description: Fail the go lane on purpose, to check that nothing publishes on red description: Fail the go lane on purpose, to check that nothing publishes on red
type: boolean type: boolean
default: false default: false
ghcr_release:
description: Build the public release image from the exported tree for GHCR (ghcr-release), instead of the private channel image
type: boolean
default: false
ghcr_dry_run:
description: With ghcr_release, build and check but push nothing. Untick only for the real release, run on main
type: boolean
default: true
# A rapid re-push to main supersedes the in-flight build: the later commit # A rapid re-push to main supersedes the in-flight build: the later commit
# wins. Tags are immutable and unique, so no tag build can be superseded by # wins. Tags are immutable and unique, so no tag build can be superseded by
# another run on the same ref. # another run on the same ref. The event name is in the group so a dispatch
# and a push on the same ref never cancel each other.
concurrency: concurrency:
group: ${{ github.workflow }}-${{ github.ref }} group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true cancel-in-progress: true
jobs: jobs:
@@ -682,7 +695,8 @@ jobs:
&& needs.web.result == 'success' && needs.web.result == 'success'
&& needs.android.result == 'success' && needs.android.result == 'success'
&& needs.govulncheck.result == 'success' && needs.govulncheck.result == 'success'
&& needs.android-release.result == 'success' }} && needs.android-release.result == 'success'
&& github.event.inputs.ghcr_release != 'true' }}
runs-on: go-ci runs-on: go-ci
container: container:
image: git.fabledsword.com/bvandeusen/ci-go:1.26 image: git.fabledsword.com/bvandeusen/ci-go:1.26
@@ -830,6 +844,183 @@ jobs:
--build-arg MINSTREL_CHANNEL="${{ steps.tags.outputs.channel }}" \ --build-arg MINSTREL_CHANNEL="${{ steps.tags.outputs.channel }}" \
--push ${{ steps.tags.outputs.args }} . --push ${{ steps.tags.outputs.args }} .
# The public release image, process #7881's release step 4.
#
# Runs only on a dispatch with ghcr_release ticked, never on a push. It
# builds from `git archive HEAD`, the same tree the public repo's release
# commit holds, so nothing export-ignored (.gitea/, ci/) reaches the
# image's build context, and the image's labels name the public repo and
# the public commit rather than this workbench.
#
# Tags: :<version> (rule 149's name, v<name> is the public git tag) and
# :latest. :<version> is pushed once and never re-pushed; a re-run only
# moves :latest. The private registry gets nothing from this job.
#
# ghcr_dry_run (the default) builds and checks everything and pushes
# nothing, so the job can be proved on dev before a release exists. A real
# run must be on main and needs the public tag to exist already: the
# exported tree is compared with the tag's tree and refused on a mismatch.
ghcr-release:
name: Publish the release image to GHCR (dispatch only)
needs: [go, integration, web, android, govulncheck, android-release]
if: >-
${{
!cancelled()
&& github.event_name == 'workflow_dispatch'
&& github.event.inputs.ghcr_release == 'true'
&& needs.go.result == 'success'
&& needs.integration.result == 'success'
&& needs.web.result == 'success'
&& needs.android.result == 'success'
&& needs.govulncheck.result == 'success'
&& needs.android-release.result == 'success' }}
runs-on: go-ci
container:
image: git.fabledsword.com/bvandeusen/ci-go:1.26
env:
PUBLIC_IMAGE: ghcr.io/fabled-sword/minstrel
PUBLIC_REPO: https://github.com/Fabled-Sword/minstrel
# Anything but an explicit false is a dry run.
DRY_RUN: ${{ github.event.inputs.ghcr_dry_run != 'false' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Full history: ci/version.sh derives the name from commit times.
fetch-depth: 0
- name: Name the release
id: name
shell: bash
run: |
set -euo pipefail
VERSION="$(ci/version.sh HEAD | sed -n 's/^name=//p')"
if [ -z "${VERSION}" ]; then
echo "::error::could not derive a release name from ci/version.sh"
exit 1
fi
if [ "${DRY_RUN}" != "true" ] && [ "${GITHUB_REF}" != "refs/heads/main" ]; then
echo "::error::a real GHCR release runs on main; this is ${GITHUB_REF}. Dispatch on main, or leave ghcr_dry_run ticked."
exit 1
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "tag=v${VERSION}" >> "$GITHUB_OUTPUT"
echo "::notice::Release ${VERSION} (public tag v${VERSION}), dry run: ${DRY_RUN}"
- name: Export the public tree and match it to the public tag
id: export
shell: bash
env:
TAG: ${{ steps.name.outputs.tag }}
run: |
set -euo pipefail
EXPORT="${RUNNER_TEMP}/export"
rm -rf "${EXPORT}"
mkdir -p "${EXPORT}"
git archive HEAD | tar -x -C "${EXPORT}"
for private in .gitea ci ci-requirements.md; do
if [ -e "${EXPORT}/${private}" ]; then
echo "::error::the export carries ${private}; .gitattributes export-ignore no longer covers it"
exit 1
fi
done
# The tree hash of exactly what was exported. -f because some
# tracked files are also ignored (android/.idea, the generated token
# CSS): the public commit has to be staged with -f too, or it drops
# them and this match refuses the release.
cd "${EXPORT}"
git init -q
git add -A -f
TREE="$(git write-tree)"
echo "::notice::export tree ${TREE}"
if git fetch -q --depth 1 "${PUBLIC_REPO}" "refs/tags/${TAG}:refs/tags/${TAG}" 2>/dev/null; then
PUBLIC_TREE="$(git rev-parse "${TAG}^{tree}")"
REVISION="$(git rev-parse "${TAG}^{commit}")"
if [ "${PUBLIC_TREE}" != "${TREE}" ]; then
echo "::error::${PUBLIC_REPO} tag ${TAG} holds tree ${PUBLIC_TREE}, but this commit exports ${TREE}. The public release commit is not this export."
exit 1
fi
echo "::notice::public ${TAG} is commit ${REVISION}, and its tree matches the export"
elif [ "${DRY_RUN}" = "true" ]; then
REVISION=unreleased
echo "::notice::${TAG} is not on ${PUBLIC_REPO} yet; a dry run labels the image revision=unreleased"
else
echo "::error::${TAG} is not on ${PUBLIC_REPO}. Push the public release commit and its tag first (#8209), then run this."
exit 1
fi
rm -rf .git
echo "dir=${EXPORT}" >> "$GITHUB_OUTPUT"
echo "revision=${REVISION}" >> "$GITHUB_OUTPUT"
- name: Download signed APK artifact
uses: actions/download-artifact@v8
with:
name: minstrel-apk
path: client/
- name: Stage the APK and its version sidecar into the export
shell: bash
env:
APK_VERSION_NAME: ${{ needs.android-release.outputs.version_name }}
APK_VERSION_CODE: ${{ needs.android-release.outputs.version_code }}
APK_CHANNEL: ${{ needs.android-release.outputs.channel }}
EXPORT: ${{ steps.export.outputs.dir }}
run: |
set -euxo pipefail
mv client/app-release.apk "${EXPORT}/client/minstrel.apk"
printf '{"name":"%s","code":%s,"channel":"%s"}\n' \
"${APK_VERSION_NAME}" "${APK_VERSION_CODE}" "${APK_CHANNEL}" \
> "${EXPORT}/client/minstrel.apk.version"
cat "${EXPORT}/client/minstrel.apk.version"
- name: Build the release image from the export
shell: bash
env:
VERSION: ${{ steps.name.outputs.version }}
REVISION: ${{ steps.export.outputs.revision }}
CHANNEL: ${{ needs.android-release.outputs.channel }}
EXPORT: ${{ steps.export.outputs.dir }}
# --provenance=false and no SBOM: an attestation would carry the
# workbench's build details into a public registry.
run: |
set -euo pipefail
docker build --pull --provenance=false \
--build-arg MINSTREL_VERSION="${VERSION}" \
--build-arg MINSTREL_CHANNEL="${CHANNEL}" \
--label org.opencontainers.image.source="${PUBLIC_REPO}" \
--label org.opencontainers.image.revision="${REVISION}" \
--label org.opencontainers.image.version="${VERSION}" \
-t "${PUBLIC_IMAGE}:${VERSION}" -t "${PUBLIC_IMAGE}:latest" \
"${EXPORT}"
docker image inspect --format '{{json .Config.Labels}}' "${PUBLIC_IMAGE}:${VERSION}"
- name: Push to GHCR
shell: bash
env:
VERSION: ${{ steps.name.outputs.version }}
GHCR_USER: ${{ vars.GHCR_USER }}
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
run: |
set -euo pipefail
if [ "${DRY_RUN}" = "true" ]; then
echo "::notice::dry run: ${PUBLIC_IMAGE}:${VERSION} and :latest built, nothing pushed"
exit 0
fi
if [ -z "${GHCR_USER}" ]; then echo "::error::the Actions variable GHCR_USER is empty"; exit 1; fi
if [ -z "${GHCR_TOKEN}" ]; then echo "::error::the Actions secret GHCR_TOKEN is empty"; exit 1; fi
printf '%s' "${GHCR_TOKEN}" | docker login ghcr.io -u "${GHCR_USER}" --password-stdin
if docker manifest inspect "${PUBLIC_IMAGE}:${VERSION}" > /dev/null 2>&1; then
echo "::notice::${PUBLIC_IMAGE}:${VERSION} is already published and is never re-pushed; moving :latest only"
else
docker push "${PUBLIC_IMAGE}:${VERSION}"
fi
docker push "${PUBLIC_IMAGE}:latest"
docker image inspect --format '{{json .RepoDigests}}' "${PUBLIC_IMAGE}:${VERSION}"
# Verifies a tag release actually ended up complete, and names the specific # Verifies a tag release actually ended up complete, and names the specific
# thing that's missing if not. # thing that's missing if not.
# #
+49 -3
View File
@@ -24,9 +24,10 @@ import (
// require its success by name. // require its success by name.
var gateLanes = []string{"go", "integration", "web", "android", "govulncheck"} var gateLanes = []string{"go", "integration", "web", "android", "govulncheck"}
// gatePublishers push something other people can pull: image tags, and the // gatePublishers push something other people can pull: image tags (the
// APK + sidecar attached to a Release. // private channels, and the public release image on GHCR), and the APK +
var gatePublishers = []string{"image-release", "release-assets"} // sidecar attached to a Release.
var gatePublishers = []string{"image-release", "release-assets", "ghcr-release"}
// gateOthers are the remaining jobs and why they sit outside the gate: // gateOthers are the remaining jobs and why they sit outside the gate:
// android-release only builds a workflow artifact (nothing outside the run can // android-release only builds a workflow artifact (nothing outside the run can
@@ -118,3 +119,48 @@ 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)
}
yaml := releaseYAML(t)
i := strings.Index(yaml, "\n ghcr-release:")
if i < 0 {
t.Fatal("no ghcr-release job")
}
job := yaml[i:]
if j := jobBoundary.FindStringIndex(job[1:]); j != nil {
job = job[:j[0]+1]
}
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)
}
}
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")
}
}