diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 85e3c4f..1f18ef7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,82 +24,109 @@ jobs: - name: Test run: go test ./... - build: - name: Build release binaries + release: + name: Run GoReleaser needs: test runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - include: - - goos: linux - goarch: amd64 - os_name: linux - ext: "" - - goos: linux - goarch: arm64 - os_name: linux - ext: "" - - goos: darwin - goarch: amd64 - os_name: macos - ext: "" - - goos: darwin - goarch: arm64 - os_name: macos - ext: "" - - goos: windows - goarch: amd64 - os_name: windows - ext: ".exe" - - goos: windows - goarch: arm64 - os_name: windows - ext: ".exe" - steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up Go uses: actions/setup-go@v5 with: go-version-file: go.mod - - name: Build + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v7 + with: + distribution: goreleaser + version: "~> v2" + args: release --clean env: - GOOS: ${{ matrix.goos }} - GOARCH: ${{ matrix.goarch }} - CGO_ENABLED: "0" - VERSION: ${{ github.ref_name }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Calculate Homebrew checksums + id: brew run: | - mkdir -p dist - output="dist/sing-box-sub_${VERSION}_${{ matrix.os_name }}_${GOARCH}${{ matrix.ext }}" - go build \ - -trimpath \ - -ldflags "-s -w -X main.version=${VERSION}" \ - -o "${output}" \ - ./cmd/sing-box-subscribe-cli - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: sing-box-sub_${{ github.ref_name }}_${{ matrix.os_name }}_${{ matrix.goarch }} - path: dist/* - if-no-files-found: error + version="${GITHUB_REF_NAME#v}" + tag="${GITHUB_REF_NAME}" + echo "version=${version}" >> "$GITHUB_OUTPUT" + echo "tag=${tag}" >> "$GITHUB_OUTPUT" + echo "macos_arm64_sha=$(sha256sum "dist/sing-box-sub_${tag}_macos_arm64.tar.gz" | awk '{print $1}')" >> "$GITHUB_OUTPUT" + echo "macos_amd64_sha=$(sha256sum "dist/sing-box-sub_${tag}_macos_amd64.tar.gz" | awk '{print $1}')" >> "$GITHUB_OUTPUT" + echo "linux_arm64_sha=$(sha256sum "dist/sing-box-sub_${tag}_linux_arm64.tar.gz" | awk '{print $1}')" >> "$GITHUB_OUTPUT" + echo "linux_amd64_sha=$(sha256sum "dist/sing-box-sub_${tag}_linux_amd64.tar.gz" | awk '{print $1}')" >> "$GITHUB_OUTPUT" - release: - name: Publish GitHub release - needs: build - runs-on: ubuntu-latest - steps: - - name: Download artifacts - uses: actions/download-artifact@v4 + - name: Checkout Homebrew tap + uses: actions/checkout@v4 with: - path: dist - merge-multiple: true + repository: rainbend/homebrew-tap + token: ${{ secrets.HOMEBREW_TAP_TOKEN }} + path: homebrew-tap - - name: Upload release assets - uses: softprops/action-gh-release@v2 - with: - files: dist/* + - name: Update Homebrew formula + env: + FORMULA_PATH: homebrew-tap/Formula/sing-box-subscribe-cli.rb + TAG: ${{ steps.brew.outputs.tag }} + VERSION: ${{ steps.brew.outputs.version }} + MACOS_ARM64_SHA: ${{ steps.brew.outputs.macos_arm64_sha }} + MACOS_AMD64_SHA: ${{ steps.brew.outputs.macos_amd64_sha }} + LINUX_ARM64_SHA: ${{ steps.brew.outputs.linux_arm64_sha }} + LINUX_AMD64_SHA: ${{ steps.brew.outputs.linux_amd64_sha }} + run: | + mkdir -p "$(dirname "$FORMULA_PATH")" + cat > "$FORMULA_PATH" <` and `latest`; pushes to `main` publish `main` and a `sha-...` tag. diff --git a/README.zh-CN.md b/README.zh-CN.md index af7cb6a..be633f8 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -105,7 +105,7 @@ WantedBy=multi-user.target ### Windows -从 [GitHub Releases 页面](https://github.com/rainbend/sing-box-subscribe-cli/releases) 下载匹配的 `.exe` 文件,可以重命名为 `sing-box-sub.exe`,并放到 `PATH` 包含的目录。 +从 [GitHub Releases 页面](https://github.com/rainbend/sing-box-subscribe-cli/releases) 下载匹配的 Windows `.zip` 文件,解压出 `sing-box-sub.exe`,并放到 `PATH` 包含的目录。 检查安装结果: @@ -274,7 +274,7 @@ git tag v1.0.0 git push origin v1.0.0 ``` -release workflow 会运行测试,构建 Linux、macOS 和 Windows 的 `amd64`、`arm64` 二进制文件,把 tag 注入 `sing-box-sub version`,并上传到 GitHub Releases。 +release workflow 会运行测试,通过 GoReleaser 构建 Linux、macOS 和 Windows 的 `amd64`、`arm64` 归档文件,把 tag 注入 `sing-box-sub version`,将产物和 `checksums.txt` 上传到 GitHub Releases,并更新 Homebrew tap formula。 容器镜像会发布到 GitHub Packages。版本 tag 会发布 `` 和 `latest`;推送到 `main` 会发布 `main` 和 `sha-...` tag。 diff --git a/install.sh b/install.sh index b4372ba..e883820 100755 --- a/install.sh +++ b/install.sh @@ -56,18 +56,33 @@ case "$version" in *) version="v${version}" ;; esac -asset="${release_binary}_${version}_linux_${arch}" -url="https://github.com/${repo}/releases/download/${version}/${asset}" +archive_asset="${release_binary}_${version}_linux_${arch}.tar.gz" +raw_asset="${release_binary}_${version}_linux_${arch}" +archive_url="https://github.com/${repo}/releases/download/${version}/${archive_asset}" +raw_url="https://github.com/${repo}/releases/download/${version}/${raw_asset}" tmp_dir="$(mktemp -d)" -tmp_file="${tmp_dir}/${asset}" +archive_file="${tmp_dir}/${archive_asset}" +tmp_file="${tmp_dir}/${release_binary}" cleanup() { rm -rf "$tmp_dir" } trap cleanup EXIT INT TERM -echo "Downloading ${asset}..." -curl -fL "$url" -o "$tmp_file" +echo "Downloading ${archive_asset}..." +if curl -fsSL "$archive_url" -o "$archive_file"; then + need_cmd tar + tar -xzf "$archive_file" -C "$tmp_dir" +else + echo "Archive not found, falling back to ${raw_asset}..." + curl -fL "$raw_url" -o "$tmp_file" +fi + +if [ ! -f "$tmp_file" ]; then + echo "error: release asset did not contain ${release_binary}" >&2 + exit 1 +fi + chmod 0755 "$tmp_file" if [ ! -d "$install_dir" ]; then