diff --git a/.github/workflows/buildapp.yml b/.github/workflows/buildapp.yml new file mode 100644 index 0000000..99ca664 --- /dev/null +++ b/.github/workflows/buildapp.yml @@ -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 diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 123fe4c..f3974ab 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -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 }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 002c943..9f39982 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 \ No newline at end of file + generate_release_notes: true diff --git a/build/syncVersion.js b/build/syncVersion.js new file mode 100644 index 0000000..869cee0 --- /dev/null +++ b/build/syncVersion.js @@ -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}`); \ No newline at end of file diff --git a/eslint.config.js b/eslint.config.js index 4a63dce..b512ed3 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -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: { diff --git a/package.json b/package.json index f0350b9..3193e95 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 38cdd41..e736ed4 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -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" ] } -} +} \ No newline at end of file