diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7f89c71..0e286a2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,12 @@ name: Release on: + push: + tags: + - 'v*' release: - types: [created] + types: [published, created] + workflow_dispatch: permissions: contents: write @@ -63,3 +67,50 @@ jobs: files: | ptd-cli-${{ github.ref_name }}-${{ matrix.target }}.tar.gz ptd-cli-${{ github.ref_name }}-${{ matrix.target }}.zip + + bump-manifests: + name: Bump Homebrew Formula & Scoop Manifest + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.repository.default_branch }} + + - name: Update Homebrew Formula & Scoop Manifest + run: | + VERSION="${GITHUB_REF_NAME#v}" + BASE_URL="https://github.com/${GITHUB_REPOSITORY}/releases/download/${GITHUB_REF_NAME}" + + # Calculate SHA256 for all release packages + MACOS_ARM64_SHA=$(curl -sL "${BASE_URL}/ptd-cli-${GITHUB_REF_NAME}-aarch64-apple-darwin.tar.gz" | sha256sum | awk '{print $1}') + MACOS_X86_64_SHA=$(curl -sL "${BASE_URL}/ptd-cli-${GITHUB_REF_NAME}-x86_64-apple-darwin.tar.gz" | sha256sum | awk '{print $1}') + LINUX_ARM64_SHA=$(curl -sL "${BASE_URL}/ptd-cli-${GITHUB_REF_NAME}-aarch64-unknown-linux-gnu.tar.gz" | sha256sum | awk '{print $1}') + LINUX_X86_64_SHA=$(curl -sL "${BASE_URL}/ptd-cli-${GITHUB_REF_NAME}-x86_64-unknown-linux-gnu.tar.gz" | sha256sum | awk '{print $1}') + WINDOWS_X86_64_SHA=$(curl -sL "${BASE_URL}/ptd-cli-${GITHUB_REF_NAME}-x86_64-pc-windows-msvc.zip" | sha256sum | awk '{print $1}') + + # In-place update Homebrew Formula + sed -i.bak -E \ + -e "s|version \".*\"|version \"${VERSION}\"|" \ + -e "s|https://github.com/[^/]+/[^/\"]+|https://github.com/${GITHUB_REPOSITORY}|g" \ + -e "s|\"aarch64-apple-darwin\" *=> *\".*\"|\"aarch64-apple-darwin\" => \"${MACOS_ARM64_SHA}\"|" \ + -e "s|\"x86_64-apple-darwin\" *=> *\".*\"|\"x86_64-apple-darwin\" => \"${MACOS_X86_64_SHA}\"|" \ + -e "s|\"aarch64-unknown-linux-gnu\" *=> *\".*\"|\"aarch64-unknown-linux-gnu\" => \"${LINUX_ARM64_SHA}\"|" \ + -e "s|\"x86_64-unknown-linux-gnu\" *=> *\".*\"|\"x86_64-unknown-linux-gnu\" => \"${LINUX_X86_64_SHA}\"|" \ + Formula/ptd-cli.rb && rm -f Formula/ptd-cli.rb.bak + + # In-place update Scoop Manifest (Version, URL, Hash, Homepage, Autoupdate) + jq --arg v "$VERSION" \ + --arg u "https://github.com/${GITHUB_REPOSITORY}/releases/download/${GITHUB_REF_NAME}/ptd-cli-${GITHUB_REF_NAME}-x86_64-pc-windows-msvc.zip" \ + --arg hash "$WINDOWS_X86_64_SHA" \ + --arg auto_u "https://github.com/${GITHUB_REPOSITORY}/releases/download/v\$version/ptd-cli-v\$version-x86_64-pc-windows-msvc.zip" \ + --arg hp "https://github.com/${GITHUB_REPOSITORY}" \ + '.version = $v | .homepage = $hp | .architecture["64bit"].url = $u | .architecture["64bit"].hash = $hash | .autoupdate.architecture["64bit"].url = $auto_u' \ + bucket/ptd-cli.json > bucket/ptd-cli.tmp.json && mv bucket/ptd-cli.tmp.json bucket/ptd-cli.json + + # Commit and push both in a single commit + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add Formula/ptd-cli.rb bucket/ptd-cli.json + git commit -m "chore(release): bump homebrew and scoop to ${GITHUB_REF_NAME} [skip ci]" || exit 0 + git push origin HEAD:${{ github.event.repository.default_branch }} diff --git a/Formula/ptd-cli.rb b/Formula/ptd-cli.rb new file mode 100644 index 0000000..103cf6c --- /dev/null +++ b/Formula/ptd-cli.rb @@ -0,0 +1,34 @@ +class PtdCli < Formula + desc "CLI for PT-Depiler browser extension via Native Messaging" + homepage "https://github.com/pt-plugins/ptd-cli" + version "0.1.0" + license "MIT" + + SHA256S = { + "aarch64-apple-darwin" => "7d152087fcbd739f7b3fa9a75abed5073a1920e2cbac378407167dd1d003b2c5", + "x86_64-apple-darwin" => "032e5748c896d6eb0e2e1f75cc1be3327c255f810b6158082fa40ad08f4f4b4b", + "aarch64-unknown-linux-gnu" => "0d2beb0718cd8fcd268e104ad777f3fb61af628497874c8bc9fa301f34776809", + "x86_64-unknown-linux-gnu" => "b1398a3374ca509be107d0a82ddf379a78f5a2ccf892b6d2b5fb586290d4203c", + }.freeze + + on_macos do + arch = Hardware::CPU.arm? ? "aarch64-apple-darwin" : "x86_64-apple-darwin" + url "https://github.com/pt-plugins/ptd-cli/releases/download/v#{version}/ptd-cli-v#{version}-#{arch}.tar.gz" + sha256 SHA256S[arch] + end + + on_linux do + arch = Hardware::CPU.arm? ? "aarch64-unknown-linux-gnu" : "x86_64-unknown-linux-gnu" + url "https://github.com/pt-plugins/ptd-cli/releases/download/v#{version}/ptd-cli-v#{version}-#{arch}.tar.gz" + sha256 SHA256S[arch] + end + + def install + bin.install "ptd" + bin.install "ptd-host" + end + + test do + assert_match "ptd", shell_output("#{bin}/ptd --help") + end +end diff --git a/README.en.md b/README.en.md index 79add0c..759208e 100644 --- a/README.en.md +++ b/README.en.md @@ -27,11 +27,29 @@ Three components: ## Install -### 1. Download pre-built binaries +### 1. Install CLI + +#### Homebrew (macOS / Linux) + +```bash +# Add tap and install +brew tap pt-plugins/ptd-cli https://github.com/pt-plugins/ptd-cli +brew install ptd-cli +``` + +#### Scoop (Windows) + +```powershell +# Add bucket and install +scoop bucket add ptd-cli https://github.com/pt-plugins/ptd-cli +scoop install ptd-cli +``` + +#### Manual Download (Pre-built Binaries) Download the latest `ptd` and `ptd-host` from [GitHub Releases](https://github.com/pt-plugins/ptd-cli/releases), extract them into the same directory, and add it to your `PATH`. -> **AI Agent users:** Download pre-built binaries from the Release page instead of building from source. +> **AI Agent users:** Use package managers (Homebrew / Scoop) or download pre-built binaries from the Release page instead of building from source.
Build from source diff --git a/README.md b/README.md index cf96a29..12bbae5 100644 --- a/README.md +++ b/README.md @@ -29,11 +29,29 @@ CLI <-- Unix socket <-- ptd-host <--stdin-- Chrome <------+ ## 安装 -### 1. 下载预编译二进制 +### 1. 安装 CLI + +#### Homebrew (macOS / Linux) + +```bash +# 添加 tap 并安装 +brew tap pt-plugins/ptd-cli https://github.com/pt-plugins/ptd-cli +brew install ptd-cli +``` + +#### Scoop (Windows) + +```powershell +# 添加 bucket 并安装 +scoop bucket add ptd-cli https://github.com/pt-plugins/ptd-cli +scoop install ptd-cli +``` + +#### 手动下载预编译二进制 从 [GitHub Releases](https://github.com/pt-plugins/ptd-cli/releases) 下载最新版本的 `ptd` 和 `ptd-host`,解压后将两个文件放在同一目录下,并添加到 `PATH`。 -> **AI Agent 用户:** 请直接从 Release 页面下载预编译二进制,无需从源码构建。 +> **AI Agent 用户:** 请优先使用包管理器(Homebrew / Scoop)或直接从 Release 页面下载预编译二进制,无需从源码构建。
从源码构建 diff --git a/bucket/ptd-cli.json b/bucket/ptd-cli.json new file mode 100644 index 0000000..f68ee55 --- /dev/null +++ b/bucket/ptd-cli.json @@ -0,0 +1,24 @@ +{ + "version": "0.1.0", + "description": "CLI for PT-Depiler browser extension via Native Messaging", + "homepage": "https://github.com/pt-plugins/ptd-cli", + "license": "MIT", + "architecture": { + "64bit": { + "url": "https://github.com/pt-plugins/ptd-cli/releases/download/v0.1.0/ptd-cli-v0.1.0-x86_64-pc-windows-msvc.zip", + "hash": "da821d693ce9a85f6bca2d72b0be528448358d895aa99852ac195ea448e93978" + } + }, + "bin": [ + "ptd.exe", + "ptd-host.exe" + ], + "checkver": "github", + "autoupdate": { + "architecture": { + "64bit": { + "url": "https://github.com/pt-plugins/ptd-cli/releases/download/v$version/ptd-cli-v$version-x86_64-pc-windows-msvc.zip" + } + } + } +}