Skip to content

Switch release workflow to GoReleaser (#5) #5

Switch release workflow to GoReleaser (#5)

Switch release workflow to GoReleaser (#5) #5

Workflow file for this run

name: Release
on:
push:
tags:
- "*"
permissions:
contents: write
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Test
run: go test ./...
release:
name: Run GoReleaser
needs: test
runs-on: ubuntu-latest
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: Run GoReleaser
uses: goreleaser/goreleaser-action@v7
with:
distribution: goreleaser
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Calculate Homebrew checksums
id: brew
run: |
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"
- name: Checkout Homebrew tap
uses: actions/checkout@v4
with:
repository: rainbend/homebrew-tap
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
path: homebrew-tap
- 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" <<FORMULA
class SingBoxSubscribeCli < Formula
desc "Generate sing-box configs from subscriptions and JSON templates"
homepage "https://github.com/rainbend/sing-box-subscribe-cli"
version "${VERSION}"
license "Apache-2.0"
on_macos do
on_arm do
url "https://github.com/rainbend/sing-box-subscribe-cli/releases/download/${TAG}/sing-box-sub_${TAG}_macos_arm64.tar.gz"
sha256 "${MACOS_ARM64_SHA}"
end
on_intel do
url "https://github.com/rainbend/sing-box-subscribe-cli/releases/download/${TAG}/sing-box-sub_${TAG}_macos_amd64.tar.gz"
sha256 "${MACOS_AMD64_SHA}"
end
end
on_linux do
if Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
url "https://github.com/rainbend/sing-box-subscribe-cli/releases/download/${TAG}/sing-box-sub_${TAG}_linux_arm64.tar.gz"
sha256 "${LINUX_ARM64_SHA}"
end
if Hardware::CPU.intel? && Hardware::CPU.is_64_bit?
url "https://github.com/rainbend/sing-box-subscribe-cli/releases/download/${TAG}/sing-box-sub_${TAG}_linux_amd64.tar.gz"
sha256 "${LINUX_AMD64_SHA}"
end
end
def install
bin.install "sing-box-sub"
end
test do
assert_match version.to_s, shell_output("#{bin}/sing-box-sub version")
assert_match "sb-config-1.14.json", shell_output("#{bin}/sing-box-sub list")
end
end
FORMULA
ruby -c "$FORMULA_PATH"
- name: Commit Homebrew formula
working-directory: homebrew-tap
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
[ -n "$(git status --porcelain -- Formula/sing-box-subscribe-cli.rb)" ] || exit 0
git add Formula/sing-box-subscribe-cli.rb
git commit -m "Update sing-box-subscribe-cli to ${GITHUB_REF_NAME}"
git push