Files

247 lines
8.5 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Release
# 打 tag(v1.2.3)即自动出包并发布 Release;也可以在 Actions 页手动跑一次只出产物。
on:
workflow_dispatch:
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: true
env:
CI: "true"
jobs:
# ================= Windows:NSIS 安装包 + 便携包 =================
windows:
name: Windows (setup + portable)
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: 版本号对齐 tag
id: ver
shell: bash
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
V="${GITHUB_REF_NAME#v}"
else
V="$(node -p "require('./src-tauri/tauri.conf.json').version")"
fi
echo "version=$V" >> "$GITHUB_OUTPUT"
node -e "const fs=require('fs');for(const p of ['src-tauri/tauri.conf.json','package.json']){const j=JSON.parse(fs.readFileSync(p));j.version=process.argv[1];fs.writeFileSync(p,JSON.stringify(j,null,2)+'\n')}" "$V"
- uses: pnpm/action-setup@v4
with:
version: 10
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- uses: dtolnay/rust-toolchain@stable
- uses: swatinem/rust-cache@v2
with:
workspaces: src-tauri -> target
- run: pnpm install --frozen-lockfile
- name: 构建(NSIS 安装包)
run: pnpm tauri build --bundles nsis
- name: 收集产物(安装包 + 便携包)
shell: pwsh
run: |
$v = "${{ steps.ver.outputs.version }}"
New-Item -ItemType Directory -Force artifacts | Out-Null
Copy-Item "src-tauri/target/release/bundle/nsis/*.exe" artifacts/
$bin = "src-tauri/target/release/huangguo-client.exe"
if (-not (Test-Path $bin)) {
$bin = (Get-ChildItem "src-tauri/target/release" -Filter *.exe | Select-Object -First 1).FullName
}
Copy-Item $bin "artifacts/HGhub.exe"
Compress-Archive -Path "artifacts/HGhub.exe" -DestinationPath "artifacts/HGhub_${v}_x64_portable.zip" -Force
Remove-Item "artifacts/HGhub.exe"
Get-ChildItem artifacts | Select-Object Name, Length
- uses: actions/upload-artifact@v4
with:
name: windows
path: artifacts/*
if-no-files-found: error
# ================= Android:按 ABI 分包 + 签名 =================
android:
name: Android (split per ABI)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: 版本号对齐 tag
id: ver
shell: bash
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
V="${GITHUB_REF_NAME#v}"
else
V="$(node -p "require('./src-tauri/tauri.conf.json').version")"
fi
echo "version=$V" >> "$GITHUB_OUTPUT"
node -e "const fs=require('fs');for(const p of ['src-tauri/tauri.conf.json','package.json']){const j=JSON.parse(fs.readFileSync(p));j.version=process.argv[1];fs.writeFileSync(p,JSON.stringify(j,null,2)+'\n')}" "$V"
- uses: pnpm/action-setup@v4
with:
version: 10
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "17"
# ubuntu runner 自带 Android SDK,不再用 android-actions/setup-android(它的 license 交互会卡住)
- name: 准备 Android SDK / NDK
run: |
SDK="${ANDROID_HOME:-/usr/local/lib/android/sdk}"
echo "ANDROID_HOME=$SDK" >> "$GITHUB_ENV"
echo "ANDROID_SDK_ROOT=$SDK" >> "$GITHUB_ENV"
SDKM="$SDK/cmdline-tools/latest/bin/sdkmanager"
yes | "$SDKM" --licenses > /dev/null 2>&1 || true
"$SDKM" --install "platform-tools" "platforms;android-36" "build-tools;36.0.0" "ndk;28.2.13676358"
echo "NDK_HOME=$SDK/ndk/28.2.13676358" >> "$GITHUB_ENV"
ls "$SDK/ndk"
- uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-linux-android,armv7-linux-androideabi,x86_64-linux-android
- uses: swatinem/rust-cache@v2
with:
workspaces: src-tauri -> target
key: android
- run: pnpm install --frozen-lockfile
- name: 生成 Android 工程
run: pnpm tauri android init --ci
- name: 编译 APK(按 ABI 分包)
run: pnpm tauri android build --apk --split-per-abi --target aarch64 armv7 x86_64
- name: 签名 APK
env:
KEYSTORE_BASE64: ${{ secrets.ANDROID_KEY_BASE64 }}
KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
STORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
VERSION: ${{ steps.ver.outputs.version }}
run: |
set -euo pipefail
if [ -z "${KEYSTORE_BASE64:-}" ]; then
echo "::error::缺少 ANDROID_KEY_BASE64 secret,无法签名"; exit 1
fi
KS="$RUNNER_TEMP/release.keystore"
echo "$KEYSTORE_BASE64" | base64 -d > "$KS"
BT="$(ls "$ANDROID_SDK_ROOT/build-tools" | sort -V | tail -1)"
APKSIGNER="$ANDROID_SDK_ROOT/build-tools/$BT/apksigner"
mkdir -p artifacts
found=0
for f in $(find src-tauri/gen/android/app/build/outputs/apk -name '*-release*.apk'); do
abi="$(basename "$(dirname "$(dirname "$f")")")"
out="artifacts/HGhub_${VERSION}_${abi}.apk"
"$APKSIGNER" sign \
--ks "$KS" --ks-key-alias "$KEY_ALIAS" \
--ks-pass "pass:$STORE_PASSWORD" --key-pass "pass:$KEY_PASSWORD" \
--v4-signing-enabled false \
--out "$out" "$f"
"$APKSIGNER" verify --print-certs "$out" | head -3
found=$((found+1))
done
rm -f "$KS"
if [ "$found" -eq 0 ]; then echo "::error::没有找到 release APK"; exit 1; fi
ls -lh artifacts
- uses: actions/upload-artifact@v4
with:
name: android
path: artifacts/*
if-no-files-found: error
# ================= macOS:Universal(Apple Silicon + Intel)dmg =================
macos:
name: macOS (universal dmg)
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: 版本号对齐 tag
id: ver
shell: bash
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
V="${GITHUB_REF_NAME#v}"
else
V="$(node -p "require('./src-tauri/tauri.conf.json').version")"
fi
echo "version=$V" >> "$GITHUB_OUTPUT"
node -e "const fs=require('fs');for(const p of ['src-tauri/tauri.conf.json','package.json']){const j=JSON.parse(fs.readFileSync(p));j.version=process.argv[1];fs.writeFileSync(p,JSON.stringify(j,null,2)+'\n')}" "$V"
- uses: pnpm/action-setup@v4
with:
version: 10
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-apple-darwin,x86_64-apple-darwin
- uses: swatinem/rust-cache@v2
with:
workspaces: src-tauri -> target
key: macos
- run: pnpm install --frozen-lockfile
# 打包目标(app + dmg)取自 src-tauri/tauri.macos.conf.json;未配置开发者证书,产物为 ad-hoc 签名
- name: 构建(Universal dmg)
run: pnpm tauri build --target universal-apple-darwin
- name: 收集产物
shell: bash
run: |
set -euo pipefail
mkdir -p artifacts
cp src-tauri/target/universal-apple-darwin/release/bundle/dmg/*.dmg \
"artifacts/HGhub_${{ steps.ver.outputs.version }}_universal.dmg"
ls -lh artifacts
- uses: actions/upload-artifact@v4
with:
name: macos
path: artifacts/*
if-no-files-found: error
# ================= 发布 =================
release:
name: Publish GitHub Release
needs: [windows, android, macos]
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: 列出待发布文件
run: ls -lh artifacts
- uses: softprops/action-gh-release@v2
with:
files: artifacts/*
generate_release_notes: true
fail_on_unmatched_files: true