Build Beta Package #80
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Beta Package | |
on: | |
schedule: | |
- cron: "22 22 * * *" | |
workflow_dispatch: | |
inputs: | |
updater: | |
description: "Enable updater?" | |
required: true | |
type: boolean | |
default: true | |
platform_windows: | |
description: "windows" | |
required: true | |
type: boolean | |
default: true | |
platform_linux: | |
description: "linux" | |
required: true | |
type: boolean | |
default: false | |
platform_macos_aarch64: | |
description: "macos-aarch64" | |
required: true | |
type: boolean | |
default: false | |
platform_macos_x86_64: | |
description: "macos-x86_64" | |
required: true | |
type: boolean | |
default: false | |
retention_days: | |
description: "Artifacts retention time (days)" | |
required: true | |
type: string | |
default: "1" | |
jobs: | |
preprocess: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.setting.outputs.matrix }} | |
retention_days: ${{ steps.setting.outputs.retention_days }} | |
file_prefix: ${{ steps.filename.outputs.file_prefix }} | |
# build_time: ${{ steps.filename.outputs.build_time }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install yq | |
uses: mikefarah/yq@master | |
with: | |
cmd: yq -V | |
- name: Update tauri.conf.json | |
if: ${{ github.event_name != 'schedule' && !inputs.updater }} | |
run: yq -i '.tauri.updater.active = false' src-tauri/tauri.conf.json | |
- name: Upload tauri-config | |
if: ${{ github.event_name != 'schedule' && !inputs.updater }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: tauri-config | |
path: src-tauri/tauri.conf.json | |
retention-days: 1 | |
- name: Get file name | |
id: filename | |
run: | | |
productName=$(yq e -r '.package.productName' src-tauri/tauri.conf.json) | |
# version=$(yq e -r '.version' package.json) | |
# build_time=$(TZ=UTC-8 date +%y%m%d%H) | |
git_des=$(git describe --long --tags --always --dirty | sed 's/-g/-/') | |
echo "file_prefix=${productName}_${git_des}" >> "$GITHUB_OUTPUT" | |
# echo "build_time=${build_time}" >> "$GITHUB_OUTPUT" | |
- name: Setting variable | |
id: setting | |
run: | | |
matrix="" | |
if [ "${{ github.event_name }}" == "schedule" ]; then | |
matrix="\"windows-latest\",\"ubuntu-20.04\",\"macos-latest\",\"macos-12\"" | |
retention_days='1' | |
else | |
if [ "${{ inputs.platform_windows }}" == "true" ]; then | |
matrix="${matrix}\"windows-latest\"," | |
fi | |
if [ "${{ inputs.platform_linux }}" == "true" ]; then | |
matrix="${matrix}\"ubuntu-20.04\"," | |
fi | |
if [ "${{ inputs.platform_macos_aarch64 }}" == "true" ]; then | |
matrix="${matrix}\"macos-latest\"," | |
fi | |
if [ "${{ inputs.platform_macos_x86_64 }}" == "true" ]; then | |
matrix="${matrix}\"macos-12\"," | |
fi | |
if [ -z "${matrix}" ]; then | |
matrix="\"windows-latest\"," | |
fi | |
matrix="${matrix%,}" | |
retention_days="${{ inputs.retention_days }}" | |
fi | |
echo "matrix=[${matrix}]" >> "$GITHUB_OUTPUT" | |
echo "retention_days=${retention_days}" >> "$GITHUB_OUTPUT" | |
auto-build: | |
needs: preprocess | |
permissions: | |
contents: write | |
strategy: | |
fail-fast: false | |
matrix: | |
os: ${{ fromJson(needs.preprocess.outputs.matrix) }} | |
runs-on: ${{ matrix.os }} | |
env: | |
RETENTION_DAYS: ${{ needs.preprocess.outputs.retention_days }} | |
FILE_PREFIX: ${{ needs.preprocess.outputs.file_prefix }} | |
# BUILD_TIME: ${{ needs.preprocess.outputs.build_time }} | |
TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }} | |
TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }} | |
NO_STRIP: true | |
CI: false | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Download artifact | |
if: ${{ github.event_name != 'schedule' && !inputs.updater }} | |
uses: actions/download-artifact@v4 | |
with: | |
name: tauri-config | |
path: src-tauri | |
- name: Install pnpm | |
uses: pnpm/action-setup@v3 | |
with: | |
version: latest | |
- name: Install Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
cache: pnpm | |
- name: Install dependencies (ubuntu only) | |
if: matrix.os == 'ubuntu-20.04' | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libayatana-appindicator3-dev librsvg2-dev patchelf | |
# webkitgtk 4.0 适用于 Tauri v1,webkitgtk 4.1 适用于 Tauriv2 | |
- name: Install Rust | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
# 那些目标仅在 macos 运行器上使用,因此将其置于 `if` 语句中,以稍微加快 Windows 和 Linux 的构建速度。 | |
targets: ${{ startsWith(matrix.os, 'macos') && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }} | |
- name: Rust cache | |
uses: swatinem/rust-cache@v2 | |
with: | |
workspaces: "./src-tauri -> target" | |
- name: Install dependencies | |
run: pnpm install --frozen-lockfile | |
- name: Build the app | |
run: pnpm tauri build | |
- name: Rename macos-aarch64 | |
if: matrix.os == 'macos-latest' | |
run: mv src-tauri/target/release/bundle/dmg/*.dmg src-tauri/target/${{ env.FILE_PREFIX }}-aarch64.dmg | |
- name: Rename macos-x86_64 | |
if: matrix.os == 'macos-12' | |
run: mv src-tauri/target/release/bundle/dmg/*.dmg src-tauri/target/${{ env.FILE_PREFIX }}-x64.dmg | |
- name: Rename windows | |
if: matrix.os == 'windows-latest' | |
run: mv src-tauri/target/release/bundle/nsis/*.exe src-tauri/target/${{ env.FILE_PREFIX }}-x64.exe | |
- name: Rename linux | |
if: matrix.os == 'ubuntu-20.04' | |
run: | | |
mv src-tauri/target/release/bundle/deb/*.deb src-tauri/target/${{ env.FILE_PREFIX }}-x64.deb | |
mv src-tauri/target/release/bundle/rpm/*.rpm src-tauri/target/${{ env.FILE_PREFIX }}-x64.rpm | |
mv src-tauri/target/release/bundle/appimage/*.AppImage src-tauri/target/${{ env.FILE_PREFIX }}-x64.AppImage | |
- name: Upload artifacts (Windows) | |
if: matrix.os == 'windows-latest' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ env.FILE_PREFIX }}_windows-x64 | |
path: src-tauri/target/*.exe | |
retention-days: ${{ env.RETENTION_DAYS}} | |
compression-level: 0 | |
- name: Upload artifacts (MacOS) | |
if: startsWith(matrix.os, 'macos') | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ env.FILE_PREFIX }}_${{ matrix.os == 'macos-latest' && 'macos-aarch64' || 'macos-x64' }} | |
path: src-tauri/target/*.dmg | |
retention-days: ${{ env.RETENTION_DAYS}} | |
compression-level: 0 | |
- name: Upload artifacts (Linux) | |
if: matrix.os == 'ubuntu-20.04' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ env.FILE_PREFIX }}_linux-x64 | |
path: | | |
src-tauri/target/*.deb | |
src-tauri/target/*.rpm | |
src-tauri/target/*.AppImage | |
retention-days: ${{ env.RETENTION_DAYS}} | |
compression-level: 0 |