build(workflow): 更新 GitHub Actions 工作流配置 #94

This commit is contained in:
LOG1997
2025-12-09 21:16:59 +08:00
parent fdd0aeef1c
commit 8e2e131625
7 changed files with 169 additions and 42 deletions

55
.github/workflows/buildapp.yml vendored Normal file
View File

@@ -0,0 +1,55 @@
name: Build and Release Tauri App
on:
push:
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
jobs:
publish-tauri:
permissions:
contents: write
strategy:
fail-fast: false
matrix:
platform: [macos-latest, ubuntu-20.04, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install dependencies (ubuntu only)
if: matrix.platform == 'ubuntu-20.04'
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
workspaces: ./src-tauri -> target
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 'lts/*'
cache: pnpm
- name: Install frontend dependencies
run: pnpm install
- name: Build the app
uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tagName: ${{ github.ref_name }} # the action automatically replaces \_\_VERSION\_\_ with the app version
releaseName: 'App ${{ github.ref_name }}'
releaseBody: See the assets to download this version and install.
releaseDraft: true
prerelease: false

View File

@@ -5,7 +5,7 @@ name: Node.js CI
on:
pull_request:
branches: [ "main" ]
branches: [main]
jobs:
build:
@@ -19,26 +19,24 @@ jobs:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
- run: pnpm install
- run: pnpm build
- name: Copy and Rename index.html to dist
run: cp dist/index.html dist/404.html
- name: Deploy to gh-pages
uses: crazy-max/ghaction-github-pages@v2
with:
target_branch: gh-pages
build_dir: dist
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: pnpm
- run: pnpm install
- run: pnpm build
- name: Copy and Rename index.html to dist
run: cp dist/index.html dist/404.html
- name: Deploy to gh-pages
uses: crazy-max/ghaction-github-pages@v2
with:
target_branch: gh-pages
build_dir: dist
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}

View File

@@ -6,12 +6,12 @@ on:
- 'v*'
jobs:
build-and-release:
build-web:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v3
@@ -26,8 +26,8 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '22.x'
cache: 'pnpm'
node-version: 22.x
cache: pnpm
- name: Install dependencies
run: pnpm install
@@ -35,9 +35,6 @@ jobs:
- name: Build for production
run: pnpm build
- name: Build for file protocol
run: pnpm build:file
- name: Prepare directories
run: |
mv dist dist-prod
@@ -45,18 +42,72 @@ jobs:
- name: Create production build archive
run: |
tar -czf dist.tar.gz dist-prod
zip -r dist.zip dist-prod
- name: Create file protocol build archive
run: |
tar -czf dist-file.tar.gz dist-file
- name: Upload web build artifact
uses: actions/upload-artifact@v3
with:
name: web-build
path: dist.zip
- name: Release
publish-tauri:
permissions:
contents: write
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
workspaces: ./src-tauri -> target
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 'lts/*'
cache: pnpm
- name: Install frontend dependencies
run: pnpm install
- name: Build the app
uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tagName: ${{ github.ref_name }}
releaseBody: See the assets to download this version and install.
releaseDraft: true
prerelease: false
release:
needs: [build-web, publish-tauri]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Download web build artifact
uses: actions/download-artifact@v3
with:
name: web-build
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: |
dist.tar.gz
dist-file.tar.gz
dist.zip
draft: true
prerelease: false
generate_release_notes: true
generate_release_notes: true

22
build/syncVersion.js Normal file
View File

@@ -0,0 +1,22 @@
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// 读取 package.json 版本号
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
const version = packageJson.version;
// 读取并更新 tauri.conf.json
const tauriConfPath = path.join(__dirname, '..', 'src-tauri', 'tauri.conf.json');
const tauriConf = JSON.parse(fs.readFileSync(tauriConfPath, 'utf8'));
// 更新版本号
tauriConf.version = version;
// 写回 tauri.conf.json
fs.writeFileSync(tauriConfPath, JSON.stringify(tauriConf, null, 2));
console.log(`Tauri 配置版本号已同步至: ${version}`);

View File

@@ -2,7 +2,7 @@ import antfu from '@antfu/eslint-config'
export default antfu(
{
ignores: ['**/node_modules', '**/public', '**/dist', '**/package.json', '**/*.yaml', '**/.gitignore', '**/.env*', '**/tsconfig*', '**/*.config.js'],
ignores: ['**/node_modules', '**/build', '**/public', '**/dist', '**/package.json', '**/*.yaml', '**/.gitignore', '**/.env*', '**/tsconfig*', '**/*.config.js'],
},
{
rules: {

View File

@@ -9,6 +9,7 @@
"build": "vue-tsc --noEmit && vite build",
"build:pre": "vue-tsc --noEmit && vite build --mode prebuild",
"build:file": "vue-tsc --noEmit && vite build --mode file",
"tauri":"node ./build/syncVersion.js && tauri",
"test": "vitest",
"test:ui": "vitest --ui",
"preview": "vite preview",

View File

@@ -1,7 +1,7 @@
{
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
"productName": "log-lottery",
"version": "0.1.0",
"version": "0.0.4",
"identifier": "to2026.xyz",
"build": {
"frontendDist": "../dist",
@@ -34,4 +34,4 @@
"icons/icon.ico"
]
}
}
}