diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index fa3bbac6..b5901a6d 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -1,17 +1,20 @@ name: release -# Builds and pushes the minstrel container image to the Gitea registry. +# Builds and pushes the minstrel container image to the Gitea registry, and on +# main also makes the public release. # -# push to dev → :dev (freshly-built dev APK bundled) -# push to main → :latest + : (freshly-built stable APK bundled) -# 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, ghcr_release → ghcr.io/fabled-sword/minstrel: + :latest, -# built from the public export (ghcr-release), -# and nothing on the private registry +# push to dev → :dev (freshly-built dev APK bundled), and the +# public release's dry run +# push to main → :latest + : (freshly-built stable APK bundled), then +# THE PUBLIC RELEASE: one commit and tag v on +# github.com/Fabled-Sword/minstrel, the image +# ghcr.io/fabled-sword/minstrel : + :latest, and a +# release page with its changelog on both forges +# workflow_dispatch → the same as a push to the dispatched branch, private +# half only; force_red checks the gate (see below) # # 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. +# registry; the public release is described at image-release. # # : on main is the ROLLBACK UNIT — every production commit addressable # without a release ceremony. It is minted only on main, where rollback is @@ -47,33 +50,24 @@ name: release # # Every branch build carries the app built from its own commit, so a merge to # main is all it takes to put a new app in front of stable phones: `:latest` -# serves it from /api/client/apk and the in-app update offers it. A release -# is an optional bookmark — a named point in history with the APK attached -# for download — never a step the app has to wait for. +# serves it from /api/client/apk and the in-app update offers it. The app is +# never published on its own; it reaches phones only through the server. # -# Release model: the tag IS the artifact's version name with a `v` in front. -# `v2026.09.10.1432` and `2026.09.10.1432` are the same string, derived from -# the tagged commit's UTC timestamp — so there is no mismatch to reconcile -# between what the tag says and what the APK reports, and nothing to look up -# when minting one. +# Release model: a merge to main IS the release. Its name is v +# from the merge commit's UTC time, so every merge has its own. The run makes +# the tag on both forges; nobody tags by hand. # -# TAGS ARE IMMUTABLE. Never move, retarget or delete a published tag. A -# same-day second release is not a collision — HHMM makes every tag unique -# by construction, so the answer is simply another tag. Anyone installing -# from a moved tag would hold something the tag no longer points at, which -# is a worse failure than an extra row in the tag list. +# TAGS ARE IMMUTABLE. Never move, retarget or delete a published tag. A re-run +# finds its tag already published: on the same tree it goes on, on another it +# stops. A failed public half is fixed on dev, and the next merge carries a new +# name. # -# :latest is updated by every main push AND every tag push, so it always -# reflects the newest blessed image. -# -# APK pipeline: on every push — dev, main and tags alike — the -# android-release job builds + signs the Android APK and uploads it as a -# workflow artifact. The image-release job declares `needs: android-release` -# and requires its success, so the docker image cannot start building until -# the APK is guaranteed-ready — no polling, no race, no silent-failure mode, -# and no image that moves a channel without an app inside it. Attaching the -# APK to the gitea Release is its own job (release-assets), tags only, behind -# the test gate below. +# APK pipeline: on every push the android-release job builds + signs the +# Android APK and uploads it as a workflow artifact. The image-release job +# declares `needs: android-release` and requires its success, so the docker +# image cannot start building until the APK is guaranteed-ready — no polling, +# no race, no silent-failure mode, and no image that moves a channel without +# an app inside it. # # THE GATE. Every verifying lane lives in this file — # Go (vet, lint, short tests), the Postgres integration suite, the web app @@ -92,42 +86,30 @@ name: release # path filters for the same reason: a web-only push still runs the Go suite, # because "not run" must never read as "passed". # -# What publishes, and is therefore gated: the image tags (image-release) and -# the APK + version sidecar attached to a tag's Release (release-assets). -# android-release only BUILDS the signed APK into a workflow artifact, which -# nobody outside this run can pull, so it runs in parallel with the lanes -# instead of after them; attaching it to the Release is the publishing half, -# and that half waits for the gate. +# What publishes, and is therefore gated: everything image-release pushes, the +# private image tags and the whole public release. android-release only BUILDS +# the signed APK into a workflow artifact, which nobody outside this run can +# pull, so it runs in parallel with the lanes instead of after them. # # To watch the gate refuse: dispatch this workflow with force_red=true. The go -# lane fails on purpose, and both publishing jobs must report skipped. +# lane fails on purpose, and the publishing job must report skipped. +# No path filter. The README, docs and tests ship in the public release too, +# so a merge to main that changes only them must still run, or it would not +# release. on: push: branches: [main, dev] - tags: ['v*'] - paths-ignore: - - 'docs/**' - - '**/*.md' workflow_dispatch: inputs: force_red: description: Fail the go lane on purpose, to check that nothing publishes on red type: boolean 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 -# wins. Tags are immutable and unique, so no tag build can be superseded by -# 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. +# wins. The event name is in the group so a dispatch and a push on the same +# ref never cancel each other. concurrency: group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }} cancel-in-progress: true @@ -454,12 +436,10 @@ jobs: android-release: name: Build signed APK - # Builds on every ref, so each channel's image carries the app from its - # own commit: `dev` for the test channel, `main` for stable phones, and a - # tag for the copy attached to its Release. + # Builds on both branches, so each channel's image carries the app from + # its own commit: `dev` for the test channel, `main` for stable phones. if: >- - startsWith(github.ref, 'refs/tags/v') - || github.ref == 'refs/heads/dev' + github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/main' runs-on: flutter-ci container: @@ -523,32 +503,6 @@ jobs: echo "channel=${channel}" >> "$GITHUB_OUTPUT" echo "::notice::APK $(printf '%s' "${out}" | tr '\n' ' ') channel=${channel}" - # Checked BEFORE the expensive work, not after it. "Attach APK to gitea - # Release" below resolves the release by tag and fails if it is absent — - # but that is the final step, so a tag pushed without a release would - # build an APK for several minutes first and only then find it has - # nowhere to put it. Same check, seconds in instead of minutes. - # - # Releases are normally created through the API (which creates the tag and - # the release together, so this passes). A bare `git push origin vX` is the - # case this catches. - - name: Release must exist for this tag - if: startsWith(github.ref, 'refs/tags/v') - shell: bash - working-directory: ${{ github.workspace }} - env: - CI_TOKEN: ${{ secrets.CI_TOKEN }} - run: | - set -euo pipefail - TAG="${GITHUB_REF#refs/tags/}" - if ! curl -fsSL -o /dev/null \ - -H "Authorization: token ${CI_TOKEN}" \ - "https://git.fabledsword.com/api/v1/repos/${GITHUB_REPOSITORY}/releases/tags/${TAG}"; then - echo "::error::no release exists for ${TAG}. Create the release (which creates the tag) rather than pushing a bare tag — otherwise there is nothing to attach the APK to." - exit 1 - fi - echo "::notice::release found for ${TAG}" - - name: Cache Gradle dirs uses: actions/cache@v4 with: @@ -629,98 +583,21 @@ jobs: # artifact existing, so an empty upload must fail here, not there. if-no-files-found: error - # Publishes the signed APK and its version sidecar on the tag's Release. - # Split out of android-release so the APK can be BUILT in parallel with the - # lanes while being PUBLISHED only once they have all passed. - release-assets: - name: Attach APK to the Release (tag releases only) - needs: [go, integration, web, android, govulncheck, android-release] - if: >- - ${{ - !cancelled() - && 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' - && startsWith(github.ref, 'refs/tags/v') }} - runs-on: go-ci - container: - image: git.fabledsword.com/bvandeusen/ci-go:1.26 - - steps: - - name: Download signed APK artifact - uses: actions/download-artifact@v8 - with: - name: minstrel-apk - path: release-apk/ - - - name: Attach APK to gitea Release - # Tag releases only. A branch build has no Release to hang assets on - # and does not need one — its image bundles the APK, and the server - # serves it from /api/client/apk. - shell: bash - env: - CI_TOKEN: ${{ secrets.CI_TOKEN }} - VERSION_NAME: ${{ needs.android-release.outputs.version_name }} - VERSION_CODE: ${{ needs.android-release.outputs.version_code }} - run: | - set -euxo pipefail - TAG="${GITHUB_REF#refs/tags/}" - REPO="${GITHUB_REPOSITORY}" - APK_PATH="release-apk/app-release.apk" - ls -lh "${APK_PATH}" - - # Publish the version sidecar as a release asset next to the APK. - # - # This is what lets a later :latest build stop RECONSTRUCTING the - # bundled APK's version and simply read what was recorded. The - # ordering key in particular cannot be re-derived after the fact — - # it is build-time minutes, so once this job ends the value exists - # nowhere else. Reconstruction could only ever recover the name, - # and only by duplicating a formula that then has to be kept in - # step across two files. - SIDECAR_PATH="/tmp/minstrel.apk.version" - printf '{"name":"%s","code":%s,"channel":"stable"}\n' \ - "${VERSION_NAME}" "${VERSION_CODE}" > "${SIDECAR_PATH}" - cat "${SIDECAR_PATH}" - - RELEASE_JSON="$(curl -fsSL \ - -H "Authorization: token ${CI_TOKEN}" \ - "https://git.fabledsword.com/api/v1/repos/${REPO}/releases/tags/${TAG}")" - RELEASE_ID="$(printf '%s' "${RELEASE_JSON}" | grep -oP '"id":\s*\K[0-9]+' | head -1)" - if [ -z "${RELEASE_ID}" ]; then - echo "::error::release for ${TAG} not found"; exit 1 - fi - echo "release_id=${RELEASE_ID}" - - UPLOAD_HTTP=$(curl -sS -L -o /tmp/upload.out -w '%{http_code}' \ - -H "Authorization: token ${CI_TOKEN}" \ - -F "attachment=@${APK_PATH}" \ - "https://git.fabledsword.com/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets?name=minstrel-${TAG}.apk") - echo "upload_http=${UPLOAD_HTTP}" - cat /tmp/upload.out || true - echo - if [ "${UPLOAD_HTTP}" -lt 200 ] || [ "${UPLOAD_HTTP}" -ge 300 ]; then - echo "::error::APK upload returned HTTP ${UPLOAD_HTTP}" - exit 1 - fi - - # Same treatment for the sidecar. Named `.apk.version` so the - # downloader's `\.apk$` match cannot pick it up by mistake. - SIDECAR_HTTP=$(curl -sS -L -o /tmp/upload-sidecar.out -w '%{http_code}' \ - -H "Authorization: token ${CI_TOKEN}" \ - -F "attachment=@${SIDECAR_PATH}" \ - "https://git.fabledsword.com/api/v1/repos/${REPO}/releases/${RELEASE_ID}/assets?name=minstrel-${TAG}.apk.version") - echo "sidecar_upload_http=${SIDECAR_HTTP}" - cat /tmp/upload-sidecar.out || true - echo - if [ "${SIDECAR_HTTP}" -lt 200 ] || [ "${SIDECAR_HTTP}" -ge 300 ]; then - echo "::error::version sidecar upload returned HTTP ${SIDECAR_HTTP}" - exit 1 - fi - + # The image, and on main the public release. + # + # Every push builds its image FROM THE EXPORT, `git archive` of this commit, + # and runs the changelog and the leak gate on it first. So a dev push is the + # public release's dry run: an export that leaks or does not build is red the + # day it lands, not at the merge. + # + # A push to main is also the PUBLIC release, after the private push: + # 1. the export becomes one commit on github.com/Fabled-Sword/minstrel's + # main, tagged v, authored by AmateurDungeoneer and dated in UTC; + # 2. that tree is built into ghcr.io/fabled-sword/minstrel : and + # :latest, labelled with the public repository and commit; + # 3. a GitHub Release with the public changelog, and a release on this forge + # with the private one, both v, both naming the image. + # is YYYY.MM.DD.HHMM from the merge commit's time. image-release: name: Build + push container image # Every lane must have SUCCEEDED, each named here, and so must the APK @@ -735,42 +612,29 @@ jobs: && needs.web.result == 'success' && needs.android.result == 'success' && needs.govulncheck.result == 'success' - && needs.android-release.result == 'success' - && github.event.inputs.ghcr_release != 'true' }} + && needs.android-release.result == 'success' }} runs-on: go-ci container: image: git.fabledsword.com/bvandeusen/ci-go:1.26 env: IMAGE: git.fabledsword.com/bvandeusen/minstrel + PUBLIC_REPO: Fabled-Sword/minstrel + PUBLIC_IMAGE: ghcr.io/fabled-sword/minstrel steps: - name: Checkout uses: actions/checkout@v4 with: - # Full history: any job that DERIVES the version name needs it, - # because a shallow clone changes what git-derived values resolve to - # WITHOUT failing — a too-low value, silently, with every lane green. - # - # This job runs ci/version.sh itself: with no : image tags, - # the server's self-reported version is the only thing that says which - # build an image is. + # Full history and its tags: any job that DERIVES the version name + # needs it, because a shallow clone changes what git-derived values + # resolve to WITHOUT failing — a too-low value, silently, with every + # lane green. The changelog lists the commits since the previous + # release's tag, so it needs them too. fetch-depth: 0 - - name: Detect buildable project - id: guard - shell: bash - run: | - if [ -f Dockerfile ] && [ -f go.mod ]; then - echo "ready=true" >> "$GITHUB_OUTPUT" - else - echo "ready=false" >> "$GITHUB_OUTPUT" - echo "::notice::No Dockerfile + go.mod yet — release build skipped" - fi - - name: Compute image tags id: tags - if: steps.guard.outputs.ready == 'true' shell: bash run: | set -euo pipefail @@ -778,10 +642,10 @@ jobs: # THE VERSION, and it is derived the same way on every ref — the # branch decides the CHANNEL, never the version. # - # A per-ref string ("main", "dev", the tag name) would not order, and - # "dev" would be the same string forever — two dev images eight weeks - # apart indistinguishable in the UI. With no version image tags, this - # is how an admin tells which build a container is running. + # A per-ref string ("main", "dev") would not order, and "dev" would be + # the same string forever — two dev images eight weeks apart + # indistinguishable in the UI. The server's self-reported version is + # how an admin tells which build a private image is. # # `sed -n s///p` rather than `grep`: it exits 0 when nothing matches, # so the empty check below is actually reachable. A grep here would @@ -792,24 +656,7 @@ jobs: exit 1 fi - if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then - # A release refreshes the CHANNEL and mints nothing else. - # - # The tag build exists to produce the signed APK and attach it to - # the release; the image it rebuilds is the SAME SOURCE as the main - # build minutes earlier, differing only in which APK is baked in. - # When the same source is rebuilt with different contents, - # publish the moving channel tag and never a commit-addressable - # one. - # - # :latest moves here so the server hands out the same APK build - # that is attached to the Release: a phone that installed from the - # Release page and one that updated in-app hold one build, with one - # ordering key. Cut a release on main's tip, as :latest follows it. - CHANNEL=stable - echo "args=-t ${IMAGE}:latest" >> "$GITHUB_OUTPUT" - echo "::notice::Release build ${VERSION}: refreshing :latest around the new APK" - elif [[ "${GITHUB_REF}" == "refs/heads/dev" ]]; then + if [[ "${GITHUB_REF}" == "refs/heads/dev" ]]; then # The rolling test channel, and :dev ALONE — deliberately no # per-commit tag. A rolling channel is rolling by definition, so a # commit-addressable image here would be a rollback target nobody @@ -830,8 +677,72 @@ jobs: echo "version=${VERSION}" >> "$GITHUB_OUTPUT" echo "channel=${CHANNEL}" >> "$GITHUB_OUTPUT" + # The public release's name, and whether this run makes the release. + # Only a PUSH to main does: a dispatch on main rebuilds the private + # channel and publishes nothing outside this forge. + { + echo "EXPORT=${RUNNER_TEMP}/export" + echo "NAME=$(date -u -d "@$(git log -1 --format=%ct HEAD)" +%Y.%m.%d.%H%M)" + if [ "${GITHUB_EVENT_NAME}" = "push" ] && [ "${GITHUB_REF}" = "refs/heads/main" ]; then + echo "PUBLIC=true" + else + echo "PUBLIC=false" + fi + } >> "$GITHUB_ENV" + + # What a release would publish: the export, and its changelog. Neither + # may carry a banned word or a private record id (ci/leakgate.sh), and the + # export carries no CI file. + - name: Export, changelog and leak gate + shell: bash + run: | + set -euo pipefail + rm -rf "${EXPORT}" + mkdir -p "${EXPORT}" + git archive HEAD | tar -x -C "${EXPORT}" + for private in .gitea .forgejo .github ci ci-requirements.md .gitattributes renovate.json; do + if [ -e "${EXPORT}/${private}" ]; then + echo "::error::the export carries ${private}; .gitattributes export-ignore no longer covers it" + exit 1 + fi + done + bash ci/changelog.sh "${RUNNER_TEMP}/changelog" + echo "--- the public changelog of v${NAME} ---" + cat "${RUNNER_TEMP}/changelog/public.md" + echo "---" + bash ci/leakgate.sh "${EXPORT}" "${RUNNER_TEMP}/changelog/public.md" + + # The secrets the public half needs, checked before anything is pushed + # anywhere. A dev push warns about one that is missing or refused; a main + # push stops. Nothing here writes: the push token reads the public + # repository, and the forge token updates a release that does not exist. + - name: Public release secrets + shell: bash + env: + PUBLIC_PUSH_TOKEN: ${{ secrets.PUBLIC_PUSH_TOKEN }} + GHCR_USER: ${{ vars.GHCR_USER || secrets.GHCR_USER }} + GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }} + FORGE_TOKEN: ${{ secrets.CI_TOKEN }} + run: | + set -u + bad="" + say() { bad="yes"; if [ "${PUBLIC}" = "true" ]; then echo "::error::$1"; else echo "::warning::$1"; fi; } + [ -n "${GHCR_USER}" ] || say "GHCR_USER is empty or unset (an Actions variable or secret)" + [ -n "${GHCR_TOKEN}" ] || say "the GHCR_TOKEN secret is empty or unset" + if [ -z "${PUBLIC_PUSH_TOKEN}" ]; then + say "the PUBLIC_PUSH_TOKEN secret is empty or unset" + else + auth="$(printf 'x-access-token:%s' "${PUBLIC_PUSH_TOKEN}" | base64 -w0)" + echo "::add-mask::${auth}" + git -c http.https://github.com/.extraheader="AUTHORIZATION: basic ${auth}" \ + ls-remote "https://github.com/${PUBLIC_REPO}.git" >/dev/null \ + || say "PUBLIC_PUSH_TOKEN cannot read github.com/${PUBLIC_REPO}" + fi + node ci/releases.mjs forge-probe || say "CI_TOKEN may not write this repository's releases" + if [ -n "${bad}" ] && [ "${PUBLIC}" = "true" ]; then exit 1; fi + exit 0 + - name: Registry login - if: steps.guard.outputs.ready == 'true' shell: bash run: | echo "${{ secrets.CI_TOKEN }}" \ @@ -839,7 +750,6 @@ jobs: - name: Download signed APK artifact # android-release just produced this, on every ref. - if: steps.guard.outputs.ready == 'true' # Consuming half of the pair: stock download-artifact, which works here for # the same reason as the upload (gitea/runner 3.x edits the GHES refusal # out of the bundle). v8 runs on node24, which every CI-runner image @@ -849,8 +759,8 @@ jobs: name: minstrel-apk path: client/ + # Into the export, which is what the image is built from. - name: Stage bundled APK + version sidecar - if: steps.guard.outputs.ready == 'true' shell: bash env: # All three pulled from android-release's outputs so the sidecar the @@ -864,15 +774,15 @@ jobs: # The artifact lands as `app-release.apk` (the original Gradle # output name). The Dockerfile COPYs client/* into /app/client/ # and the server reads minstrel.apk + minstrel.apk.version. - mv client/app-release.apk client/minstrel.apk + 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}" \ - > client/minstrel.apk.version - cat client/minstrel.apk.version - ls -lh client/ + > "${EXPORT}/client/minstrel.apk.version" + cat "${EXPORT}/client/minstrel.apk.version" + ls -lh "${EXPORT}/client/" - name: Build and push - if: steps.guard.outputs.ready == 'true' + shell: bash # --pull: the Dockerfile's base images are floating tags (golang:1.26, # debian:bookworm-slim). Without it the runner's daemon reuses # whatever it cached, and the shipped binary can sit on a Go patch @@ -882,262 +792,127 @@ jobs: docker buildx build --pull \ --build-arg MINSTREL_VERSION="${{ steps.tags.outputs.version }}" \ --build-arg MINSTREL_CHANNEL="${{ steps.tags.outputs.channel }}" \ - --push ${{ steps.tags.outputs.args }} . + --push ${{ steps.tags.outputs.args }} "${EXPORT}" - # 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: : (rule 149's name, v is the public git tag) and - # :latest. : 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 + # THE PUBLIC RELEASE, a push to main only. The export becomes one commit + # on the public repository's main, replacing its whole tree so removed + # files go too, tagged v. Author, committer and tagger are the + # project's public identity, dated at this commit's time in UTC. + # + # A re-run finds v already there: on the same tree it goes on to the + # image and the releases, on a different tree it stops. A published tag + # is never moved. + - name: Public commit and tag + if: env.PUBLIC == 'true' shell: bash env: - TAG: ${{ steps.name.outputs.tag }} + PUBLIC_PUSH_TOKEN: ${{ secrets.PUBLIC_PUSH_TOKEN }} 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 + auth="$(printf 'x-access-token:%s' "${PUBLIC_PUSH_TOKEN}" | base64 -w0)" + echo "::add-mask::${auth}" + pub="${RUNNER_TEMP}/public" + rm -rf "${pub}" + git init -q -b main "${pub}" + cd "${pub}" + git config http.https://github.com/.extraheader "AUTHORIZATION: basic ${auth}" + git remote add origin "https://github.com/${PUBLIC_REPO}.git" + # An empty repository has no main yet, and its first release starts it. + if [ -n "$(git ls-remote --heads origin main)" ]; then + git fetch -q --depth 1 origin main + git checkout -q -B main FETCH_HEAD + fi + find . -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} + + # A fresh archive, not the build context, which also holds the app. + git -C "${GITHUB_WORKSPACE}" archive HEAD | tar -xf - + # -f: the export exactly, a tracked file a .gitignore matches + # (the generated token CSS) included. 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." + tree="$(git write-tree)" + when="@$(git -C "${GITHUB_WORKSPACE}" log -1 --format=%ct HEAD) +0000" + if [ -n "$(git ls-remote --tags origin "refs/tags/v${NAME}")" ]; then + git fetch -q --depth 1 origin "refs/tags/v${NAME}:refs/tags/v${NAME}" + if [ "$(git rev-parse "v${NAME}^{tree}")" != "${tree}" ]; then + echo "::error::the public tag v${NAME} holds another tree; a published tag is never moved" 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" + echo "::notice::v${NAME} is already published with this tree" else - echo "::error::${TAG} is not on ${PUBLIC_REPO}. Push the public release commit and its tag first (#8209), then run this." - exit 1 + export GIT_AUTHOR_NAME=AmateurDungeoneer GIT_AUTHOR_EMAIL=amateurdungeoneer@fabledsword.com + export GIT_COMMITTER_NAME=AmateurDungeoneer GIT_COMMITTER_EMAIL=amateurdungeoneer@fabledsword.com + export GIT_AUTHOR_DATE="${when}" GIT_COMMITTER_DATE="${when}" + git commit -q -m "Release ${NAME}" + git tag -a "v${NAME}" -m "Release ${NAME}" + git push -q origin main "refs/tags/v${NAME}" fi - rm -rf .git - echo "dir=${EXPORT}" >> "$GITHUB_OUTPUT" - echo "revision=${REVISION}" >> "$GITHUB_OUTPUT" + echo "REVISION=$(git rev-parse "v${NAME}^{commit}")" >> "$GITHUB_ENV" - - 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 + # The same export, built again with the release's name and labels that + # point at the public repository and commit, so nothing in the image + # points back here. Every layer but the stamped binary comes from the + # build above. --provenance=false and no SBOM: an attestation would carry + # this workbench's build details into a public registry. + - name: Public image + if: env.PUBLIC == 'true' 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 is read from an Actions variable, or from a secret of - # that name where no variable reaches the job. GHCR_USER: ${{ vars.GHCR_USER || secrets.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::GHCR_USER is empty: set it as an Actions variable or secret"; exit 1; fi - if [ -z "${GHCR_TOKEN}" ]; then echo "::error::the Actions secret GHCR_TOKEN is empty"; exit 1; fi + docker build --provenance=false \ + --build-arg MINSTREL_VERSION="${NAME}" \ + --build-arg MINSTREL_CHANNEL=stable \ + --label "org.opencontainers.image.source=https://github.com/${PUBLIC_REPO}" \ + --label "org.opencontainers.image.revision=${REVISION}" \ + --label "org.opencontainers.image.version=${NAME}" \ + -t "${PUBLIC_IMAGE}:${NAME}" "${EXPORT}" + labelled="$(docker inspect --format '{{ index .Config.Labels "org.opencontainers.image.revision" }}' "${PUBLIC_IMAGE}:${NAME}")" + test "${labelled}" = "${REVISION}" || { echo "::error::the image names commit ${labelled}, not ${REVISION}"; exit 1; } 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" + # : is never re-pushed, so a re-run only moves :latest. + if docker manifest inspect "${PUBLIC_IMAGE}:${NAME}" >/dev/null 2>&1; then + echo "::notice::${PUBLIC_IMAGE}:${NAME} is already published; only :latest moves" else - docker push "${PUBLIC_IMAGE}:${VERSION}" + docker push "${PUBLIC_IMAGE}:${NAME}" fi + docker tag "${PUBLIC_IMAGE}:${NAME}" "${PUBLIC_IMAGE}:latest" docker push "${PUBLIC_IMAGE}:latest" - docker image inspect --format '{{json .RepoDigests}}' "${PUBLIC_IMAGE}:${VERSION}" + echo "DIGEST=$(docker inspect --format '{{ index .RepoDigests 0 }}' "${PUBLIC_IMAGE}:${NAME}")" >> "$GITHUB_ENV" - # Verifies a tag release actually ended up complete, and names the specific - # thing that's missing if not. - # - # A release can be incomplete while looking fine. If android-release never - # starts (a runner failing to launch), its steps all report `failure` with - # none executed and image-release shows `skipped`. The run is red, but the - # release page renders and main's own push build has already moved - # `:latest`, so a release missing its APK and its image is easy to skim - # past. - # - # This job cannot prevent that; it turns an incomplete release into an - # explicit, named error instead of a row of mystery step failures. - # - # `if: always()` is the whole point: it has to report precisely when the jobs - # above did NOT succeed. - verify-release: - name: Verify release artifacts (tag releases only) - needs: [android-release, release-assets, image-release] - if: ${{ always() && startsWith(github.ref, 'refs/tags/v') }} - runs-on: go-ci - container: - image: git.fabledsword.com/bvandeusen/ci-go:1.26 - - steps: - - name: Release must have an APK attached + # The release pages, each created or updated in place: GitHub's with the + # public changelog, this forge's with the private one, tagging this + # commit. Both name the image. No files are attached: the app ships + # inside the image. + - name: Public and private releases + if: env.PUBLIC == 'true' shell: bash env: - CI_TOKEN: ${{ secrets.CI_TOKEN }} + PUBLIC_PUSH_TOKEN: ${{ secrets.PUBLIC_PUSH_TOKEN }} + FORGE_TOKEN: ${{ secrets.CI_TOKEN }} run: | set -euo pipefail - TAG="${GITHUB_REF#refs/tags/}" - REPO="${GITHUB_REPOSITORY}" + cl="${RUNNER_TEMP}/changelog" + for side in public private; do + { + cat "${cl}/${side}.md" + printf '\nImage: `%s:%s`\n' "${PUBLIC_IMAGE}" "${NAME}" + } > "${cl}/${side}-body.md" + done + echo "GITHUB_RELEASE=$(node ci/releases.mjs github "v${NAME}" "${cl}/public-body.md")" >> "$GITHUB_ENV" + echo "FORGE_RELEASE=$(node ci/releases.mjs forge "v${NAME}" "${cl}/private-body.md" "${GITHUB_SHA}")" >> "$GITHUB_ENV" - REL_JSON="$(curl -fsSL \ - -H "Authorization: token ${CI_TOKEN}" \ - "https://git.fabledsword.com/api/v1/repos/${REPO}/releases/tags/${TAG}" || true)" - if [ -z "${REL_JSON}" ]; then - echo "::error::no release found for ${TAG} — the tag exists but nothing was published" - exit 1 - fi - - APK="$(printf '%s' "${REL_JSON}" \ - | grep -oP '"browser_download_url":\s*"\K[^"]+' \ - | grep -E '\.apk$' | head -1 || true)" - if [ -z "${APK}" ]; then - echo "::error::release ${TAG} has NO APK attached — in-app update will offer nothing, and the bundled-APK path on future :latest builds has no source." - echo "::error::Fix by RE-RUNNING this workflow run. Do NOT delete and re-create the tag; if it fails again the runner never started the container, and the evidence is in act_runner on the host (Gitea will hold no job log)." - exit 1 - fi - - echo "::notice::APK attached: ${APK}" - - # The other half. Checking only the APK would report success on a release - # whose image push failed. `always()` on this job means it runs even when - # image-release failed, so without this the guard would cheerfully verify - # an incomplete release. - # - # The image checked is the : rollback target, which main's own build - # published for this same commit before the tag was cut (there are no - # version image tags). It catches an image push that silently did not - # happen, and it proves the ORDERING — a tag cut on a commit whose main - # build never completed has no rollback target, and that is worth failing - # on rather than discovering during an incident. - - name: Rollback image must exist for the tagged commit + # The record the release task keeps. + - name: Published shell: bash run: | - set -euo pipefail - IMAGE="git.fabledsword.com/bvandeusen/minstrel" - - echo "${{ secrets.CI_TOKEN }}" \ - | docker login git.fabledsword.com -u "${{ github.actor }}" --password-stdin - - if ! docker manifest inspect "${IMAGE}:${GITHUB_SHA}" > /dev/null 2>&1; then - echo "::error::image ${IMAGE}:${GITHUB_SHA} does not exist — this commit has no rollback target." - echo "::error::That image is published by the MAIN build of this commit, not by the tag build. If main's build never ran or failed, fix that first; a release whose commit cannot be rolled back to is the thing this check exists to refuse." - exit 1 + echo "pushed ${{ steps.tags.outputs.args }}" + if [ "${PUBLIC}" = "true" ]; then + echo "release v${NAME} of workbench ${GITHUB_SHA}" + echo "public commit ${REVISION}" + echo "image ${DIGEST}" + echo "GitHub release ${GITHUB_RELEASE}" + echo "forge release ${FORGE_RELEASE}" + else + echo "dry run of release v${NAME}: export, changelog and leak gate passed, image built from the export" fi - echo "::notice::rollback target verified: ${IMAGE}:${GITHUB_SHA}" diff --git a/README.md b/README.md index b8824d3b..8f7ea45b 100644 --- a/README.md +++ b/README.md @@ -87,11 +87,10 @@ docker compose pull && docker compose up -d Database migrations run at startup. Image tags: -- `:latest`: the stable release. Most people should run this. -- `:`: one fixed build. Pin one to stop updates, or to roll back. -- `:dev`: the test channel, rebuilt on every change. It may break, and the fix is the next build. +- `:latest`: the newest release. Most people should run this. +- `:`, such as `:2026.12.04.1530`: one release, which never changes. Pin one to stop updates, or to roll back. The [releases page](https://github.com/Fabled-Sword/minstrel/releases) lists each one with what changed. -Every image carries a signed Android app, all with the same key, so a phone can move between channels without reinstalling. Rolling back a SHA tag rolls back the app it carries too. +Every image carries a signed Android app, all with the same key, so a phone can move between versions without reinstalling. Rolling back to an older version rolls back the app it carries too. **Back up the Postgres volume** with `pg_dump`. It holds accounts, likes, play history, playlists and settings, and a migration can only be undone by restoring a dump. The `minstrel-data` volume holds artwork and caches that Minstrel rebuilds if lost. diff --git a/ci-requirements.md b/ci-requirements.md index d5418f6f..7aa1482c 100644 --- a/ci-requirements.md +++ b/ci-requirements.md @@ -12,7 +12,7 @@ git.fabledsword.com/bvandeusen/ci-go:1.26 git.fabledsword.com/bvandeusen/ci-android:36 ``` -- `ci-go:1.26` — the `go`, `integration` and `web` lanes, `release-assets`, and the container build (`image-release`). All CI lives in that one workflow so every publishing job can depend on every lane. +- `ci-go:1.26` — the `go`, `integration` and `web` lanes, and the container build and public release (`image-release`). All CI lives in that one workflow so every publishing job can depend on every lane. - `golang:1.26-bookworm` (Docker Hub) — the `govulncheck` lane. Deliberately the same image as the Dockerfile's builder stage rather than `ci-go`, so the standard library it checks is the one in the shipped binary. Keep the two in step. - `ci-android:36` — native Kotlin/Compose client: ktlint + detekt + unit tests (the `android` lane), and the signed release APK (`android-release`). @@ -28,7 +28,7 @@ while pulling `ci-android:36`, per the label/image split below. - **golangci-lint** — lint pass in the `go` lane. - **docker CLI** — bridge-IP discovery of the per-job Postgres service container in the `integration` lane (via the runner's shared `/var/run/docker.sock`). - **docker buildx** — release container build + push in `release.yml`. -- **curl** — release-asset polling / upload in `release.yml`. +- **git, perl, node** — the public release in `image-release`: `git archive` for the export, `ci/leakgate.sh` (perl joins comment lines), `ci/releases.mjs` (node's fetch) for the release pages on GitHub and this forge. ### From `ci-android:36` - **JDK 25** — Gradle launcher + Android build. Requires Gradle 9.1.0+ in @@ -41,8 +41,7 @@ while pulling `ci-android:36`, per the label/image split below. the `android` lane. Image pins track `android/gradle/libs.versions.toml` so local and CI checks agree. - **git** — `actions/checkout@v4` baseline (and any shell git operations). -- **base64 + curl** — keystore decode + release-asset upload in `release.yml`'s - `android-release` job. +- **base64** — keystore decode in `release.yml`'s `android-release` job. ## Per-job tool installs @@ -53,7 +52,8 @@ None. - **Label/image split.** Workflows keep `runs-on: go-ci` / `runs-on: flutter-ci` as the scheduling label per the [`ci-runners.md`](https://…/FabledRulebook/ci-runners.md) "label = scheduling handle, image = `container.image`" pattern. The labels are intentional handles, not toolchain assertions — which is why the Android jobs still schedule on `flutter-ci` while pulling `ci-android:36`. Switch them to `android-ci` if that runner label is ever registered; nothing breaks either way. - **Integration-job docker-socket dependency.** The `integration` lane uses the runner's shared docker socket (`/var/run/docker.sock`) to bridge-IP-discover the per-job Postgres service container by name + network intersection — the dev compose's `minstrel-postgres-*` containers are explicitly skipped as belt-and-suspenders. Depends on `act_runner.valid_volumes` whitelisting the socket; if that ever stops auto-mounting, integration tests fail at the `docker inspect` step. - **Go toolchain pin.** `go.mod` is on `go 1.25.0` because `golang.org/x/crypto v0.51.0` declares 1.25 as its minimum. `ci-go:1.26` satisfies this with headroom. Future `x/crypto` bumps that move the Go floor should be paired with an image-tag bump in this file + the workflows. -- **In-app update channel — `needs:`, not polling.** `release.yml`'s `image-release` job declares `needs: [android-release]`, so on dev and tag pushes the signed APK is guaranteed present before the image build starts — no polling window, no race. On `main` pushes `android-release` is skipped and `image-release` instead pulls the most recent release's APK and the version sidecar recorded beside it, so `:latest` never ships without an update channel. It degrades to an empty `client/` — never a wrong version — if no release or APK asset can be resolved. +- **In-app update channel — `needs:`, not polling.** `release.yml`'s `image-release` job declares `needs: [android-release]`, so on dev and main pushes the signed APK built from the same commit is guaranteed present before the image build starts — no polling window, no race. No APK is attached to any release page; phones get the app from the server image. +- **Public release secrets.** `PUBLIC_PUSH_TOKEN` (push to github.com/Fabled-Sword/minstrel and create its releases), `GHCR_USER` and `GHCR_TOKEN` (push to ghcr.io/fabled-sword/minstrel), and `CI_TOKEN` (this forge's release page). A dev push warns when one is missing; a main push stops before anything is pushed. - **Cache server reachability.** The `web` lane does NOT use `cache: 'npm'` on `actions/setup-node` — the Gitea Actions cache server isn't reachable from this runner's container network, so `setup-node` would spend minutes on ETIMEDOUT before failing open. `setup-node` is not used at all (Node is in the image). The cache concern reappears if a change introduces a network-dependent action. - **Artifacts — stock `actions/upload-artifact@v7` and `actions/download-artifact@v8`; never `@v3`.** ```yaml diff --git a/ci/changelog-skip.txt b/ci/changelog-skip.txt new file mode 100644 index 00000000..aa324fc1 --- /dev/null +++ b/ci/changelog-skip.txt @@ -0,0 +1,3 @@ +# Commits ci/changelog.sh leaves out of the public changelog, one full hash per +# line, each with a comment saying why. For a subject that names something that +# must not be published; the private changelog still lists it. diff --git a/ci/changelog.sh b/ci/changelog.sh new file mode 100755 index 00000000..52aa0b17 --- /dev/null +++ b/ci/changelog.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash +# +# A release's changelog, in the two versions a release publishes: +# +# private.md every commit subject since the previous release, as written +# public.md the same list with record ids cut out ("(#1234)", "rule 12"), +# and the commits that only touch CI or tests left out, since +# neither ships +# +# The previous release is the newest public-release tag (v, from +# PUBLIC_SINCE on) that is not on the commit being released. With none, this is +# the first public release, and both versions are a fixed note rather than the +# whole history before it. +# +# PUBLIC_SINCE exists because this repository also holds older v* tags, from +# releases made on this forge alone before the public ones began. Those are not +# public releases, so a changelog never counts from them. +# +# A commit whose subject must not reach the public list (it names something +# private) is left out by listing its full hash in changelog-skip.txt. The +# subject itself is never rewritten: the history is not. +# +# Usage: ci/changelog.sh [] (default HEAD; needs the +# full history and tags, fetch-depth: 0) +set -euo pipefail + +readonly PUBLIC_SINCE='v2026.12.04' + +out="${1:?usage: $0 []}" +ref="${2:-HEAD}" +here="$(cd "$(dirname "$0")" && pwd)" +mkdir -p "$out" + +head="$(git rev-parse "$ref^{commit}")" +previous="" +for tag in $(git tag -l 'v*' --sort=-v:refname); do + # sort -V puts the older of the two first. + if [ "$(printf '%s\n%s\n' "$PUBLIC_SINCE" "$tag" | sort -V | head -1)" != "$PUBLIC_SINCE" ]; then + break + fi + if [ "$(git rev-parse "$tag^{commit}")" != "$head" ]; then + previous="$tag" + break + fi +done + +if [ -z "$previous" ]; then + note='The first public release of Fabled Minstrel, a self-hosted music server with its own Android app. The README says what it does and how to run it.' + printf '%s\n' "$note" >"$out/private.md" + printf '%s\n' "$note" >"$out/public.md" + echo "changelog: first release, the fixed note" + exit 0 +fi + +subjects="$(git log --no-merges --reverse --format='%H %s' "$previous..$head")" + +{ + printf 'Changes since %s:\n\n' "$previous" + printf '%s\n' "$subjects" | sed -E '/^$/d; s/^[0-9a-f]+ /- /' +} >"$out/private.md" + +skip="$(grep -oE '^[0-9a-f]{40}' "$here/changelog-skip.txt" || true)" +{ + printf 'Changes since %s:\n\n' "$previous" + printf '%s\n' "$subjects" | while IFS=' ' read -r hash subject; do + [ -n "$hash" ] || continue + if printf '%s\n' "$skip" | grep -qx "$hash"; then continue; fi + # The area before the colon, as a list: "server, web, ci". A type with a + # scope, "test(web)", counts by its type. + area="${subject%%:*}" + if [ "$area" != "$subject" ] && + ! printf '%s\n' "$area" | sed -E 's/\(.*\)//' | tr ',' '\n' | sed -E 's/^ +| +$//g' | + grep -qvxE 'ci|tests?|[a-z]+ tests?'; then + continue + fi + printf -- '- %s\n' "$subject" + done | sed -E ' + s/ *\(((rule|preference|lesson|snippet|process|milestone|task|issue) )?#?[0-9]+(, *#?[0-9]+)*\)//gI + s/ *\b(rule|preference|lesson|snippet|process|milestone|task|issue) #?[0-9]+//gI + s/ *#[0-9]{3,5}\b//g + s/ *\( *\)//g + s/ +([,;.])/\1/g + s/[,;] *$//' +} >"$out/public.md" + +echo "changelog: $(grep -c '^- ' "$out/private.md" || true) commits since $previous, $(grep -c '^- ' "$out/public.md" || true) public" diff --git a/ci/leak-allow.txt b/ci/leak-allow.txt new file mode 100644 index 00000000..91de4a7e --- /dev/null +++ b/ci/leak-allow.txt @@ -0,0 +1,20 @@ +# Known false positives of ci/leakgate.sh, one extended regex per line, matched +# without regard to case. Each is cut out of a hit line before the line is +# tested again, so keep a pattern as narrow as the thing it allows. + +# Words that contain a banned one. +jsonarray +readarray + +# Drawing paths: SVG d attributes, Android pathData, and the path strings the +# web and Android icon sets keep, all of which start with a moveto, "M12". +d="[^"]*"? +pathdata="[^"]*"? +'M[0-9][^']*' +# The continuation lines of a long drawing path: numbers and path commands only. +^[-0-9 .,cmlzhvsqta]+$ + +# Material 3, the Android design system, in comments about its defaults. +\bM3('s)?\b +# CSS colours in hex, written as design tokens. +--[a-z-]+: [#][0-9a-f]{3,6}; diff --git a/ci/leakgate.sh b/ci/leakgate.sh new file mode 100755 index 00000000..abf3b1e0 --- /dev/null +++ b/ci/leakgate.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash +# +# The automatic half of the leak standard, run on what a public release would +# publish: the exported tree and the public changelog. Two kinds of hit fail it: +# +# words that must never ship the names of tools and services this project +# has nothing to do with in public +# private record ids "#1234", "rule 12", "milestone 7": pointers into +# a tracker no reader of the release can open +# +# The ids are also searched with comment continuation lines joined, because a +# citation split at a line break ("see rule\n// 12") passes a per-line search. +# +# The by-eye half (people, titles, quotes, images) is not here: a search cannot +# decide it. +# +# Known false positives are listed in leak-allow.txt, one pattern per line. A +# pattern is cut out of a hit line before the line is tested again, so an +# allowed word never hides a real hit beside it. +# +# Usage: ci/leakgate.sh ... (directories are searched recursively) +# Prints each hit and exits 1 if there is one. +set -euo pipefail + +readonly HARD='sluice|storehouse|prospector|bookbag|musicbox|fabledexchange|lidarr|readarr|chaptarr|prowlarr|jackett|sonarr|radarr|qbittorrent|deluge|sabnzbd|nzbget|slskd|soulseek|deemix|torrent|usenet|\bnzb\b|magnet:|grimoire|\bscribe\b|traefik\.internal|vdnt' +readonly IDS='(\(|\s)#[0-9]{3,5}\b|\bM[0-9]{1,3}\b|\b(rule|preference|lesson|snippet|process|milestone) #?[0-9]{1,5}\b' +# Joined across comment lines, only the worded citations: the bare forms above +# are already whole on one line. +readonly JOINED='\b(?:rule|preference|lesson|snippet|process|milestone|task|issue)\s+#?\d{1,5}\b|\b(?:reference|measured)\s+library\b' + +[ "$#" -gt 0 ] || { echo "usage: $0 ..." >&2; exit 2; } + +here="$(cd "$(dirname "$0")" && pwd)" +strip="$(mktemp)" +trap 'rm -f "$strip"' EXIT +# One sed substitution per allowed pattern, case-insensitive like the search. +# \x01 delimits, so a pattern may hold any other character. +while IFS= read -r pattern; do + case "$pattern" in '' | '#'*) continue ;; esac + printf 's\x01%s\x01\x01gI\n' "$pattern" >>"$strip" +done <"$here/leak-allow.txt" + +# Reads grep's path:line:text and prints the hits that still match once the +# allowed patterns are cut out of the text. +still() { + local hit text + while IFS= read -r hit; do + text="${hit#*:*:}" + if printf '%s\n' "$text" | sed -E -f "$strip" | grep -qiE -- "$1"; then + printf '%s\n' "$hit" + fi + done +} + +found="$( + { + grep -rnHIiE -- "$HARD" "$@" || true + grep -rnHIiE -- "$IDS" "$@" || true + } | still "$HARD|$IDS" + # -I skips binary files, as grep does above. Each joined hit is printed as + # path:joined:text, so the same filter applies. + find "$@" -type f -exec grep -lIZ '' {} + 2>/dev/null \ + | xargs -0 -r perl -0777 -ne ' + s/\n[ \t]*(?:\/\/+|--|\*|#+)[ \t]*/ /g; + while (/('"$JOINED"')/gi) { (my $m = $1) =~ s/\s+/ /g; print "$ARGV:joined:$m\n" }' \ + | still "$(printf '%s' "$JOINED" | sed -E 's/\(\?:/(/g; s/\\s/[[:space:]]/g; s/\\d/[0-9]/g')" +)" + +if [ -n "$found" ]; then + printf '%s\n' "$found" | sort -u + echo "leakgate: the hits above would be published; reword them, or list a false positive in ci/leak-allow.txt" >&2 + exit 1 +fi +echo "leakgate: clean" diff --git a/ci/release_test.go b/ci/release_test.go new file mode 100644 index 00000000..8b63fe06 --- /dev/null +++ b/ci/release_test.go @@ -0,0 +1,175 @@ +package ci + +import ( + "os" + "os/exec" + "path/filepath" + "strings" + "testing" +) + +// leakgate runs leakgate.sh over one file holding text, and says whether it +// passed. +func leakgate(t *testing.T, text string) (bool, string) { + t.Helper() + dir := t.TempDir() + if err := os.WriteFile(filepath.Join(dir, "f.go"), []byte(text), 0o644); err != nil { + t.Fatal(err) + } + out, err := exec.Command("bash", "leakgate.sh", dir).CombinedOutput() + return err == nil, string(out) +} + +// The gate fails on a banned word or a private record id, wherever it sits on +// the line, and passes the known false positives. +func TestTheLeakGateRefusesWhatMustNotBePublished(t *testing.T) { + for _, c := range []struct{ name, text string }{ + {"a banned word", "// a folder some downloader called Lidarr made\n"}, + {"a banned word in a fixture path", `{".sluice-held/Artist/01.flac", true},` + "\n"}, + {"a banned word beside an allowed one", "var list JsonArray // the torrent's files\n"}, + {"a ticket", "// fixed in (#4321)\n"}, + {"a worded citation", "// as milestone 635 decided\n"}, + {"a short milestone id", "// added in m7-scan-progress\n"}, + {"a citation split across comment lines", "// as the rule\n// 12 says\n"}, + {"a library measured, split across lines", "// counted on the reference\n// library\n"}, + {"an id beside a drawing path", " see rule 9\n"}, + {"an id beside Material 3", "// M3's default, as M12 chose\n"}, + } { + if passed, out := leakgate(t, c.text); passed { + t.Errorf("%s: passed %q\n%s", c.name, c.text, out) + } + } +} + +func TestTheLeakGatePassesItsKnownFalsePositives(t *testing.T) { + text := strings.Join([]string{ + "import kotlinx.serialization.json.JsonArray", + ``, + `android:pathData="M17,3H7c-1.1,0 -1.99,0.9 -1.99,2L5,21z" />`, + `back: 'M15 5l-7 7 7 7',`, + "97 -322 147 -488 125z m928 -812 c53 -27 39 -34", + "// M3 inactive default is secondaryContainer; drops M3's stop", + `expect(css).toMatch(/--fs-obsidian: #000;[\s\S]*--fs-parchment: #FFF;/);`, + "// a song called the rule of three is fine", + }, "\n") + "\n" + if passed, out := leakgate(t, text); !passed { + t.Errorf("refused a known false positive:\n%s", out) + } +} + +// repo makes a git repository whose commits carry the given subjects, and +// returns its path. +func repo(t *testing.T, subjects ...string) string { + t.Helper() + dir := t.TempDir() + git(t, dir, "init", "-q", "-b", "main") + for _, s := range subjects { + commit(t, dir, s) + } + return dir +} + +// commit makes one commit with the given subject, changing a file so that it +// is never empty. +func commit(t *testing.T, dir, subject string) { + t.Helper() + if err := os.WriteFile(filepath.Join(dir, "f"), []byte(subject), 0o644); err != nil { + t.Fatal(err) + } + git(t, dir, "add", "f") + git(t, dir, "commit", "-q", "-m", subject) +} + +func git(t *testing.T, dir string, args ...string) string { + t.Helper() + cmd := exec.Command("git", append([]string{"-c", "user.name=t", "-c", "user.email=t@example.com"}, args...)...) + cmd.Dir = dir + cmd.Env = append(os.Environ(), "GIT_CONFIG_GLOBAL=/dev/null", "GIT_CONFIG_SYSTEM=/dev/null") + out, err := cmd.CombinedOutput() + if err != nil { + t.Fatalf("git %v: %v\n%s", args, err, out) + } + return strings.TrimSpace(string(out)) +} + +// changelog runs changelog.sh in dir and returns the private and public lists. +func changelog(t *testing.T, dir string) (string, string) { + t.Helper() + script, err := filepath.Abs("changelog.sh") + if err != nil { + t.Fatal(err) + } + out := t.TempDir() + cmd := exec.Command("bash", script, out) + cmd.Dir = dir + if msg, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("changelog.sh: %v\n%s", err, msg) + } + read := func(name string) string { + b, err := os.ReadFile(filepath.Join(out, name)) + if err != nil { + t.Fatal(err) + } + return string(b) + } + return read("private.md"), read("public.md") +} + +// The first public release has no public release before it, and its changelog +// is the fixed note rather than every commit the project ever made. A v* tag +// from before the public releases began is not a public release, so it does +// not count as one. +func TestTheFirstReleaseIsAFixedNote(t *testing.T) { + dir := repo(t, "library: the first commit") + git(t, dir, "tag", "v2026.10.26.1520") + commit(t, dir, "web: after the forge-only release") + private, public := changelog(t, dir) + if private != public || strings.Contains(public, "web:") || !strings.Contains(public, "first public release") { + t.Errorf("private %q, public %q: want the same fixed note", private, public) + } +} + +// A later release lists what changed since the previous one. The public list +// loses its record ids and the commits that only touch CI or tests. +func TestALaterReleaseListsWhatChangedSinceThePrevious(t *testing.T) { + dir := repo(t, "library: before the release") + git(t, dir, "tag", "v2026.12.05.0000") + for _, s := range []string{ + "fix(library): a song keeps its title (#4321)", + "web, ci: a page and its lane (rule 12, #77)", + "ci: a faster lane", + "test(web): one test fewer", + "web tests: one more", + "server, tests: a route, as milestone 635 asks", + } { + commit(t, dir, s) + } + + private, public := changelog(t, dir) + if strings.Contains(private, "before the release") { + t.Errorf("the private list reaches past the previous release:\n%s", private) + } + if !strings.Contains(private, "(#4321)") || !strings.Contains(private, "- ci: a faster lane") { + t.Errorf("the private list is not as written:\n%s", private) + } + want := "Changes since v2026.12.05.0000:\n\n" + + "- fix(library): a song keeps its title\n" + + "- web, ci: a page and its lane\n" + + "- server, tests: a route, as asks\n" + if public != want { + t.Errorf("public list:\n%s\nwant:\n%s", public, want) + } +} + +// A re-run of a release finds its own tag on the commit, and lists from the +// release before it. +func TestARerunListsFromTheReleaseBefore(t *testing.T) { + dir := repo(t, "library: before") + git(t, dir, "tag", "v2026.12.05.0000") + commit(t, dir, "web: after") + git(t, dir, "tag", "v2026.12.06.0000") + _, public := changelog(t, dir) + if !strings.Contains(public, "since v2026.12.05.0000") || !strings.Contains(public, "- web: after") { + t.Errorf("re-run list:\n%s", public) + } +} diff --git a/ci/releases.mjs b/ci/releases.mjs new file mode 100644 index 00000000..076d725c --- /dev/null +++ b/ci/releases.mjs @@ -0,0 +1,106 @@ +// Creates a release's page on a forge, or updates it in place when the run is +// repeated, so a re-run never fails on the release it made the first time. +// +// node ci/releases.mjs github +// the public repository's GitHub Release, with PUBLIC_PUSH_TOKEN. The tag +// must already be pushed there. +// node ci/releases.mjs forge +// this repository's release on its own forge, with FORGE_TOKEN, tagging +// when the tag does not exist yet. +// node ci/releases.mjs forge-probe +// whether FORGE_TOKEN may write releases, without writing one: an update +// of a release that does not exist answers 404 to a token that may, and +// 403 to one that may not. +// +// Prints the release's page. +import { readFileSync } from 'node:fs'; + +const PUBLIC_REPO = 'Fabled-Sword/minstrel'; + +const [kind, tag, bodyFile, commit] = process.argv.slice(2); + +function need(name) { + const value = process.env[name]; + if (!value) throw new Error(`${name} is empty or unset`); + return value; +} + +async function call(method, url, headers, body) { + const res = await fetch(url, { + method, + headers: { 'Content-Type': 'application/json', ...headers }, + body: body === undefined ? undefined : JSON.stringify(body) + }); + const text = await res.text(); + return { status: res.status, json: text ? safeJSON(text) : null, text }; +} + +function safeJSON(text) { + try { + return JSON.parse(text); + } catch { + return null; + } +} + +function ok(res, what) { + if (res.status < 200 || res.status >= 300) { + throw new Error(`${what}: HTTP ${res.status} ${res.text.slice(0, 300)}`); + } + return res.json; +} + +// The same steps on either forge: find the release by its tag, then update it +// or create it. +async function upsert(api, headers, fields) { + const found = await call('GET', `${api}/releases/tags/${encodeURIComponent(tag)}`, headers); + if (found.status === 200) { + return ok(await call('PATCH', `${api}/releases/${found.json.id}`, headers, fields), 'update'); + } + if (found.status !== 404) ok(found, 'look up'); + return ok(await call('POST', `${api}/releases`, headers, { tag_name: tag, ...fields }), 'create'); +} + +async function main() { + if (kind === 'forge-probe') { + const res = await call( + 'PATCH', + `${need('GITHUB_SERVER_URL')}/api/v1/repos/${need('GITHUB_REPOSITORY')}/releases/0`, + { Authorization: `token ${need('FORGE_TOKEN')}` }, + {} + ); + if (res.status !== 404) throw new Error(`the token may not write releases: HTTP ${res.status} ${res.text.slice(0, 200)}`); + console.log('the forge token may write releases'); + return; + } + if (!tag || !bodyFile) throw new Error('usage: node ci/releases.mjs github|forge []'); + const body = readFileSync(bodyFile, 'utf8'); + const name = `Fabled Minstrel ${tag}`; + let release; + if (kind === 'github') { + release = await upsert( + `https://api.github.com/repos/${PUBLIC_REPO}`, + { + Authorization: `Bearer ${need('PUBLIC_PUSH_TOKEN')}`, + Accept: 'application/vnd.github+json', + 'X-GitHub-Api-Version': '2022-11-28' + }, + { name, body } + ); + } else if (kind === 'forge') { + if (!commit) throw new Error('forge needs the commit to tag'); + release = await upsert( + `${need('GITHUB_SERVER_URL')}/api/v1/repos/${need('GITHUB_REPOSITORY')}`, + { Authorization: `token ${need('FORGE_TOKEN')}` }, + { name, body, target_commitish: commit } + ); + } else { + throw new Error(`unknown forge ${kind}`); + } + console.log(release.html_url); +} + +main().catch((err) => { + console.error(`releases: ${err.message}`); + process.exit(1); +}); diff --git a/internal/server/release_gate_test.go b/internal/server/release_gate_test.go index 5c60a641..6092dd21 100644 --- a/internal/server/release_gate_test.go +++ b/internal/server/release_gate_test.go @@ -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) + } } } diff --git a/internal/server/release_version_test.go b/internal/server/release_version_test.go index 128f8c40..b33e2bf1 100644 --- a/internal/server/release_version_test.go +++ b/internal/server/release_version_test.go @@ -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 + :. 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, : and :dev. (The +// public image on GHCR is the one that carries the release's name.) // -// The regression to guard: a : 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 : 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 : 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, : 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 : 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) }