Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
265 changes: 265 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
name: Build and Release Binaries

on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g. 0.2.4)'
required: true
type: string

permissions:
contents: write

env:
PYTHON_VERSION: '3.11'

jobs:
# ── macOS Intel (x64) ──────────────────────────────────────────
build-macos-x64:
runs-on: macos-13 # Intel runner
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: x64

- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install pyinstaller
pip install -e .

- name: Compile C binary for x86_64
run: |
cc -O2 -arch x86_64 \
-o wechat_cli/bin/find_all_keys_macos.x86_64 \
wechat_cli/bin/find_all_keys_macos.c \
-framework Foundation
chmod +x wechat_cli/bin/find_all_keys_macos.x86_64
file wechat_cli/bin/find_all_keys_macos.x86_64

- name: Build PyInstaller binary
run: python npm/scripts/build.py darwin-x64

- name: Package platform tarball
run: |
cd npm/platforms/darwin-x64
tar czf /tmp/wechat-cli-darwin-x64.tgz -C . bin/
cd /tmp
echo "=== Contents ==="
tar tzf wechat-cli-darwin-x64.tgz

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: darwin-x64-binary
path: /tmp/wechat-cli-darwin-x64.tgz

# ── macOS Apple Silicon (arm64) ────────────────────────────────
build-macos-arm64:
runs-on: macos-14 # Apple Silicon runner
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install pyinstaller
pip install -e .

- name: Compile C binary for arm64
run: |
cc -O2 -arch arm64 \
-o wechat_cli/bin/find_all_keys_macos.arm64 \
wechat_cli/bin/find_all_keys_macos.c \
-framework Foundation
chmod +x wechat_cli/bin/find_all_keys_macos.arm64
file wechat_cli/bin/find_all_keys_macos.arm64

- name: Build PyInstaller binary
run: python npm/scripts/build.py darwin-arm64

- name: Package platform tarball
run: |
cd npm/platforms/darwin-arm64
tar czf /tmp/wechat-cli-darwin-arm64.tgz -C . bin/

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: darwin-arm64-binary
path: /tmp/wechat-cli-darwin-arm64.tgz

# ── Linux x64 ──────────────────────────────────────────────────
build-linux-x64:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install pyinstaller
pip install -e .

- name: Build PyInstaller binary
run: python npm/scripts/build.py linux-x64

- name: Package platform tarball
run: |
cd npm/platforms/linux-x64
tar czf /tmp/wechat-cli-linux-x64.tgz -C . bin/

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: linux-x64-binary
path: /tmp/wechat-cli-linux-x64.tgz

# ── Linux arm64 ────────────────────────────────────────────────
build-linux-arm64:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install cross-compilation toolchain
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu

- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install pyinstaller
pip install -e .

- name: Build PyInstaller binary (native, best-effort)
run: python npm/scripts/build.py linux-arm64
continue-on-error: true

- name: Package platform tarball
if: success()
run: |
cd npm/platforms/linux-arm64
tar czf /tmp/wechat-cli-linux-arm64.tgz -C . bin/

- name: Upload artifact
if: success()
uses: actions/upload-artifact@v4
with:
name: linux-arm64-binary
path: /tmp/wechat-cli-linux-arm64.tgz

# ── Windows x64 ────────────────────────────────────────────────
build-windows-x64:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install pyinstaller
pip install -e .

- name: Build PyInstaller binary
run: python npm/scripts/build.py win32-x64

- name: Package platform zip
run: |
cd npm/platforms/win32-x64
Compress-Archive -Path bin/* -DestinationPath /tmp/wechat-cli-win32-x64.zip -Force

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: win32-x64-binary
path: /tmp/wechat-cli-win32-x64.zip

# ── Create GitHub Release ──────────────────────────────────────
release:
needs:
- build-macos-x64
- build-macos-arm64
- build-linux-x64
- build-linux-arm64
- build-windows-x64
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch'
steps:
- uses: actions/checkout@v4

- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: /tmp/artifacts

- name: Determine version
id: ver
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "VERSION=${{ inputs.version }}" >> $GITHUB_OUTPUT
else
echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
fi

- name: List artifacts
run: find /tmp/artifacts -type f

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ startsWith(github.ref, 'refs/tags/v') && github.ref_name || format('v{0}', inputs.version) }}
name: wechat-cli ${{ steps.ver.outputs.VERSION }}
body: |
## wechat-cli ${{ steps.ver.outputs.VERSION }}

### Platforms
| Platform | Arch | Package |
|----------|------|---------|
| macOS | x64 | `wechat-cli-darwin-x64.tgz` |
| macOS | arm64| `wechat-cli-darwin-arm64.tgz` |
| Linux | x64 | `wechat-cli-linux-x64.tgz` |
| Linux | arm64| `wechat-cli-linux-arm64.tgz` |
| Windows | x64 | `wechat-cli-win32-x64.zip` |

### npm install
```bash
npm install -g @canghe_ai/wechat-cli@${{ steps.ver.outputs.VERSION }}
```
files: |
/tmp/artifacts/darwin-x64-binary/wechat-cli-darwin-x64.tgz
/tmp/artifacts/darwin-arm64-binary/wechat-cli-darwin-arm64.tgz
/tmp/artifacts/linux-x64-binary/wechat-cli-linux-x64.tgz
/tmp/artifacts/linux-arm64-binary/wechat-cli-linux-arm64.tgz
/tmp/artifacts/win32-x64-binary/wechat-cli-win32-x64.zip
draft: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 5 additions & 1 deletion npm/wechat-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
"install.js"
],
"optionalDependencies": {
"@canghe_ai/wechat-cli-darwin-arm64": "0.2.4"
"@canghe_ai/wechat-cli-darwin-arm64": "0.2.4",
"@canghe_ai/wechat-cli-darwin-x64": "0.2.4",
"@canghe_ai/wechat-cli-linux-x64": "0.2.4",
"@canghe_ai/wechat-cli-linux-arm64": "0.2.4",
"@canghe_ai/wechat-cli-win32-x64": "0.2.4"
},
"engines": {
"node": ">=14"
Expand Down