Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix:mac版本打包错误 #52

fix:mac版本打包错误

fix:mac版本打包错误 #52

Workflow file for this run

name: Tauri 2 Release
# 设置触发条件
on:
push:
tags:
- 'v*' # 当推送以v开头的标签时触发
workflow_dispatch: # 允许手动触发
inputs:
update_notes:
type: string
description: '更新内容'
required: true
default: '版本发布'
jobs:
# 设置运行环境
setup:
name: Setup environment
runs-on: ubuntu-latest
steps:
# 拉取项目代码
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
# 安装 Node.js
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
# 输出更新内容
- name: Check Update Content
run: echo ${{ github.event.inputs.update_notes }}
# 项目打包
build:
needs: setup
permissions:
contents: write
strategy:
fail-fast: false
matrix:
platform: [ macos-latest, windows-latest ]
include:
- platform: macos-latest
rust-target: aarch64-apple-darwin
system-deps: |
brew update
brew install create-dmg
- platform: windows-latest
rust-target: x86_64-pc-windows-msvc
system-deps: |
choco install -y wixtoolset
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20
# 安装 pnpm
- name: Setup pnpm
uses: pnpm/[email protected]
- name: Install rust target
run: rustup target add ${{ matrix.rust-target }}
# 安装 Rust
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
# 使用 Rust 缓存,加快安装速度
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
workspaces: target
# 获取 pnpm 缓存
- name: Sync node version and setup cache
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
# 安装依赖, 前端打包
- name: Install app dependencies and build web
run: pnpm install --frozen-lockfile
# 构建 Tauri 应用
- name: Build Tauri application
run: pnpm tauri build --target ${{ matrix.rust-target }}
env:
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
# 上传构建结果
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: release-${{ matrix.platform }}
path: |
src-tauri/target/${{ matrix.rust-target }}/release/bundle/**/*.exe
src-tauri/target/${{ matrix.rust-target }}/release/bundle/**/*.dmg
src-tauri/target/${{ matrix.rust-target }}/release/bundle/**/*.gz
src-tauri/target/${{ matrix.rust-target }}/release/bundle/macos/*.sig
src-tauri/target/${{ matrix.rust-target }}/release/bundle/nsis/*.sig
# 代码发布
release:
needs: [ setup, build ]
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
# 创建 GitHub release
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: "App ${{ github.ref_name }}"
body: ${{ github.event.inputs.update_notes }}
draft: false # 是否生成release草稿
prerelease: false # 是否生成预发布包
files: |
artifacts/**/*
# 更新 latest.json 文件内容
update_latest_json:
needs: [setup, build, release]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: master
fetch-depth: 0
- name: Download artifacts again
uses: actions/download-artifact@v4
with:
path: artifacts
pattern: release-*
merge-multiple: true
- name: List downloaded artifacts
run: ls -R artifacts
- name: Get latest release info
id: get_release
uses: actions/github-script@v7
with:
script: |
const response = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo
});
return {
version: response.data.tag_name.replace(/^v/, ''),
notes: response.data.body,
pub_date: new Date().toISOString()
};
- name: Find release assets and signatures
id: find_assets
run: |
# 调试:查看artifact目录结构
echo "Artifacts directory structure:"
find artifacts -type d -print
# 查找构建产物
MACOS_ARTIFACT=$(find artifacts -type f -name "*.gz" | head -1 || echo '')
WIN_ARTIFACT=$(find artifacts -type f -name "*.exe" | head -1 || echo '')
# 获取下载URL
MACOS_URL=""
WIN_URL=""
if [ -n "$MACOS_ARTIFACT" ]; then
MACOS_URL="https://gh-proxy.com/https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/$(basename "$MACOS_ARTIFACT")"
fi
if [ -n "$WIN_ARTIFACT" ]; then
WIN_URL="https://gh-proxy.com/https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/$(basename "$WIN_ARTIFACT")"
fi
# 获取签名内容
MACOS_SIG=""
WIN_SIG=""
if [ -n "$MACOS_ARTIFACT" ]; then
SIG_FILE="${MACOS_ARTIFACT}.sig"
if [ -f "$SIG_FILE" ]; then
MACOS_SIG=$(cat "$SIG_FILE" | tr -d '\n')
fi
fi
if [ -n "$WIN_ARTIFACT" ]; then
SIG_FILE="${WIN_ARTIFACT}.sig"
if [ -f "$SIG_FILE" ]; then
WIN_SIG=$(cat "$SIG_FILE" | tr -d '\n')
fi
fi
# 一次性生成JSON字符串
PLATFORMS_JSON=$(jq -n \
--arg macos_url "$MACOS_URL" \
--arg win_url "$WIN_URL" \
--arg macos_sig "$MACOS_SIG" \
--arg win_sig "$WIN_SIG" \
'{
"darwin-aarch64": ($macos_url | if . != "" then {signature: $macos_sig, url: $macos_url} else null end),
"windows-x86_64": ($win_url | if . != "" then {signature: $win_sig, url: $win_url} else null end)
}')
# 控制台打印json内容
echo $PLATFORMS_JSON
ESCAPED_PLATFORMS_JSON=$(echo "$PLATFORMS_JSON" | jq -c '.')
echo "PLATFORMS_JSON=$ESCAPED_PLATFORMS_JSON" >> $GITHUB_OUTPUT
- name: Update latest.json
run: |
# 使用更安全的JSON生成方式
cat <<EOF > latest.json
{
"version": "${{ fromJson(steps.get_release.outputs.result).version }}",
"notes": "${{ fromJson(steps.get_release.outputs.result).notes }}",
"pub_date": "${{ fromJson(steps.get_release.outputs.result).pub_date }}",
"platforms": ${{ steps.find_assets.outputs.PLATFORMS_JSON }}
}
EOF
cat latest.json
- name: Commit and push changes
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
git add latest.json
git commit -m "Update latest.json for release ${{ fromJson(steps.get_release.outputs.result).version }}"
git push