Skip to content

Release

Release #16

Workflow file for this run

name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag_name:
description: 'Tag name for release (e.g., v8.1.0)'
required: true
type: string
permissions:
contents: write
env:
# 使用手动输入或 git tag
TAG_NAME: ${{ github.event.inputs.tag_name || github.ref_name }}
jobs:
build-cli:
name: Build CLI Tool
runs-on: ubuntu-latest
strategy:
matrix:
include:
# Windows
- os: windows
arch: amd64
ext: .exe
- os: windows
arch: arm64
ext: .exe
# Linux
- os: linux
arch: amd64
ext: ""
- os: linux
arch: arm64
ext: ""
# macOS
- os: darwin
arch: amd64
ext: ""
- os: darwin
arch: arm64
ext: ""
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Build CLI
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
CGO_ENABLED: 0 # 禁用 CGO 以实现静态链接,解决 GLIBC 兼容性问题
run: |
cd cli-go
go build -ldflags="-s -w" -o ../dist/opencode-cli-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }} .
- name: Upload CLI Artifact
uses: actions/upload-artifact@v4
with:
name: cli-${{ matrix.os }}-${{ matrix.arch }}
path: dist/*
build-opencode:
name: Build OpenCode Chinese
runs-on: ubuntu-latest
needs: build-cli # 需要先编译 CLI
strategy:
matrix:
include:
- platform: windows-x64
bun_target: bun-windows-x64
- platform: windows-arm64
bun_target: bun-windows-x64 # Bun doesn't have official stable windows-arm64 builds yet, using x64 via emulation or cross-compilation if supported by tooling
- platform: linux-x64
bun_target: bun-linux-x64
- platform: linux-arm64
bun_target: bun-linux-aarch64
- platform: darwin-x64
bun_target: bun-darwin-x64
- platform: darwin-arm64
bun_target: bun-darwin-arm64
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: '1.3.5'
- name: Build CLI for current platform
run: |
cd cli-go
go build -o ../opencode-cli .
- name: Clone OpenCode source
run: |
git clone --depth 1 --branch dev https://github.com/anomalyco/opencode.git opencode-zh-CN
- name: Apply Chinese translation
run: |
./opencode-cli apply
- name: Build OpenCode
run: |
./opencode-cli build --platform ${{ matrix.platform }} --deploy=false
- name: Package
run: |
VERSION=${{ env.TAG_NAME }}
PLATFORM=${{ matrix.platform }}
PACKAGE_NAME="opencode-zh-CN-${VERSION}-${PLATFORM}"
echo "=== Packaging ${PACKAGE_NAME} ==="
# 构建产物的实际路径
# opencode-zh-CN/packages/opencode/dist/opencode-{platform}/bin/
BUILD_DIR="opencode-zh-CN/packages/opencode/dist/opencode-${PLATFORM}/bin"
echo "Looking for build artifacts in: ${BUILD_DIR}"
ls -la ${BUILD_DIR}/ || echo "Build dir not found"
# 确保输出目录存在
mkdir -p dist
# 检查构建产物并打包
if [[ "$PLATFORM" == "windows-x64" || "$PLATFORM" == "windows-arm64" ]]; then
BINARY="${BUILD_DIR}/opencode.exe"
else
BINARY="${BUILD_DIR}/opencode"
fi
if [ -f "$BINARY" ]; then
zip -j dist/${PACKAGE_NAME}.zip "$BINARY"
echo "✓ Created dist/${PACKAGE_NAME}.zip"
ls -la dist/
else
echo "❌ Binary not found: $BINARY"
echo "=== Searching for opencode binaries ==="
find opencode-zh-CN -name "opencode*" -type f 2>/dev/null | head -20
exit 1
fi
- name: Upload OpenCode Artifact
uses: actions/upload-artifact@v4
with:
name: opencode-${{ matrix.platform }}
path: dist/*.zip
release:
name: Create GitHub Release
needs: [build-cli, build-opencode]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get Build Timestamp
id: date
run: echo "timestamp=$(date -u +'%Y-%m-%d %H:%M UTC')" >> $GITHUB_OUTPUT
- name: Download CLI Artifacts
uses: actions/download-artifact@v4
with:
pattern: cli-*
path: dist
merge-multiple: true
- name: Download OpenCode Artifacts
uses: actions/download-artifact@v4
with:
pattern: opencode-*
path: dist
merge-multiple: true
- name: List artifacts
run: |
echo "=== Downloaded artifacts ==="
find dist -type f -name "*.zip" -o -name "*.exe" -o -name "opencode-cli-*" | head -50
ls -la dist/ || true
- name: Package i18n tool
run: |
VERSION=${{ env.TAG_NAME }}
zip -r dist/opencode-i18n-tool-${VERSION}.zip \
opencode-i18n/ \
cli-go/ \
install.ps1 \
install.sh \
README.md \
CHANGELOG.md \
-x "cli-go/.git/*" \
-x "*.exe"
- name: Generate Release Notes
run: |
VERSION=${{ env.TAG_NAME }}
TIMESTAMP="${{ steps.date.outputs.timestamp }}"
cat > release_notes.md << EOF
## OpenCode 中文汉化版 ${{ env.TAG_NAME }}
> 🕒 **更新时间**: ${TIMESTAMP}
### 📦 下载说明
| 平台 | 管理工具 (CLI) | 汉化版 OpenCode |
|------|----------------|-----------------|
| Windows x64 | \`opencode-cli-windows-amd64.exe\` | \`opencode-zh-CN-${VERSION}-windows-x64.zip\` |
| Windows ARM64 | \`opencode-cli-windows-arm64.exe\` | \`opencode-zh-CN-${VERSION}-windows-arm64.zip\` |
| macOS Apple Silicon | \`opencode-cli-darwin-arm64\` | \`opencode-zh-CN-${VERSION}-darwin-arm64.zip\` |
| macOS Intel | \`opencode-cli-darwin-amd64\` | \`opencode-zh-CN-${VERSION}-darwin-x64.zip\` |
| Linux x64 | \`opencode-cli-linux-amd64\` | \`opencode-zh-CN-${VERSION}-linux-x64.zip\` |
| Linux ARM64 | \`opencode-cli-linux-arm64\` | \`opencode-zh-CN-${VERSION}-linux-arm64.zip\` |
### 🚀 快速安装
**Windows (PowerShell)**
\`\`\`powershell
powershell -c "irm https://cdn.jsdelivr.net/gh/1186258278/OpenCodeChineseTranslation@main/install.ps1 | iex"
\`\`\`
**Linux / macOS**
\`\`\`bash
curl -fsSL https://cdn.jsdelivr.net/gh/1186258278/OpenCodeChineseTranslation@main/install.sh | bash
\`\`\`
### 📝 更新日志
详见 [CHANGELOG.md](https://github.com/1186258278/OpenCodeChineseTranslation/blob/main/CHANGELOG.md)
EOF
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.TAG_NAME }}
name: "OpenCode 中文汉化版 ${{ env.TAG_NAME }} (${{ steps.date.outputs.timestamp }})"
body_path: release_notes.md
files: |
dist/*
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}