refactor(bgm-auth): tighten token types and rename BGM_TOKEN to bgmToken #317
This file contains hidden or 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 & Test Common | |
| on: | |
| push: | |
| branches: ["main"] | |
| pull_request: | |
| branches: ["main"] | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - os: ubuntu-22.04 | |
| rust_target: x86_64-unknown-linux-gnu | |
| - os: ubuntu-22.04-arm | |
| rust_target: aarch64-unknown-linux-gnu | |
| - os: windows-latest | |
| rust_target: x86_64-pc-windows-msvc | |
| - os: windows-latest | |
| rust_target: aarch64-pc-windows-msvc | |
| # 主仓库可以访问 TAURI_KEY environment,fork PR 访问不到但不会失败 | |
| environment: ${{ (github.event.pull_request.head.repo.full_name == github.repository || github.event_name != 'pull_request') && 'TAURI_KEY' || '' }} | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Install Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| - name: Install pnpm | |
| uses: pnpm/action-setup@v5 | |
| with: | |
| version: 10 | |
| run_install: false | |
| - name: Get pnpm store directory | |
| if: runner.os == 'Windows' | |
| id: pnpm-store | |
| shell: bash | |
| run: | | |
| echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.rust_target }} | |
| - name: Rust cache | |
| uses: swatinem/rust-cache@v2 | |
| with: | |
| workspaces: "./src-tauri -> target" | |
| shared-key: ${{ matrix.rust_target }} | |
| - name: Install dependencies | |
| run: pnpm install | |
| - name: Get version | |
| id: get_version | |
| shell: bash | |
| run: | | |
| VERSION=$(node -p "require('./package.json').version") | |
| echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Version is $VERSION" | |
| - name: Compute short target name | |
| id: short | |
| shell: bash | |
| run: | | |
| case "${{ matrix.rust_target }}" in | |
| *x86_64-pc-windows*) SHORT=win_x64 ;; | |
| *aarch64-pc-windows*) SHORT=win_arm64 ;; | |
| *x86_64-unknown-linux-gnu*) SHORT=linux_x64 ;; | |
| *aarch64-unknown-linux-gnu*) SHORT=linux_arm64 ;; | |
| *) SHORT=unknown ;; | |
| esac | |
| echo "SHORT=$SHORT" >> $GITHUB_OUTPUT | |
| # Linux 专用:使用官方 Action 安装最新版 mold | |
| # 这比 apt-get 安装的旧版本快且稳,而且会自动配置相关环境 | |
| - name: Install Mold (Linux) | |
| if: runner.os == 'Linux' | |
| uses: rui314/setup-mold@v1 | |
| # Linux 依赖安装 (去掉了 mold,因为上一步已经安装) | |
| - name: Install system dependencies (Linux) | |
| if: runner.os == 'Linux' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libgtk-3-dev libsoup-3.0-dev libwebkit2gtk-4.0-dev libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf clang | |
| # 配置链接器 (核心逻辑) | |
| - name: Configure Rust linker | |
| shell: bash | |
| run: | | |
| mkdir -p .cargo | |
| # === Linux 配置 === | |
| if [[ "${{ matrix.os }}" == "ubuntu-22.04" ]] || [[ "${{ matrix.os }}" == "ubuntu-22.04-arm" ]]; then | |
| echo "Configuring mold for Linux..." | |
| cat >> .cargo/config.toml <<EOF | |
| [target.x86_64-unknown-linux-gnu] | |
| linker = "clang" | |
| rustflags = ["-C", "link-arg=-fuse-ld=mold"] | |
| EOF | |
| # === Windows 配置 === | |
| elif [[ "${{ matrix.os }}" == "windows-latest" ]]; then | |
| echo "Configuring lld for Windows..." | |
| cat >> .cargo/config.toml <<EOF | |
| [target.x86_64-pc-windows-msvc] | |
| linker = "rust-lld.exe" | |
| [target.aarch64-pc-windows-msvc] | |
| linker = "rust-lld.exe" | |
| EOF | |
| fi | |
| - name: Build with Tauri Action | |
| uses: tauri-apps/tauri-action@v0 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }} | |
| TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}, | |
| BGM_APP_SECRET: ${{ secrets.BGM_APP_SECRET }} | |
| CARGO_INCREMENTAL: 0 | |
| with: | |
| # 不在这里创建 GitHub release,仅构建 | |
| args: >- | |
| --target ${{ matrix.rust_target }} | |
| ${{ | |
| (github.event.pull_request.head.repo.full_name == github.repository || github.event_name != 'pull_request') | |
| && '' | |
| || '-c ''{"bundle": {"createUpdaterArtifacts": false}}''' | |
| }} | |
| tagName: "" | |
| releaseName: "" | |
| releaseBody: "" | |
| releaseDraft: false | |
| prerelease: false | |
| includeDebug: false | |
| includeRelease: true | |
| tauriScript: pnpm tauri | |
| - name: Prepare portable package (Windows) | |
| if: matrix.os == 'windows-latest' | |
| shell: pwsh | |
| run: | | |
| $version = "${{ steps.get_version.outputs.VERSION }}" | |
| $short = "${{ steps.short.outputs.SHORT }}" | |
| $target = "${{ matrix.rust_target }}" | |
| $portableRoot = "src-tauri/target/$target/release/portable/ReinaManager-$version-$short" | |
| $resourcesDataDir = Join-Path $portableRoot "resources/data" | |
| if (Test-Path $portableRoot) { | |
| Remove-Item $portableRoot -Recurse -Force | |
| } | |
| New-Item -ItemType Directory -Path $resourcesDataDir -Force | Out-Null | |
| @" | |
| 该文件夹为数据库文件夹,删除该文件夹则退出便携模式,反之则保持便携模式。 | |
| This folder stores the database. Deleting this folder exits portable mode; keeping it preserves portable mode. | |
| "@ | Set-Content -Path (Join-Path $resourcesDataDir "readme.txt") -Encoding UTF8 | |
| Copy-Item "src-tauri/target/$target/release/ReinaManager.exe" "$portableRoot/ReinaManager.exe" | |
| # 显示构建状态 | |
| - name: Build status | |
| shell: bash | |
| run: | | |
| if [ "${{ github.event_name }}" == "pull_request" ] && [ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]; then | |
| echo "⚠️ Fork PR: Build completed WITHOUT signing" | |
| echo " The application will work normally but won't support auto-updates" | |
| else | |
| echo "✅ Build completed with signing enabled and auto-update support" | |
| fi | |
| # Upload build artifacts for testings | |
| - name: Upload Portable Package (Artifact) | |
| if: matrix.os == 'windows-latest' | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: ReinaManager-${{ steps.get_version.outputs.VERSION }}-${{ steps.short.outputs.SHORT }}-portable | |
| path: src-tauri/target/${{ matrix.rust_target }}/release/portable/ReinaManager-${{ steps.get_version.outputs.VERSION }}-${{ steps.short.outputs.SHORT }} | |
| if-no-files-found: warn | |
| - name: Upload MSI Installer (Artifact) | |
| if: matrix.os == 'windows-latest' | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: ReinaManager-${{ steps.get_version.outputs.VERSION }}-${{ steps.short.outputs.SHORT }}-msi | |
| path: src-tauri/target/${{ matrix.rust_target }}/release/bundle/msi/*.msi | |
| if-no-files-found: warn | |
| - name: Upload NSIS Installer (Artifact) | |
| if: matrix.os == 'windows-latest' | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: ReinaManager-${{ steps.get_version.outputs.VERSION }}-${{ steps.short.outputs.SHORT }}-setup | |
| path: src-tauri/target/${{ matrix.rust_target }}/release/bundle/nsis/*.exe | |
| if-no-files-found: warn | |
| - name: Upload deb (Artifact) | |
| if: matrix.os == 'ubuntu-22.04' || matrix.os == 'ubuntu-22.04-arm' | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: ReinaManager-${{ steps.get_version.outputs.VERSION }}-${{ steps.short.outputs.SHORT }}-deb | |
| path: src-tauri/target/${{ matrix.rust_target }}/release/bundle/deb/*.deb | |
| if-no-files-found: warn | |
| - name: Upload rpm (Artifact) | |
| if: matrix.os == 'ubuntu-22.04' || matrix.os == 'ubuntu-22.04-arm' | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: ReinaManager-${{ steps.get_version.outputs.VERSION }}-${{ steps.short.outputs.SHORT }}-rpm | |
| path: src-tauri/target/${{ matrix.rust_target }}/release/bundle/rpm/*.rpm | |
| if-no-files-found: warn | |
| - name: Upload AppImage (Artifact) | |
| if: matrix.os == 'ubuntu-22.04' || matrix.os == 'ubuntu-22.04-arm' | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: ReinaManager-${{ steps.get_version.outputs.VERSION }}-${{ steps.short.outputs.SHORT }}-appimage | |
| path: src-tauri/target/${{ matrix.rust_target }}/release/bundle/appimage/*.AppImage | |
| if-no-files-found: warn |