From f4ec24bc6ea815c4146aafa0d998c21ac0caa36c Mon Sep 17 00:00:00 2001 From: itamaker Date: Wed, 11 Mar 2026 16:02:28 +0800 Subject: [PATCH] Adopt GoReleaser release packaging --- .github/workflows/ci.yml | 14 +++--- .github/workflows/release.yml | 30 ++++------- .gitignore | 1 + .goreleaser.yaml | 44 +++++++++++++++++ Makefile | 42 +++++----------- PUBLISHING.md | 43 ++++++++++++++++ README.md | 5 +- docs/README.zh.md | 5 +- docs/homebrew-cask.md | 7 +-- scripts/render-homebrew-cask.sh | 88 +++++++++++++++++++++++++++++++++ 10 files changed, 214 insertions(+), 65 deletions(-) create mode 100644 .goreleaser.yaml create mode 100644 PUBLISHING.md create mode 100755 scripts/render-homebrew-cask.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cd678c0..17cd446 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,12 +31,12 @@ jobs: - name: Run tests run: go test ./... - - name: Build release archives - run: make release + - name: Build binary + run: go build ./cmd/go-chrome-ai - - name: Upload build artifacts - uses: actions/upload-artifact@v6 + - name: Check GoReleaser config + uses: goreleaser/goreleaser-action@v6 with: - name: go-chrome-ai-${{ github.sha }} - path: output/release/* - if-no-files-found: error + distribution: goreleaser + version: "~> v2" + args: check diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 91fc3d9..6bed362 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,31 +20,19 @@ jobs: steps: - name: Checkout uses: actions/checkout@v6 + with: + fetch-depth: 0 - name: Setup Go uses: actions/setup-go@v6 with: go-version-file: go.mod - - name: Run tests - run: go test ./... - - - name: Build release archives - run: make release - - - name: Upload workflow artifacts - uses: actions/upload-artifact@v6 - with: - name: go-chrome-ai-release-${{ github.ref_name }} - path: output/release/* - if-no-files-found: error - - - name: Publish GitHub release - uses: softprops/action-gh-release@v2 + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 with: - generate_release_notes: true - fail_on_unmatched_files: true - files: | - output/release/go-chrome-ai-darwin-arm64.tar.gz - output/release/go-chrome-ai-darwin-amd64.tar.gz - output/release/SHA256SUMS + distribution: goreleaser + version: "~> v2" + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 73af006..d928955 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Build outputs build/ output/ +dist/ *.exe # Root binaries from `go build` without -o diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..30806f0 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,44 @@ +version: 2 + +project_name: go-chrome-ai + +before: + hooks: + - go test ./... + +builds: + - id: go-chrome-ai + main: ./cmd/go-chrome-ai + binary: go-chrome-ai + env: + - CGO_ENABLED=1 + goos: + - darwin + goarch: + - amd64 + - arm64 + flags: + - -trimpath + ldflags: + - -s -w + +archives: + - id: release + ids: + - go-chrome-ai + formats: + - tar.gz + name_template: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}" + +checksum: + name_template: SHA256SUMS + +snapshot: + version_template: "{{ .Version }}-devel" + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" diff --git a/Makefile b/Makefile index 8e22a8b..3140d33 100644 --- a/Makefile +++ b/Makefile @@ -1,37 +1,19 @@ -OUT_DIR := output -APP_BIN := $(OUT_DIR)/go-chrome-ai -RELEASE_DIR := $(OUT_DIR)/release -APP := go-chrome-ai +BINARY := go-chrome-ai -.PHONY: build release release-macos release-macos-arm64 release-macos-amd64 checksums clean +.PHONY: build test release-check snapshot clean -build: $(OUT_DIR) - go build -trimpath -ldflags="-s -w" -o $(APP_BIN) ./cmd/go-chrome-ai +build: + mkdir -p output + go build -trimpath -ldflags="-s -w" -o output/$(BINARY) ./cmd/go-chrome-ai -$(OUT_DIR): - mkdir -p $(OUT_DIR) +test: + go test ./... -$(RELEASE_DIR): - mkdir -p $(RELEASE_DIR) +release-check: + goreleaser check -release: release-macos checksums - -release-macos: release-macos-arm64 release-macos-amd64 - -release-macos-arm64: $(RELEASE_DIR) - rm -rf $(RELEASE_DIR)/$(APP)-darwin-arm64 $(RELEASE_DIR)/$(APP)-darwin-arm64.tar.gz - mkdir -p $(RELEASE_DIR)/$(APP)-darwin-arm64 - GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go build -trimpath -ldflags="-s -w" -o $(RELEASE_DIR)/$(APP)-darwin-arm64/$(APP) ./cmd/go-chrome-ai - tar -C $(RELEASE_DIR)/$(APP)-darwin-arm64 -czf $(RELEASE_DIR)/$(APP)-darwin-arm64.tar.gz $(APP) - -release-macos-amd64: $(RELEASE_DIR) - rm -rf $(RELEASE_DIR)/$(APP)-darwin-amd64 $(RELEASE_DIR)/$(APP)-darwin-amd64.tar.gz - mkdir -p $(RELEASE_DIR)/$(APP)-darwin-amd64 - GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build -trimpath -ldflags="-s -w" -o $(RELEASE_DIR)/$(APP)-darwin-amd64/$(APP) ./cmd/go-chrome-ai - tar -C $(RELEASE_DIR)/$(APP)-darwin-amd64 -czf $(RELEASE_DIR)/$(APP)-darwin-amd64.tar.gz $(APP) - -checksums: $(RELEASE_DIR) - cd $(RELEASE_DIR) && shasum -a 256 $(APP)-darwin-arm64.tar.gz $(APP)-darwin-amd64.tar.gz | tee SHA256SUMS +snapshot: + goreleaser release --snapshot --clean clean: - rm -rf $(APP_BIN) $(RELEASE_DIR) + rm -rf output dist diff --git a/PUBLISHING.md b/PUBLISHING.md new file mode 100644 index 0000000..0da4648 --- /dev/null +++ b/PUBLISHING.md @@ -0,0 +1,43 @@ +# Publishing + +## CI + +The repository includes `.github/workflows/ci.yml` to run: + +- `go test ./...` +- `go build ./cmd/go-chrome-ai` +- `goreleaser check` + +## Release + +Tagging a semantic version triggers `.github/workflows/release.yml`. + +```bash +git tag v1.0.3 +git push origin v1.0.3 +``` + +That workflow publishes release archives and `SHA256SUMS` through GoReleaser. + +Published macOS assets keep the current install-compatible names: + +- `go-chrome-ai-darwin-arm64.tar.gz` +- `go-chrome-ai-darwin-amd64.tar.gz` +- `SHA256SUMS` + +## Homebrew Cask + +After the release is live: + +```bash +./scripts/render-homebrew-cask.sh --owner itamaker --version v1.0.3 > /path/to/homebrew-tap/Casks/go-chrome-ai.rb +``` + +Commit the rendered file to `https://github.com/itamaker/homebrew-tap` as `Casks/go-chrome-ai.rb`. + +Users can then install with: + +```bash +brew tap itamaker/tap https://github.com/itamaker/homebrew-tap +brew install --cask go-chrome-ai +``` diff --git a/README.md b/README.md index 75a4bb7..ea74dd7 100644 --- a/README.md +++ b/README.md @@ -119,9 +119,10 @@ go build -o output/go-chrome-ai ./cmd/go-chrome-ai Makefile: - `make build` -- `make release` to generate Homebrew cask release assets in `output/release/` +- `make release-check` to validate `.goreleaser.yaml` +- `make snapshot` to build GoReleaser release assets into `dist/` -All build artifacts are written to `output/`. +Local build output is written to `output/`. GoReleaser packaging output is written to `dist/`. Installed binary usage: diff --git a/docs/README.zh.md b/docs/README.zh.md index 5e79530..90b7170 100644 --- a/docs/README.zh.md +++ b/docs/README.zh.md @@ -117,9 +117,10 @@ go build -o output/go-chrome-ai ./cmd/go-chrome-ai Makefile: - `make build` -- `make release`:生成 Homebrew cask 需要的发布资产到 `output/release/` +- `make release-check`:校验 `.goreleaser.yaml` +- `make snapshot`:通过 GoReleaser 生成发布资产到 `dist/` -所有构建产物统一输出到 `output/`。 +本地构建输出到 `output/`,GoReleaser 打包输出到 `dist/`。 安装后的用法: diff --git a/docs/homebrew-cask.md b/docs/homebrew-cask.md index 009a687..38d1752 100644 --- a/docs/homebrew-cask.md +++ b/docs/homebrew-cask.md @@ -14,7 +14,7 @@ Upload these files to each GitHub Release: You can generate them via: ```bash -make release +make snapshot ``` Each archive should contain: @@ -23,8 +23,9 @@ Each archive should contain: Then update the cask: -1. `version` -2. arm64/amd64 `sha256` +```bash +./scripts/render-homebrew-cask.sh --owner itamaker --version v1.0.3 > /path/to/homebrew-tap/Casks/go-chrome-ai.rb +``` ## User install diff --git a/scripts/render-homebrew-cask.sh b/scripts/render-homebrew-cask.sh new file mode 100755 index 0000000..0d89592 --- /dev/null +++ b/scripts/render-homebrew-cask.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash + +set -euo pipefail + +PROJECT="go-chrome-ai" +DESCRIPTION="Patch Chrome Local State to enable Ask Gemini and other AI features" +CHECKSUMS_FILE="dist/SHA256SUMS" +OWNER="" +REPO="${PROJECT}" +VERSION="" + +usage() { + echo "Render a cask for https://github.com/itamaker/homebrew-tap" >&2 + echo "Usage: $0 --owner --version [--repo ] [--checksums ]" >&2 +} + +while [[ $# -gt 0 ]]; do + case "$1" in + --owner) + OWNER="$2" + shift 2 + ;; + --repo) + REPO="$2" + shift 2 + ;; + --version) + VERSION="${2#v}" + shift 2 + ;; + --checksums) + CHECKSUMS_FILE="$2" + shift 2 + ;; + *) + usage + exit 1 + ;; + esac +done + +if [[ -z "${OWNER}" || -z "${VERSION}" ]]; then + usage + exit 1 +fi + +if [[ ! -f "${CHECKSUMS_FILE}" ]]; then + echo "checksums file not found: ${CHECKSUMS_FILE}" >&2 + exit 1 +fi + +checksum_for() { + local arch="$1" + local artifact="${PROJECT}-darwin-${arch}.tar.gz" + awk -v artifact="${artifact}" '$2 == artifact { print $1 }' "${CHECKSUMS_FILE}" +} + +darwin_arm64="$(checksum_for arm64)" +darwin_amd64="$(checksum_for amd64)" + +for checksum in "${darwin_arm64}" "${darwin_amd64}"; do + if [[ -z "${checksum}" ]]; then + echo "missing required checksum in ${CHECKSUMS_FILE}" >&2 + exit 1 + fi +done + +cat <