From 1b94adc2a301fe1c7fbbb7681b5be3e14cb63781 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Fri, 29 Aug 2025 17:30:37 +0800 Subject: [PATCH] :art: Refactoring actions --- .github/actions/setup-node.yml | 31 +++++ .github/actions/setup-rust-cache.yml | 40 ++++++ .github/actions/setup-rust.yml | 45 +++++++ .github/actions/setup-ubuntu-deps.yml | 11 ++ .github/actions/setup-windows.yml | 21 +++ .github/workflows/pake-cli.yaml | 55 +++----- .github/workflows/quality-and-test.yml | 169 +++++++------------------ .github/workflows/single-app.yaml | 38 ++---- 8 files changed, 224 insertions(+), 186 deletions(-) create mode 100644 .github/actions/setup-node.yml create mode 100644 .github/actions/setup-rust-cache.yml create mode 100644 .github/actions/setup-rust.yml create mode 100644 .github/actions/setup-ubuntu-deps.yml create mode 100644 .github/actions/setup-windows.yml diff --git a/.github/actions/setup-node.yml b/.github/actions/setup-node.yml new file mode 100644 index 0000000..61e34b8 --- /dev/null +++ b/.github/actions/setup-node.yml @@ -0,0 +1,31 @@ +name: Setup Node.js Environment +description: Install Node.js and pnpm with caching + +inputs: + node-version: + description: Node.js version to install + required: false + default: '22' + pnpm-version: + description: pnpm version to install + required: false + default: '10.15.0' + +runs: + using: composite + steps: + - name: Install pnpm + uses: pnpm/action-setup@v4 + with: + version: ${{ inputs.pnpm-version }} + run_install: false + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node-version }} + cache: pnpm + + - name: Install dependencies + shell: bash + run: pnpm install --frozen-lockfile \ No newline at end of file diff --git a/.github/actions/setup-rust-cache.yml b/.github/actions/setup-rust-cache.yml new file mode 100644 index 0000000..dc6e427 --- /dev/null +++ b/.github/actions/setup-rust-cache.yml @@ -0,0 +1,40 @@ +name: Setup Rust Cache +description: Setup Rust dependency caching with restore and save + +inputs: + save-cache: + description: Whether to save cache after build + required: false + default: 'false' + +outputs: + cache-hit: + description: Whether cache was restored successfully + value: ${{ steps.cache_restore.outputs.cache-hit }} + +runs: + using: composite + steps: + - name: Rust cache restore + uses: actions/cache/restore@v4.2.0 + id: cache_restore + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + src-tauri/target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + - name: Rust cache save + if: inputs.save-cache == 'true' + uses: actions/cache/save@v4.2.0 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + src-tauri/target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} \ No newline at end of file diff --git a/.github/actions/setup-rust.yml b/.github/actions/setup-rust.yml new file mode 100644 index 0000000..22591e3 --- /dev/null +++ b/.github/actions/setup-rust.yml @@ -0,0 +1,45 @@ +name: Setup Rust Environment +description: Install and configure Rust toolchain with platform-specific targets + +inputs: + platform: + description: Platform to setup Rust for + required: true + components: + description: Additional Rust components to install + required: false + default: '' + +runs: + using: composite + steps: + - name: Install Rust for Linux + if: contains(inputs.platform, 'ubuntu') + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + target: x86_64-unknown-linux-gnu + components: ${{ inputs.components }} + + - name: Install Rust for Windows + if: contains(inputs.platform, 'windows') + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable-x86_64-msvc + target: x86_64-pc-windows-msvc + components: ${{ inputs.components }} + + - name: Install Rust for macOS + if: contains(inputs.platform, 'macos') + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + target: x86_64-apple-darwin + components: ${{ inputs.components }} + + - name: Add macOS universal targets + if: contains(inputs.platform, 'macos') + shell: bash + run: | + rustup target add aarch64-apple-darwin + rustup target add x86_64-apple-darwin \ No newline at end of file diff --git a/.github/actions/setup-ubuntu-deps.yml b/.github/actions/setup-ubuntu-deps.yml new file mode 100644 index 0000000..de50b16 --- /dev/null +++ b/.github/actions/setup-ubuntu-deps.yml @@ -0,0 +1,11 @@ +name: Setup Ubuntu Dependencies +description: Install system dependencies required for Tauri on Ubuntu + +runs: + using: composite + steps: + - name: Install Ubuntu system dependencies + uses: awalsh128/cache-apt-pkgs-action@v1.4.3 + with: + packages: libdbus-1-dev libsoup-3.0-dev libjavascriptcoregtk-4.1-dev libwebkit2gtk-4.1-dev build-essential curl wget file libxdo-dev libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev gnome-video-effects gnome-video-effects-extra + version: 1.1 \ No newline at end of file diff --git a/.github/actions/setup-windows.yml b/.github/actions/setup-windows.yml new file mode 100644 index 0000000..9a840c8 --- /dev/null +++ b/.github/actions/setup-windows.yml @@ -0,0 +1,21 @@ +name: Setup Windows Environment +description: Install WIX Toolset and other Windows-specific dependencies + +runs: + using: composite + steps: + - name: Install WIX Toolset + shell: powershell + run: | + # Download and install WIX Toolset v3.11 + Invoke-WebRequest -Uri "https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311.exe" -OutFile "wix311.exe" + Start-Process -FilePath "wix311.exe" -ArgumentList "/quiet" -Wait + + # Add WIX to PATH + $wixPath = "${env:ProgramFiles(x86)}\WiX Toolset v3.11\bin" + if (Test-Path $wixPath) { + echo $wixPath >> $env:GITHUB_PATH + echo "WIX Toolset installed successfully" + } else { + echo "Warning: WIX installation path not found" + } \ No newline at end of file diff --git a/.github/workflows/pake-cli.yaml b/.github/workflows/pake-cli.yaml index 98d565b..fb1f4a0 100644 --- a/.github/workflows/pake-cli.yaml +++ b/.github/workflows/pake-cli.yaml @@ -1,4 +1,9 @@ name: Build App With Pake CLI + +env: + NODE_VERSION: '22' + PNPM_VERSION: '10.15.0' + on: workflow_dispatch: inputs: @@ -64,50 +69,20 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Install pnpm - uses: pnpm/action-setup@v4 + - name: Setup Node.js Environment + uses: ./.github/actions/setup-node.yml with: - version: 10.15.0 - run_install: false + node-version: ${{ env.NODE_VERSION }} + pnpm-version: ${{ env.PNPM_VERSION }} - - name: Install node - uses: actions/setup-node@v4 + - name: Setup Rust Environment + uses: ./.github/actions/setup-rust.yml with: - node-version: 22 - cache: "pnpm" + platform: ${{ inputs.platform }} - - name: Install Rust for ubuntu-24.04 - if: inputs.platform == 'ubuntu-24.04' - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - target: x86_64-unknown-linux-musl - - - name: Install Rust for windows-latest - if: inputs.platform == 'windows-latest' - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable-x86_64-msvc - target: x86_64-pc-windows-msvc - - - name: Install Rust for macos-latest - if: inputs.platform == 'macos-latest' - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - target: x86_64-apple-darwin - - - name: Add additional Rust target for multi-arch - if: inputs.platform == 'macos-latest' && inputs.multi_arch == true - run: | - rustup target add aarch64-apple-darwin - - - name: Install dependencies (ubuntu only) - if: inputs.platform == 'ubuntu-24.04' - uses: awalsh128/cache-apt-pkgs-action@v1.4.3 - with: - packages: libsoup-3.0-dev libdbus-1-dev libjavascriptcoregtk-4.1-dev libwebkit2gtk-4.1-dev build-essential curl wget file libxdo-dev libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev gnome-video-effects gnome-video-effects-extra - version: 1.1 + - name: Setup Ubuntu Dependencies + if: contains(inputs.platform, 'ubuntu') + uses: ./.github/actions/setup-ubuntu-deps.yml - name: Cache Node dependencies uses: actions/cache@v4 diff --git a/.github/workflows/quality-and-test.yml b/.github/workflows/quality-and-test.yml index e12c279..e9be831 100644 --- a/.github/workflows/quality-and-test.yml +++ b/.github/workflows/quality-and-test.yml @@ -7,6 +7,13 @@ on: branches: [main, dev] workflow_dispatch: +env: + NODE_VERSION: '22' + PNPM_VERSION: '10.15.0' + UBUNTU_DEPS_VERSION: '1.1' + ACTIONS_CHECKOUT_VERSION: 'v4' + CACHE_VERSION: 'v4.2.0' + permissions: actions: write contents: read @@ -19,7 +26,7 @@ jobs: auto-format: name: Auto-fix Formatting runs-on: ubuntu-latest - if: github.ref != 'refs/heads/main' && github.event_name != 'pull_request' + if: github.ref != 'refs/heads/main' && github.event_name == 'push' permissions: contents: write steps: @@ -27,25 +34,18 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} - - name: Install pnpm - uses: pnpm/action-setup@v4 + - name: Setup Node.js Environment + uses: ./.github/actions/setup-node.yml with: - version: 10.15.0 - run_install: false + node-version: ${{ env.NODE_VERSION }} + pnpm-version: ${{ env.PNPM_VERSION }} - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: "22" - cache: "pnpm" - - - name: Setup Rust - uses: actions-rust-lang/setup-rust-toolchain@v1 + - name: Setup Rust Environment + uses: ./.github/actions/setup-rust.yml with: + platform: ubuntu-latest components: rustfmt - - name: Install dependencies - run: pnpm install --frozen-lockfile - name: Auto-fix Prettier formatting run: npx prettier --write . --ignore-unknown @@ -73,20 +73,12 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install pnpm - uses: pnpm/action-setup@v4 + - name: Setup Node.js Environment + uses: ./.github/actions/setup-node.yml with: - version: 10.15.0 - run_install: false + node-version: ${{ env.NODE_VERSION }} + pnpm-version: ${{ env.PNPM_VERSION }} - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: "22" - cache: "pnpm" - - - name: Install dependencies - run: pnpm install --frozen-lockfile - name: Check EditorConfig compliance uses: editorconfig-checker/action-editorconfig-checker@main @@ -111,8 +103,10 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions-rust-lang/setup-rust-toolchain@v1 + - name: Setup Rust Environment + uses: ./.github/actions/setup-rust.yml with: + platform: ${{ matrix.os }} components: rustfmt, clippy - uses: rui314/setup-mold@v1 @@ -122,12 +116,9 @@ jobs: with: tool: cargo-hack - - name: Install Ubuntu dependencies + - name: Setup Ubuntu Dependencies if: matrix.os == 'ubuntu-latest' - uses: awalsh128/cache-apt-pkgs-action@v1.4.3 - with: - packages: libdbus-1-dev libsoup-3.0-dev libjavascriptcoregtk-4.1-dev libwebkit2gtk-4.1-dev build-essential curl wget file libxdo-dev libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev gnome-video-effects gnome-video-effects-extra - version: 1.0 + uses: ./.github/actions/setup-ubuntu-deps.yml - name: Check Rust formatting run: cargo fmt --all -- --color=always --check @@ -146,65 +137,25 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Install pnpm - uses: pnpm/action-setup@v4 + - name: Setup Node.js Environment + uses: ./.github/actions/setup-node.yml with: - version: 10.15.0 - run_install: false + node-version: ${{ env.NODE_VERSION }} + pnpm-version: ${{ env.PNPM_VERSION }} - - name: Setup Node.js - uses: actions/setup-node@v4 + - name: Setup Rust Environment + uses: ./.github/actions/setup-rust.yml with: - node-version: 22 - cache: "pnpm" + platform: ${{ matrix.os }} - - name: Install Rust (Ubuntu) + + - name: Setup Ubuntu Dependencies if: matrix.os == 'ubuntu-latest' - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - target: x86_64-unknown-linux-gnu + uses: ./.github/actions/setup-ubuntu-deps.yml - - name: Install Rust (Windows) + - name: Setup Windows Environment if: matrix.os == 'windows-latest' - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable-x86_64-msvc - target: x86_64-pc-windows-msvc - - - name: Install Rust (macOS) - if: matrix.os == 'macos-latest' - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - target: x86_64-apple-darwin - - - name: Install WIX Toolset (Windows) - if: matrix.os == 'windows-latest' - run: | - # Download and install WIX Toolset v3.11 - Invoke-WebRequest -Uri "https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311.exe" -OutFile "wix311.exe" - Start-Process -FilePath "wix311.exe" -ArgumentList "/quiet" -Wait - - # Add WIX to PATH - $wixPath = "${env:ProgramFiles(x86)}\WiX Toolset v3.11\bin" - if (Test-Path $wixPath) { - echo $wixPath >> $env:GITHUB_PATH - echo "WIX Toolset installed successfully" - } else { - echo "Warning: WIX installation path not found" - } - shell: powershell - - - name: Install system dependencies (Ubuntu) - if: matrix.os == 'ubuntu-latest' - uses: awalsh128/cache-apt-pkgs-action@v1.4.3 - with: - packages: libdbus-1-dev libsoup-3.0-dev libjavascriptcoregtk-4.1-dev libwebkit2gtk-4.1-dev build-essential curl wget file libxdo-dev libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev gnome-video-effects gnome-video-effects-extra - version: 1.1 - - - name: Install dependencies - run: pnpm install --frozen-lockfile + uses: ./.github/actions/setup-windows.yml - name: Build CLI run: pnpm run cli:build @@ -237,38 +188,16 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Install pnpm - uses: pnpm/action-setup@v4 + - name: Setup Node.js Environment + uses: ./.github/actions/setup-node.yml with: - version: 10.15.0 - run_install: false + node-version: ${{ env.NODE_VERSION }} + pnpm-version: ${{ env.PNPM_VERSION }} - - name: Setup Node.js - uses: actions/setup-node@v4 + - name: Setup Rust Environment + uses: ./.github/actions/setup-rust.yml with: - node-version: 22 - cache: "pnpm" - - - name: Install Rust (Ubuntu) - if: matrix.os == 'ubuntu-latest' - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - target: x86_64-unknown-linux-gnu - - - name: Install Rust (Windows) - if: matrix.os == 'windows-latest' - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable-x86_64-msvc - target: x86_64-pc-windows-msvc - - - name: Install Rust (macOS) - if: matrix.os == 'macos-latest' - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - target: x86_64-apple-darwin + platform: ${{ matrix.os }} - name: Add macOS targets if: matrix.os == 'macos-latest' @@ -276,15 +205,13 @@ jobs: rustup target add aarch64-apple-darwin rustup target add x86_64-apple-darwin - - name: Install system dependencies (Ubuntu) + - name: Setup Ubuntu Dependencies if: matrix.os == 'ubuntu-latest' - uses: awalsh128/cache-apt-pkgs-action@v1.4.3 - with: - packages: libdbus-1-dev libsoup-3.0-dev libjavascriptcoregtk-4.1-dev libwebkit2gtk-4.1-dev build-essential curl wget file libxdo-dev libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev gnome-video-effects gnome-video-effects-extra - version: 1.1 + uses: ./.github/actions/setup-ubuntu-deps.yml - - name: Install dependencies - run: pnpm install --frozen-lockfile + - name: Setup Windows Environment + if: matrix.os == 'windows-latest' + uses: ./.github/actions/setup-windows.yml - name: Build CLI run: pnpm run cli:build diff --git a/.github/workflows/single-app.yaml b/.github/workflows/single-app.yaml index 2e9eabf..8a0d132 100644 --- a/.github/workflows/single-app.yaml +++ b/.github/workflows/single-app.yaml @@ -1,4 +1,9 @@ name: Build Single Popular App + +env: + NODE_VERSION: '22' + PNPM_VERSION: '10.15.0' + on: workflow_dispatch: inputs: @@ -72,24 +77,15 @@ jobs: toolchain: ${{ matrix.rust }} target: ${{ matrix.target }} - - name: Install pnpm - uses: pnpm/action-setup@v4 + - name: Setup Node.js Environment + uses: ./.github/actions/setup-node.yml with: - version: 10.15.0 - run_install: false + node-version: ${{ env.NODE_VERSION }} + pnpm-version: ${{ env.PNPM_VERSION }} - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: 22 - cache: "pnpm" - - - name: Install dependencies (ubuntu only) + - name: Setup Ubuntu Dependencies if: matrix.os == 'ubuntu-latest' - uses: awalsh128/cache-apt-pkgs-action@v1.4.3 - with: - packages: libdbus-1-dev libsoup-3.0-dev libjavascriptcoregtk-4.1-dev libwebkit2gtk-4.1-dev build-essential curl wget file libxdo-dev libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev gnome-video-effects gnome-video-effects-extra - version: 1.1 + uses: ./.github/actions/setup-ubuntu-deps.yml - name: Rust cache restore uses: actions/cache/restore@v4.2.0 @@ -109,15 +105,7 @@ jobs: TITLE: ${{ inputs.title }} NAME_ZH: ${{ inputs.name_zh }} URL: ${{ inputs.url }} - run: | - pnpm install --frozen-lockfile - pnpm run build:config - - - name: Add Rust targets for macOS universal build - if: matrix.os == 'macos-latest' - run: | - rustup target add aarch64-apple-darwin - rustup target add x86_64-apple-darwin + run: pnpm run build:config - name: Build for Linux if: matrix.os == 'ubuntu-latest' @@ -172,7 +160,7 @@ jobs: retention-days: 3 - name: Upload to release - uses: ncipollo/release-action@v1 + uses: ncipollo/release-action@v1 # cspell:disable-line if: startsWith(github.ref, 'refs/tags/') with: allowUpdates: true