From e5b3314acd051c650fa7b683bc819997c2fb67ea Mon Sep 17 00:00:00 2001 From: Blake Gentry Date: Mon, 23 Nov 2026 21:05:33 -0600 Subject: [PATCH] release riverui and riverproui from one commit A release takes two rounds. `riverproui`'s `go.sum` needs the hash of a `riverui` zip that exists only once `riverui` is tagged and published, and neither CI nor the River Pro UI image build can resolve a `riverui` version that the module proxy doesn't serve yet. So `riverui` releases first, and a second pull request and tag move `riverproui` to it. Module zips are reproducible, so building the frontend and packaging `riverui` from an export of a commit's tracked files, as the release workflow does, produces the zip that the release will publish. A new script packages the `riverui` version that `riverproui` requires into a directory that Go can use as a `file://` module proxy ahead of `GOPROXY`, and can run a command in `riverproui` against it. It skips versions that are already published, checking riverui's own proxy rather than the public mirror, which would remember the miss for a version about to be released. On an ordinary commit it only makes that check, and the command uses the regular module cache. When it packages a version, the command gets a throwaway module cache, so candidate zips never stay in the regular cache under release version numbers. The frontend build clears `NODE_ENV` and `VITE_` variables, which Vite would otherwise bake into the bundle. `make release/prepare` sets `riverproui`'s `riverui` requirement to `$VERSION` and writes its `go.sum` lines with a `go mod tidy` against the candidate proxy. `make release/verify` builds `riverproui` against it, so a `riverui` change after the hashes were written fails with a checksum mismatch. CI and the River Pro UI image build package the candidate in a new job that has no secrets and only reads the repository, because packaging runs npm. On an ordinary commit that job only checks that the version is published and skips Node.js. Otherwise it uploads the candidate as an artifact. The River Pro UI CI job downloads `riverproui`'s dependencies through it, which verifies the candidate against the committed `go.sum` before any of its code builds. The image build passes it to the Dockerfile as a named build context, which is empty by default, for the same verified download. The release workflow needs no change: each tag's run packages only its own module from the tagged commit and never resolves `riverproui`'s dependencies, so both tags can point at the same commit. The release instructions now describe the one-commit flow, with `make release/verify` run on the merged commit before tagging. --- .github/workflows/ci.yaml | 68 ++++++++++++++++- .github/workflows/docker-riverproui.yaml | 78 ++++++++++++++++++-- Dockerfile.pro | 10 ++- Makefile | 20 +++++ docs/development.md | 57 ++++----------- packager/build-candidate-proxy.sh | 93 ++++++++++++++++++++++++ 6 files changed, 277 insertions(+), 49 deletions(-) create mode 100755 packager/build-candidate-proxy.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index db755f49..8f17e43f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -80,11 +80,67 @@ jobs: - name: Test run: make test/race SKIP_SUBMODULES=./riverproui + # A release commit's riverproui requires a riverui version that's published + # only once the commit is tagged. Package it from this commit into a module + # proxy for the River Pro UI job. Packaging runs npm, so this job has no + # secrets. + riverui_candidate: + name: Package riverui candidate + runs-on: ubuntu-latest + timeout-minutes: 5 + outputs: + unpublished: ${{ steps.check.outputs.unpublished }} + permissions: + contents: read + + steps: + - name: Checkout repository + uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + + - name: Setup Go + uses: actions/setup-go@v7 + with: + cache: false + go-version-file: packager/go.mod + + # The script makes the same check. It's repeated here so that ordinary + # commits skip Node.js. + - name: Check for an unpublished riverui requirement + id: check + run: | + version="$(awk '$1 == "riverqueue.com/riverui" { print $2 }' riverproui/go.mod)" + GOPROXY=direct GOSUMDB=off go list -m "riverqueue.com/riverui@$version" || echo "unpublished=true" >> "$GITHUB_OUTPUT" + + - name: Install Node.js + if: steps.check.outputs.unpublished == 'true' + uses: actions/setup-node@v7 + with: + check-latest: true + node-version: "24" + + - name: Package riverui + if: steps.check.outputs.unpublished == 'true' + run: ./packager/build-candidate-proxy.sh "$RUNNER_TEMP/candidate-proxy" + + - name: Upload riverui candidate + if: steps.check.outputs.unpublished == 'true' + uses: actions/upload-artifact@v7 + with: + if-no-files-found: error + name: riverui-candidate + path: ${{ runner.temp }}/candidate-proxy + # Downloads River Pro modules with the River Pro credential, so it only # restores caches. Saving would put River Pro modules into caches shared # with other workflow runs. riverproui: name: River Pro UI build, test, and lint + needs: riverui_candidate + # Run even if the candidate job failed. A skipped job would satisfy this + # required check; without the candidate, a release commit fails below. + if: ${{ !cancelled() }} runs-on: ubuntu-latest timeout-minutes: 5 env: @@ -120,9 +176,19 @@ jobs: go-version: "1.26" save-build-cache: "false" + - name: Download riverui candidate + if: needs.riverui_candidate.outputs.unpublished == 'true' + uses: actions/download-artifact@v8 + with: + name: riverui-candidate + path: ${{ runner.temp }}/candidate-proxy + + # The download verifies the candidate against riverproui's go.sum before + # any of its code builds, so a go.sum that doesn't match this commit's + # riverui fails here. Later steps use the downloaded modules. - name: Install River Pro UI dependencies working-directory: ./riverproui - run: go mod download + run: GOPROXY="file://$RUNNER_TEMP/candidate-proxy,$GOPROXY" go mod download - name: Install River Pro CLI run: go install riverqueue.com/riverpro/cmd/riverpro@latest diff --git a/.github/workflows/docker-riverproui.yaml b/.github/workflows/docker-riverproui.yaml index d7c516f6..1ab8f1ed 100644 --- a/.github/workflows/docker-riverproui.yaml +++ b/.github/workflows/docker-riverproui.yaml @@ -33,11 +33,68 @@ env: ECR_REGION: us-east-2 jobs: + # A release commit's riverproui requires a riverui version that's published + # only once the commit is tagged. Package it from this commit into a module + # proxy for the image build, which passes it to Dockerfile.pro. Packaging + # runs npm, so this job has no secrets. + riverui-candidate: + name: Package riverui candidate + runs-on: ubuntu-latest + timeout-minutes: 5 + outputs: + unpublished: ${{ steps.check.outputs.unpublished }} + permissions: + contents: read + + steps: + - name: Checkout + uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + ref: ${{ inputs.ref || github.ref }} + + - name: Setup Go + uses: actions/setup-go@v7 + with: + cache: false + go-version-file: packager/go.mod + + # The script makes the same check. It's repeated here so that ordinary + # commits skip Node.js. + - name: Check for an unpublished riverui requirement + id: check + run: | + version="$(awk '$1 == "riverqueue.com/riverui" { print $2 }' riverproui/go.mod)" + GOPROXY=direct GOSUMDB=off go list -m "riverqueue.com/riverui@$version" || echo "unpublished=true" >> "$GITHUB_OUTPUT" + + - name: Install Node.js + if: steps.check.outputs.unpublished == 'true' + uses: actions/setup-node@v7 + with: + check-latest: true + node-version: "24" + + - name: Package riverui + if: steps.check.outputs.unpublished == 'true' + run: ./packager/build-candidate-proxy.sh "$RUNNER_TEMP/candidate-proxy" + + - name: Upload riverui candidate + if: steps.check.outputs.unpublished == 'true' + uses: actions/upload-artifact@v7 + with: + if-no-files-found: error + name: riverui-candidate + path: ${{ runner.temp }}/candidate-proxy + build-riverproui: name: "Build image: riverproui (${{ matrix.docker_platform }})" + needs: riverui-candidate runs-on: ${{ matrix.runner }} - # Skip this job when manually dispatched with verify_only=true - if: ${{ !(github.event_name == 'workflow_dispatch' && inputs.verify_only) }} + # Skip this job when manually dispatched with verify_only=true. Otherwise + # run even if the candidate job failed: a skipped job would leave this + # required check unreported, and without the candidate, a release commit + # fails in the image build. + if: ${{ !cancelled() && !(github.event_name == 'workflow_dispatch' && inputs.verify_only) }} env: ECR_ACCOUNT_ID: ${{ secrets.ECR_CACHE_AWS_ACCOUNT_ID }} ECR_ROLE_ARN: ${{ secrets.ECR_CACHE_ROLE_ARN }} @@ -58,6 +115,13 @@ jobs: with: ref: ${{ inputs.ref || github.ref }} + - name: Download riverui candidate + if: needs.riverui-candidate.outputs.unpublished == 'true' + uses: actions/download-artifact@v8 + with: + name: riverui-candidate + path: ${{ runner.temp }}/candidate-proxy + - name: Build metadata id: build_metadata run: | @@ -100,6 +164,7 @@ jobs: with: context: . file: Dockerfile.pro + build-contexts: ${{ needs.riverui-candidate.outputs.unpublished == 'true' && format('candidate-proxy={0}/candidate-proxy', runner.temp) || '' }} build-args: | BUILD_VERSION=${{ steps.build_metadata.outputs.version }} BUILD_REVISION=${{ steps.build_metadata.outputs.revision }} @@ -134,8 +199,10 @@ jobs: runs-on: ubuntu-latest needs: - build-riverproui - # Skip this job when manually dispatched with verify_only=true - if: ${{ !(github.event_name == 'workflow_dispatch' && inputs.verify_only) }} + # Skip this job when manually dispatched with verify_only=true. A failed + # candidate job would otherwise skip this job even after the image builds + # pass, so check the image builds' result directly. + if: ${{ !cancelled() && needs.build-riverproui.result == 'success' && !(github.event_name == 'workflow_dispatch' && inputs.verify_only) }} permissions: contents: read id-token: write @@ -374,7 +441,8 @@ jobs: # Only run on release tag events (refs/tags/riverproui/vX.Y.Z), # or when manually forced via workflow_dispatch: force_prefetch=true. # For workflow_dispatch, inputs.ref should be in the form 'riverproui/vX.Y.Z'. - if: startsWith(github.ref, 'refs/tags/riverproui/v') || (github.event_name == 'workflow_dispatch' && (startsWith(inputs.ref, 'riverproui/v') || inputs.force_prefetch)) + # As above, this depends on the merge job's result, not the candidate job's. + if: ${{ !cancelled() && needs.merge-riverproui.result == 'success' && (startsWith(github.ref, 'refs/tags/riverproui/v') || (github.event_name == 'workflow_dispatch' && (startsWith(inputs.ref, 'riverproui/v') || inputs.force_prefetch))) }} permissions: contents: read steps: diff --git a/Dockerfile.pro b/Dockerfile.pro index 75c26eb4..441d7dd3 100644 --- a/Dockerfile.pro +++ b/Dockerfile.pro @@ -1,5 +1,10 @@ # syntax=docker/dockerfile:1 +# A release commit's riverproui requires a riverui version that's published +# only once the commit is tagged. CI packages it with +# packager/build-candidate-proxy.sh and passes it in place of this empty stage. +FROM scratch AS candidate-proxy + FROM node:24.21.0-alpine@sha256:ebfe2f90462722a7a4de65e91990e97fe0d401c70e0e762c5b53302f905ec1c1 AS build-ui WORKDIR /app COPY .npmrc package.json package-lock.json ./ @@ -22,8 +27,9 @@ RUN go mod download # Download riverproui module dependencies with secret COPY riverproui/go.mod riverproui/go.sum ./riverproui/ WORKDIR /go/src/riverui/riverproui -RUN --mount=type=secret,id=riverpro_credential,dst=/etc/secrets/riverpro_credential \ - sh -c 'GOPROXY=https://proxy.golang.org,https://u:$(cat /etc/secrets/riverpro_credential)@riverqueue.com/goproxy,direct \ +RUN --mount=type=bind,from=candidate-proxy,target=/candidate-proxy \ + --mount=type=secret,id=riverpro_credential,dst=/etc/secrets/riverpro_credential \ + sh -c 'GOPROXY=file:///candidate-proxy,https://proxy.golang.org,https://u:$(cat /etc/secrets/riverpro_credential)@riverqueue.com/goproxy,direct \ go mod download' # Return to main directory and copy Go files without copying the ui dir: diff --git a/Makefile b/Makefile index a0877854..c411e910 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,26 @@ check/modzip: ## Check that released Go module zips include only Go source, modu go run . -check $(if $(filter true,$(MODZIP_REQUIRE_FRONTEND)),-require-frontend) -dir "$$export_dir"; \ go run . -check -dir "$$export_dir/riverproui" +# Where the release targets package the riverui version that riverproui +# requires, if it isn't published yet. The script explains why. +CANDIDATE_PROXY ?= $(abspath $(or $(TMPDIR),/tmp)/riverui-candidate-proxy) + +# riverproui's riverui go.sum lines come from a `go mod tidy` against the +# candidate proxy, after dropping the old ones so that a rerun after a change +# replaces them. +.PHONY: release/prepare +release/prepare: ## Set riverproui's riverui requirement to $VERSION and write its go.sum + @test -n "$(VERSION)" || { echo "VERSION is required, like VERSION=v1.2.3" >&2; exit 1; } + cd riverproui && go mod edit -require=riverqueue.com/riverui@$(VERSION) + cd riverproui && grep -v '^riverqueue\.com/riverui ' go.sum > go.sum.new && mv go.sum.new go.sum + ./packager/build-candidate-proxy.sh "$(CANDIDATE_PROXY)" go mod tidy + +# Run this before pushing release tags. CI makes the same check in two jobs, so +# that the one that builds the frontend has no secrets. +.PHONY: release/verify +release/verify: ## Check riverproui's go.sum by building it against the riverui in this commit + @./packager/build-candidate-proxy.sh "$(CANDIDATE_PROXY)" go build ./... + .PHONY: dev dev: fake_assets npm run dev diff --git a/docs/development.md b/docs/development.md index b3a9f52a..3f3a6805 100644 --- a/docs/development.md +++ b/docs/development.md @@ -79,7 +79,11 @@ $ npm run build ## Releasing a new version -1. Fetch changes to the repo and any new tags. Export `VERSION` by incrementing the last tag: +The `riverui` module and the `riverproui` submodule release from one commit. In that commit `riverproui`'s `go.mod` requires the `riverui` version being released, and its `go.sum` holds the hash of a `riverui` zip that's published only once the commit is tagged. Module zips are reproducible, so `make release/prepare` builds the frontend and packages `riverui` locally the way the release workflow does, and writes the hash from that zip. CI packages `riverui` again from the pull request's commit and downloads `riverproui`'s dependencies through it, so a `go.sum` that doesn't match fails with a `checksum mismatch`. `make release/verify` makes the same check locally. + +Building the frontend needs the Node.js version that `package.json` requires. + +1. Fetch changes to the repo and any new tags. Export `VERSION` by incrementing the last tag, and start a branch: ```shell git checkout master && git pull --rebase @@ -87,55 +91,26 @@ $ npm run build git checkout -b $USER-$VERSION ``` -2. Prepare a PR with the changes, updating `CHANGELOG.md` with any necessary additions at the same time. Have it reviewed and merged. - -3. Upon merge, pull down the changes, tag the main riverui module with the new version, and push the new tag: +2. Update `CHANGELOG.md`. Make sure the `replace` directive for `riverui` in `./riverproui/go.mod` is commented out, because it prevents `riverproui` from being `go install`-able. Then set `riverproui`'s `riverui` requirement to `$VERSION` and write its `go.sum`: ```shell - git pull origin master - git tag $VERSION - git push --tags + make release/prepare ``` -4. The build will cut a new release and create binaries automatically, but it won't have a good release message. Go the [release list](https://github.com/riverqueue/riverui/releases), find `$VERSION` and change the description to the release content in `CHANGELOG.md` (again, the build will have to finish first). - -### Releasing riverproui + The `riverui` zip includes `CHANGELOG.md`, so run this after editing the changelog, and again after any later change to `riverui`'s Go code, frontend, or changelog. Until `$VERSION` is published, `go mod tidy` in `./riverproui` (and `make tidy`) can't find it. -The `riverproui` submodule depends on the top level `riverui` module and in development it is customary to leave a `replace` directive in its `go.mod` so that it can be developed against the live local version. However, this `replace` directive makes it incompatible with `go install ...@latest`. +3. Prepare a PR with the changes. Have it reviewed and merged. If changes to `riverui` merge to `master` after the PR's CI ran, its result is out of date, so wait for CI on `master` before tagging. -As such, we must use a two-phase release for these modules: - -1. Release `riverui` with an initial version (i.e. all the steps above). - -2. Comment out `replace` directives to riverui `./riverproui/go.mod`. These were probably needed for developing the new feature, but need to be removed because they prevent the module from being `go install`-able. - -3. From `./riverproui`, `go get` to upgrade to the main package versions were just released (make sure you're getting `$VERSION` and not thwarted by shenanigans in Go's module proxy): - - ```shell - cd ./riverproui - go get -u riverqueue.com/riverui@$VERSION - ``` - -4. Run `go mod tidy`: - - ```shell - go mod tidy - ``` - -5. Start a new branch and commit changes: - - ``` shell - git checkout -b $USER-$VERSION-pro - ``` - -6. Prepare a PR with the changes. Have it reviewed and merged. - -7. Pull the changes back down, add a tag for `riverproui/$VERSION`, and push it to GitHub: +4. Upon merge, pull down the changes, check `riverproui`'s `go.sum` against the merged commit, then tag both modules and push the tags: ```shell git pull origin master + make release/verify + git tag $VERSION git tag riverproui/$VERSION -m "release riverproui/$VERSION" - git push --tags + git push origin $VERSION riverproui/$VERSION ``` - The main `$VERSION` tag and `riverproui/$VERSION` will point to different commits, and although a little odd, is tolerable. + Run `make release/verify` with no uncommitted changes to tracked files, because it packages them too. If it fails with a `checksum mismatch`, `riverui` changed after `make release/prepare`: don't tag, and rerun `make release/prepare` with the same version in a new PR. + +5. The build will cut a new release and create binaries automatically, but it won't have a good release message. Go the [release list](https://github.com/riverqueue/riverui/releases), find `$VERSION` and change the description to the release content in `CHANGELOG.md` (again, the build will have to finish first). diff --git a/packager/build-candidate-proxy.sh b/packager/build-candidate-proxy.sh new file mode 100755 index 00000000..af0164d5 --- /dev/null +++ b/packager/build-candidate-proxy.sh @@ -0,0 +1,93 @@ +#!/bin/sh +# +# Packages the riverui version that riverproui requires, if it isn't published +# yet, into a directory that Go can use as a module proxy ahead of the real +# ones: +# +# GOPROXY="file://$dir,$GOPROXY" +# +# Usage, from the checkout's root: +# +# packager/build-candidate-proxy.sh [ [...]] +# +# riverui and riverproui release from one commit, so riverproui's go.sum holds +# the hash of a riverui version that's published only after that commit is +# tagged. Module zips are reproducible, so building the frontend and packaging +# riverui from an export of the tracked files, as the release workflow does, +# gives the zip that the release will publish. +# +# A version that's already published is skipped, because its published zip is +# the one that counts. On an ordinary commit it is, and this only asks +# riverui's own module proxy about it. GOPROXY's public mirror isn't asked, +# because it would remember for a while that a version about to be released +# doesn't exist. +# +# A command, like `go build ./...`, runs afterward in riverproui with the +# candidate proxy first in GOPROXY. If anything was packaged, it gets a +# throwaway module cache: the candidate zip must not stay in the regular cache +# under a release version number, and a previous run's zip must not stand in +# for this run's. Otherwise it uses the regular cache, so an ordinary commit +# downloads nothing new. + +set -eu + +if [ $# -lt 1 ]; then + echo "usage: $0 [ [...]]" >&2 + exit 1 +fi + +mkdir -p "$1" +proxy_dir="$(cd "$1" && pwd)" +shift +root="$(pwd)" + +run() { + [ $# -eq 0 ] || (cd "$root/riverproui" && GOPROXY="file://$proxy_dir,$(go env GOPROXY)" "$@") +} + +# A previous run's zip must not stand in for this run's. +rm -rf "$proxy_dir/riverqueue.com" + +version="$(awk '$1 == "riverqueue.com/riverui" { print $2 }' riverproui/go.mod)" + +# Run outside the repository's modules. GOPROXY=direct asks the proxy that +# riverqueue.com names for the module. +if (cd "$proxy_dir" && GOPROXY=direct GOSUMDB=off go list -m "riverqueue.com/riverui@$version" >/dev/null 2>&1); then + echo "riverqueue.com/riverui@$version is published" + run "$@" + exit 0 +fi + +# Include uncommitted changes to tracked files, so this works before the +# release commit exists. `git stash create` prints nothing when there are +# none, and fails when the index is only stale, like after `go mod edit`. +tree="$(git stash create || true)" +tree="${tree:-HEAD}" + +export_dir="$(mktemp -d)" +modcache="$(mktemp -d)" +trap 'rm -rf "$export_dir" "$modcache"' EXIT +git archive "$tree" | tar -x -C "$export_dir" + +# Build the frontend as the release workflow does. Vite reads NODE_ENV and +# VITE_ variables from the environment, which would change the bundle. +( + cd "$export_dir" + unset NODE_ENV $(env | sed -n 's/^\(VITE_[A-Za-z0-9_]*\)=.*/\1/p') + npm ci + npm exec vite build -- --sourcemap false + ./packager/remove-unpackaged-files.sh +) + +echo "packaging riverqueue.com/riverui@$version" +(cd packager && go run . \ + -dir "$export_dir" \ + -mod riverqueue.com/riverui \ + -output "$proxy_dir" \ + -require-frontend \ + -timestamp "$(git log -1 --format=%ct "$tree")" \ + -version "$version") + +# The checksum database doesn't have the unpublished version either. +export GOMODCACHE="$modcache" GOFLAGS=-modcacherw GONOSUMDB="riverqueue.com/riverui,$(go env GONOSUMDB)" +run "$@"