From 78ce185a5bfbbfb9b6e03bd4644563e029e1cadd Mon Sep 17 00:00:00 2001 From: laggu91 Date: Sun, 5 Apr 2026 04:15:20 +0900 Subject: [PATCH 1/2] Preserve Homebrew build metadata in version output The Homebrew formula switched to source builds, but the renderer only passed the semantic version into the Go ldflags. As a result, brew installs reported fallback commit/date values even though release artifacts already had full metadata. This updates the release workflow to resolve the tagged commit and commit timestamp, passes both values into the formula renderer, and adds a regression check for the generated formula so the metadata wiring stays covered in CI. Constraint: Homebrew installs now build from the tagged source tarball instead of shipping unsigned macOS binaries Rejected: Change cmd/version.go defaults | would hide packaging regressions instead of fixing the formula path Confidence: high Scope-risk: narrow Reversibility: clean Directive: Keep Homebrew formula ldflags aligned with GoReleaser version metadata whenever release packaging changes Tested: bash test/render_homebrew_formula.sh Tested: go test ./... Tested: go vet ./... Tested: go build ./... Tested: goreleaser check Not-tested: golangci-lint run (fails in this repo with existing "no go files to analyze" context loading error) --- .github/workflows/ci.yaml | 3 +++ .github/workflows/release.yaml | 4 ++++ scripts/render-homebrew-formula.sh | 17 +++++++++++++--- test/render_homebrew_formula.sh | 31 ++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100755 test/render_homebrew_formula.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b83f3c4..c66d196 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -66,6 +66,9 @@ jobs: - name: Build run: go build -v ./... + - name: Verify Homebrew formula renderer + run: bash test/render_homebrew_formula.sh + - name: Verify GoReleaser config uses: goreleaser/goreleaser-action@v6 with: diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 88ffed3..65e03a1 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -46,6 +46,8 @@ jobs: run: | echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT" echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT" + echo "commit=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + echo "date=$(git show -s --format=%cI HEAD)" >> "$GITHUB_OUTPUT" echo "tarball_url=https://github.com/laggu/git-volume/archive/refs/tags/${GITHUB_REF_NAME}.tar.gz" >> "$GITHUB_OUTPUT" - name: Download source tarball @@ -70,6 +72,8 @@ jobs: scripts/render-homebrew-formula.sh \ "${{ steps.meta.outputs.version }}" \ "${{ steps.checksum.outputs.sha256 }}" \ + "${{ steps.meta.outputs.commit }}" \ + "${{ steps.meta.outputs.date }}" \ "homebrew-tap/Formula/git-volume.rb" rm -f homebrew-tap/Casks/.gitkeep diff --git a/scripts/render-homebrew-formula.sh b/scripts/render-homebrew-formula.sh index c9bacb8..b9dc471 100755 --- a/scripts/render-homebrew-formula.sh +++ b/scripts/render-homebrew-formula.sh @@ -5,7 +5,9 @@ set -euo pipefail VERSION="${1:?version is required}" VERSION="${VERSION#v}" SHA256="${2:?sha256 is required}" -OUTPUT="${3:?output path is required}" +COMMIT="${3:?commit is required}" +DATE="${4:?date is required}" +OUTPUT="${5:?output path is required}" mkdir -p "$(dirname "$OUTPUT")" @@ -20,13 +22,22 @@ class GitVolume < Formula depends_on "go" => :build def install - ldflags = "-s -w -X github.com/laggu/git-volume/cmd.version=#{version}" + ldflags = [ + "-s -w", + "-X github.com/laggu/git-volume/cmd.version=#{version}", + "-X github.com/laggu/git-volume/cmd.commit=${COMMIT}", + "-X github.com/laggu/git-volume/cmd.date=${DATE}", + ].join(" ") system "go", "build", *std_go_args(ldflags: ldflags) end test do - assert_match version.to_s, shell_output("#{bin}/git-volume version") + output = shell_output("#{bin}/git-volume version") + + assert_match version.to_s, output + assert_match "commit: ${COMMIT}", output + assert_match "built: ${DATE}", output end end EOF diff --git a/test/render_homebrew_formula.sh b/test/render_homebrew_formula.sh new file mode 100755 index 0000000..9519c61 --- /dev/null +++ b/test/render_homebrew_formula.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +set -euo pipefail + +PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)" +OUTPUT_DIR="$(mktemp -d)" +OUTPUT_FILE="${OUTPUT_DIR}/git-volume.rb" +VERSION="0.3.1" +SHA256="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" +COMMIT="27836373d30ec5d4b20eaba0fcb32197c13eee4a" +DATE="2026-04-05T02:26:42+09:00" + +cleanup() { + rm -rf "${OUTPUT_DIR}" +} +trap cleanup EXIT + +"${PROJECT_ROOT}/scripts/render-homebrew-formula.sh" \ + "${VERSION}" \ + "${SHA256}" \ + "${COMMIT}" \ + "${DATE}" \ + "${OUTPUT_FILE}" + +grep -F 'url "https://github.com/laggu/git-volume/archive/refs/tags/v0.3.1.tar.gz"' "${OUTPUT_FILE}" +grep -F 'sha256 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"' "${OUTPUT_FILE}" +grep -F -- '-X github.com/laggu/git-volume/cmd.version=#{version}' "${OUTPUT_FILE}" +grep -F -- "-X github.com/laggu/git-volume/cmd.commit=${COMMIT}" "${OUTPUT_FILE}" +grep -F -- "-X github.com/laggu/git-volume/cmd.date=${DATE}" "${OUTPUT_FILE}" +grep -F "assert_match \"commit: ${COMMIT}\", output" "${OUTPUT_FILE}" +grep -F "assert_match \"built: ${DATE}\", output" "${OUTPUT_FILE}" From e15369cd7ed735b74c2f91f2b4044d83880d5aee Mon Sep 17 00:00:00 2001 From: laggu91 Date: Sun, 5 Apr 2026 14:08:57 +0900 Subject: [PATCH 2/2] Avoid regex-sensitive Homebrew metadata assertions The generated Homebrew formula test compared version metadata with assert_match, which treats string inputs as regular expression patterns. ISO8601 build timestamps commonly include '+' timezone offsets, so the check could fail even when the output was correct. Switch the generated test to assert_includes and update the renderer regression script to lock in the literal substring checks suggested in review. Constraint: Homebrew formula tests must safely handle ISO8601 build timestamps emitted by the release workflow Rejected: Escape the generated strings for regex use | more fragile than literal substring assertions for this case Confidence: high Scope-risk: narrow Reversibility: clean Directive: Prefer literal output assertions over regex matching for generated release metadata unless pattern matching is required Tested: bash test/render_homebrew_formula.sh Tested: bash -n scripts/render-homebrew-formula.sh test/render_homebrew_formula.sh Tested: go test ./... Not-tested: go vet ./... (unchanged from prior passing state for this review-only follow-up) Not-tested: goreleaser check (unchanged from prior passing state for this review-only follow-up) --- scripts/render-homebrew-formula.sh | 6 +++--- test/render_homebrew_formula.sh | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/render-homebrew-formula.sh b/scripts/render-homebrew-formula.sh index b9dc471..26cd8ec 100755 --- a/scripts/render-homebrew-formula.sh +++ b/scripts/render-homebrew-formula.sh @@ -35,9 +35,9 @@ class GitVolume < Formula test do output = shell_output("#{bin}/git-volume version") - assert_match version.to_s, output - assert_match "commit: ${COMMIT}", output - assert_match "built: ${DATE}", output + assert_includes output, version.to_s + assert_includes output, "commit: ${COMMIT}" + assert_includes output, "built: ${DATE}" end end EOF diff --git a/test/render_homebrew_formula.sh b/test/render_homebrew_formula.sh index 9519c61..49336de 100755 --- a/test/render_homebrew_formula.sh +++ b/test/render_homebrew_formula.sh @@ -27,5 +27,5 @@ grep -F 'sha256 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde grep -F -- '-X github.com/laggu/git-volume/cmd.version=#{version}' "${OUTPUT_FILE}" grep -F -- "-X github.com/laggu/git-volume/cmd.commit=${COMMIT}" "${OUTPUT_FILE}" grep -F -- "-X github.com/laggu/git-volume/cmd.date=${DATE}" "${OUTPUT_FILE}" -grep -F "assert_match \"commit: ${COMMIT}\", output" "${OUTPUT_FILE}" -grep -F "assert_match \"built: ${DATE}\", output" "${OUTPUT_FILE}" +grep -F "assert_includes output, \"commit: ${COMMIT}\"" "${OUTPUT_FILE}" +grep -F "assert_includes output, \"built: ${DATE}\"" "${OUTPUT_FILE}"