Skip to content

Commit 260bb75

Browse files
joe4devclaude
andcommitted
Pin GoReleaser and gate the generated Homebrew cask in CI
Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a0a8375 commit 260bb75

5 files changed

Lines changed: 164 additions & 6 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,26 @@ jobs:
110110
goreleaser-check:
111111
name: GoReleaser Check
112112
runs-on: ubuntu-latest
113-
timeout-minutes: 10
113+
timeout-minutes: 15
114114
steps:
115115
- name: Checkout code
116116
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
117117

118-
- name: Run GoReleaser check
118+
- name: Set up Go
119+
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
120+
with:
121+
go-version-file: go.mod
122+
cache-dependency-path: go.sum
123+
124+
- name: Install GoReleaser
119125
uses: goreleaser/goreleaser-action@f06c13b6b1a9625abc9e6e439d9c05a8f2190e94 # v7.2.3
120126
with:
121127
distribution: goreleaser
122-
version: "~> v2"
123-
args: check
128+
version-file: .tool-versions
129+
install-only: true
130+
131+
- name: Run GoReleaser check
132+
run: goreleaser check
124133

125134
# `goreleaser check` only validates config syntax, so it cannot see that
126135
# packaging bundled extensions and downloading them have to land
@@ -131,6 +140,39 @@ jobs:
131140
- name: Test release scripts
132141
run: make test-scripts
133142

143+
# Nothing else reads the generated cask before a release publishes it.
144+
# Render it and check what would ship.
145+
- name: Check generated Homebrew cask
146+
run: make check-cask
147+
148+
- name: Upload generated cask
149+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
150+
with:
151+
name: generated-cask
152+
path: dist/homebrew/Casks/lstk.rb
153+
if-no-files-found: error
154+
155+
# The cask cops need Homebrew, absent on the Linux runners. Lints the bytes
156+
# the job above rendered, not a second render that could diverge. Left out of
157+
# `release`'s `needs:` for now, like govulncheck, until it has proven itself.
158+
cask-lint:
159+
name: Cask Lint
160+
runs-on: macos-latest
161+
needs: goreleaser-check
162+
timeout-minutes: 15
163+
steps:
164+
- name: Checkout code
165+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
166+
167+
- name: Download generated cask
168+
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
169+
with:
170+
name: generated-cask
171+
path: dist/homebrew/Casks
172+
173+
- name: Run Homebrew linters
174+
run: make lint-cask
175+
134176
test-unit:
135177
name: Unit Tests
136178
runs-on: ubuntu-latest
@@ -376,7 +418,7 @@ jobs:
376418
uses: goreleaser/goreleaser-action@f06c13b6b1a9625abc9e6e439d9c05a8f2190e94 # v7.2.3
377419
with:
378420
distribution: goreleaser
379-
version: "~> v2"
421+
version-file: .tool-versions
380422
args: release --clean
381423
env:
382424
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

‎.tool-versions‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
golangci-lint 2.9.0
2+
goreleaser 2.18.2

‎Makefile‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ endif
55
BUILD_DIR=bin
66
export CGO_ENABLED=0
77

8-
.PHONY: build clean test test-integration test-scripts lint govulncheck mock-generate otel
8+
.PHONY: build clean test test-integration test-scripts check-cask lint-cask lint govulncheck mock-generate otel
99

1010
# Always invoke `go build` and let Go's build cache handle incrementality; a
1111
# file target on bin/lstk would be skipped when the binary exists, even with
@@ -28,6 +28,12 @@ test-integration: build
2828
test-scripts:
2929
@./scripts/bundled-extensions/test-scripts.sh
3030

31+
check-cask:
32+
@./scripts/check-cask.sh
33+
34+
lint-cask:
35+
@./scripts/lint-cask.sh
36+
3137
otel:
3238
docker compose -f docker-compose.tracing.yaml up -d
3339

‎scripts/check-cask.sh‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
# Render the Homebrew cask and check what a release would publish.
3+
#
4+
# Only a release writes the cask, into a tap with no CI, so a fault reaches
5+
# users as their next `brew install` -- how the deprecated `postflight` stanza
6+
# shipped (localstack/lstk#501, localstack/homebrew-tap#7).
7+
#
8+
# Homebrew's own linters need Homebrew, absent on the Linux runners, so they run
9+
# against this output on macOS -- scripts/lint-cask.sh.
10+
#
11+
# Wipes dist/ and stubs bundled/; both paths come from the config.
12+
13+
set -euo pipefail
14+
15+
cd "$(dirname "$0")/.."
16+
17+
CASK=dist/homebrew/Casks/lstk.rb
18+
19+
if ! command -v goreleaser >/dev/null 2>&1; then
20+
echo "goreleaser required on PATH: https://goreleaser.com/install/" >&2
21+
exit 1
22+
fi
23+
24+
# A different GoReleaser can render a different cask, so the pin is part of the
25+
# artifact's definition.
26+
EXPECTED=$(awk '/^goreleaser/ {print $2}' .tool-versions)
27+
INSTALLED=$(goreleaser --version 2>/dev/null | awk '/GitVersion:/ {print $2}' | sed 's/^v//')
28+
if [ "$INSTALLED" != "$EXPECTED" ]; then
29+
echo "goreleaser $EXPECTED required (found: ${INSTALLED:-none})" >&2
30+
exit 1
31+
fi
32+
33+
# archives.files globs `bundled/`, so an empty tree fails the build. The cask
34+
# ignores the bundle, and the real fetch needs a private-repo token.
35+
scripts/bundled-extensions/fetch-bundled-extensions.sh --stub
36+
37+
goreleaser release --snapshot --clean
38+
39+
[ -f "$CASK" ] || { echo "no cask generated at $CASK" >&2; exit 1; }
40+
41+
fail() { echo "FAIL: $1" >&2; echo "--- $CASK ---" >&2; cat "$CASK" >&2; exit 1; }
42+
43+
# Homebrew warns on every `brew` operation that loads a raw-Ruby flight block.
44+
# Only deprecated spellings match -- `_steps` leaves no trailing ` do` -- and
45+
# indentation is ignored, so a reindent upstream cannot empty the check.
46+
grep -Eq '^[[:space:]]*(uninstall_)?(pre|post)flight do$' "$CASK" &&
47+
fail "cask uses a deprecated raw-Ruby flight stanza; use the *_steps form"
48+
49+
# Our darwin binaries are unsigned, so Gatekeeper kills them unless quarantine
50+
# is cleared. Deleting the hook would satisfy the check above, so assert the
51+
# step survives.
52+
grep -q 'postflight_steps do' "$CASK" ||
53+
fail "cask has no postflight_steps stanza"
54+
grep -q 'com.apple.quarantine' "$CASK" ||
55+
fail "cask no longer clears com.apple.quarantine"
56+
57+
# Homebrew's tokens share GoReleaser's delimiters. An unescaped
58+
# `{{staged_path}}` fails the release; a broken escape emits a literal pointing
59+
# somewhere else.
60+
grep -q '"{{staged_path}}"' "$CASK" ||
61+
fail "quarantine step does not target the whole staged dir"
62+
63+
echo "OK: $CASK"

‎scripts/lint-cask.sh‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
# Run Homebrew's own linters over a generated cask.
3+
#
4+
# check-cask.sh asserts what we know to look for; these cops catch what we did
5+
# not -- `Cask/InstallSteps` is what flags localstack/lstk#501. They need
6+
# Homebrew, absent on the Linux runners, so CI renders there and lints here.
7+
#
8+
# Usage: scripts/lint-cask.sh [path/to/lstk.rb]
9+
10+
set -euo pipefail
11+
12+
cd "$(dirname "$0")/.."
13+
14+
CASK="${1:-dist/homebrew/Casks/lstk.rb}"
15+
16+
[ -f "$CASK" ] || { echo "no cask at $CASK -- run 'make check-cask' first" >&2; exit 1; }
17+
18+
if ! command -v brew >/dev/null 2>&1; then
19+
echo "brew required on PATH: https://brew.sh" >&2
20+
exit 1
21+
fi
22+
23+
export HOMEBREW_NO_AUTO_UPDATE=1
24+
25+
# `brew audit` refuses a bare path, and the cask cops only fire under `Casks/`,
26+
# so this needs a tap. Build a throwaway one and drop it however we exit.
27+
TAP=lstkci/caskcheck
28+
untap() { brew untap "$TAP" >/dev/null 2>&1 || true; }
29+
trap untap EXIT
30+
untap
31+
brew tap-new --no-git "$TAP" >/dev/null
32+
TAP_CASKS="$(brew --repository "$TAP")/Casks"
33+
mkdir -p "$TAP_CASKS"
34+
cp "$CASK" "$TAP_CASKS/lstk.rb"
35+
36+
# TODO(#512): drop --except-cops once hooks.post.install_steps replaces
37+
# custom_block, which renders the stanza first and trips Cask/StanzaOrder on
38+
# everything after it. Scoped to that cop so the deprecation cops still fire.
39+
brew style --except-cops=Cask/StanzaOrder "$TAP_CASKS/lstk.rb"
40+
41+
# Passes on a deprecated stanza, so this guards other faults, not #501. Its
42+
# `--online` form checks urls and checksums, but only the tap has a published
43+
# release to check against.
44+
brew audit --cask "$TAP/lstk"
45+
46+
echo "OK: Homebrew linters clean for $CASK"

0 commit comments

Comments
 (0)