From 0df25f154e87eb7d4f253803cbac66d4523c304f Mon Sep 17 00:00:00 2001 From: liangxu Date: Wed, 6 May 2026 22:22:06 +0800 Subject: [PATCH] refactor(workflow): unify macOS and Windows client build steps into a single desktop client build job --- .gitea/workflows/desktop-client-build.yml | 161 ++++++++-------------- 1 file changed, 56 insertions(+), 105 deletions(-) diff --git a/.gitea/workflows/desktop-client-build.yml b/.gitea/workflows/desktop-client-build.yml index 2425fb8..ca892d5 100644 --- a/.gitea/workflows/desktop-client-build.yml +++ b/.gitea/workflows/desktop-client-build.yml @@ -353,15 +353,17 @@ jobs: echo "Use sudo on NAS: ${nas_use_sudo}" echo "NAS output: ${nas_user}@${nas_host}:${output_dir}/${release_name}" - build-mac: - name: Build macOS Client + build-client: + name: Build Desktop Client needs: resolve - if: needs.resolve.outputs.build_mac == 'true' - runs-on: macos-latest + runs-on: ubuntu-latest timeout-minutes: 120 env: + BUILD_MAC: ${{ needs.resolve.outputs.build_mac }} + BUILD_WIN: ${{ needs.resolve.outputs.build_win }} CLIENT_VERSION: ${{ needs.resolve.outputs.client_version }} MAC_ARCH_FLAGS: ${{ needs.resolve.outputs.mac_arch_flags }} + WIN_ARCH_FLAGS: ${{ needs.resolve.outputs.win_arch_flags }} CSC_IDENTITY_AUTO_DISCOVERY: "false" steps: - name: Checkout @@ -381,124 +383,74 @@ jobs: - name: Install dependencies run: pnpm install --frozen-lockfile - - name: Build unsigned macOS package + - name: Build unsigned desktop packages working-directory: apps/desktop-client run: | set -eu - unset CSC_LINK CSC_NAME CSC_KEY_PASSWORD APPLE_ID APPLE_APP_SPECIFIC_PASSWORD APPLE_TEAM_ID + unset CSC_LINK CSC_NAME CSC_KEY_PASSWORD APPLE_ID APPLE_APP_SPECIFIC_PASSWORD APPLE_TEAM_ID WIN_CSC_LINK WIN_CSC_KEY_PASSWORD export CSC_IDENTITY_AUTO_DISCOVERY=false node -e 'const fs = require("fs"); const p = "package.json"; const pkg = JSON.parse(fs.readFileSync(p, "utf8")); pkg.version = process.env.CLIENT_VERSION; fs.writeFileSync(p, `${JSON.stringify(pkg, null, 2)}\n`); console.log(`Desktop client version: ${pkg.version}`);' rm -rf release pnpm run build:obf - pnpm exec electron-builder --mac zip ${MAC_ARCH_FLAGS} --publish never -c.mac.target=zip -c.extraMetadata.version="${CLIENT_VERSION}" - - name: Collect macOS artifacts + if [ "${BUILD_MAC}" = "true" ]; then + pnpm exec electron-builder --mac zip ${MAC_ARCH_FLAGS} --publish never -c.mac.target=zip -c.extraMetadata.version="${CLIENT_VERSION}" + fi + + if [ "${BUILD_WIN}" = "true" ]; then + pnpm exec electron-builder --win zip ${WIN_ARCH_FLAGS} --publish never -c.win.target=zip -c.extraMetadata.version="${CLIENT_VERSION}" + fi + + - name: Collect desktop artifacts working-directory: apps/desktop-client run: | set -eu - artifact_dir="${RUNNER_TEMP}/desktop-client-mac" - mkdir -p "${artifact_dir}" + artifact_root="${RUNNER_TEMP}/desktop-client-artifacts" + mkdir -p "${artifact_root}" - zip_count="$(find release -maxdepth 1 -type f -name "*.zip" | wc -l | tr -d ' ')" - if [ "${zip_count}" = "0" ]; then - echo "::error::No macOS artifacts found" - exit 1 + if [ "${BUILD_MAC}" = "true" ]; then + mkdir -p "${artifact_root}/mac" + mac_zip_count="$(find release -maxdepth 1 -type f -name "*.zip" ! -iname "*win*" ! -iname "*windows*" | wc -l | tr -d ' ')" + if [ "${mac_zip_count}" = "0" ]; then + echo "::error::No macOS zip artifact found" + find release -maxdepth 1 -type f -name "*.zip" -print + exit 1 + fi + if [ "${mac_zip_count}" != "1" ]; then + echo "::error::Expected exactly one macOS zip artifact, found ${mac_zip_count}." + find release -maxdepth 1 -type f -name "*.zip" -print + exit 1 + fi + mac_zip="$(find release -maxdepth 1 -type f -name "*.zip" ! -iname "*win*" ! -iname "*windows*" | head -n1)" + cp -p "${mac_zip}" "${artifact_root}/mac/省心推-mac-${CLIENT_VERSION}.zip" fi - if [ "${zip_count}" != "1" ]; then - echo "::error::Expected exactly one macOS zip artifact for this build, found ${zip_count}." - find release -maxdepth 1 -type f -name "*.zip" -print - exit 1 + if [ "${BUILD_WIN}" = "true" ]; then + mkdir -p "${artifact_root}/win" + win_zip_count="$(find release -maxdepth 1 -type f -name "*.zip" \( -iname "*win*" -o -iname "*windows*" \) | wc -l | tr -d ' ')" + if [ "${win_zip_count}" = "0" ]; then + echo "::error::No Windows zip artifact found" + find release -maxdepth 1 -type f -name "*.zip" -print + exit 1 + fi + if [ "${win_zip_count}" != "1" ]; then + echo "::error::Expected exactly one Windows zip artifact, found ${win_zip_count}." + find release -maxdepth 1 -type f -name "*.zip" -print + exit 1 + fi + win_zip="$(find release -maxdepth 1 -type f -name "*.zip" \( -iname "*win*" -o -iname "*windows*" \) | head -n1)" + cp -p "${win_zip}" "${artifact_root}/win/省心推-win-${CLIENT_VERSION}.zip" fi - mac_zip="$(find release -maxdepth 1 -type f -name "*.zip" | head -n1)" - cp -p "${mac_zip}" "${artifact_dir}/省心推-mac-${CLIENT_VERSION}.zip" - ls -lh "${artifact_dir}" + find "${artifact_root}" -maxdepth 3 -type f -print - - name: Upload macOS artifacts + - name: Upload desktop artifacts uses: actions/upload-artifact@v3 with: - name: mac - path: ${{ runner.temp }}/desktop-client-mac - if-no-files-found: error - retention-days: 14 - - build-win: - name: Build Windows Client - needs: resolve - if: needs.resolve.outputs.build_win == 'true' - runs-on: windows-latest - timeout-minutes: 120 - env: - CLIENT_VERSION: ${{ needs.resolve.outputs.client_version }} - WIN_ARCH_FLAGS: ${{ needs.resolve.outputs.win_arch_flags }} - CSC_IDENTITY_AUTO_DISCOVERY: "false" - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: "20" - - - name: Setup pnpm - shell: pwsh - run: | - corepack enable - corepack prepare pnpm@$env:PNPM_VERSION --activate - - - name: Install dependencies - run: pnpm install --frozen-lockfile - - - name: Build unsigned Windows package - working-directory: apps/desktop-client - shell: pwsh - run: | - Remove-Item Env:CSC_LINK -ErrorAction SilentlyContinue - Remove-Item Env:CSC_NAME -ErrorAction SilentlyContinue - Remove-Item Env:CSC_KEY_PASSWORD -ErrorAction SilentlyContinue - Remove-Item Env:WIN_CSC_LINK -ErrorAction SilentlyContinue - Remove-Item Env:WIN_CSC_KEY_PASSWORD -ErrorAction SilentlyContinue - $env:CSC_IDENTITY_AUTO_DISCOVERY = "false" - - node -e "const fs = require('fs'); const p = 'package.json'; const pkg = JSON.parse(fs.readFileSync(p, 'utf8')); pkg.version = process.env.CLIENT_VERSION; fs.writeFileSync(p, JSON.stringify(pkg, null, 2) + '\n'); console.log('Desktop client version: ' + pkg.version);" - - Remove-Item -Recurse -Force release -ErrorAction SilentlyContinue - pnpm run build:obf - - $archFlags = $env:WIN_ARCH_FLAGS -split " " | Where-Object { $_ } - pnpm exec electron-builder --win zip @archFlags --publish never "-c.win.target=zip" "-c.extraMetadata.version=$env:CLIENT_VERSION" - - - name: Collect Windows artifacts - working-directory: apps/desktop-client - shell: pwsh - run: | - $artifactDir = Join-Path $env:RUNNER_TEMP "desktop-client-win" - New-Item -ItemType Directory -Force -Path $artifactDir | Out-Null - - $files = Get-ChildItem -Path release -Filter "*.zip" -File -ErrorAction SilentlyContinue - - if (-not $files) { - throw "No Windows artifacts found" - } - - $zipFiles = $files | Sort-Object FullName -Unique - if ($zipFiles.Count -ne 1) { - $zipFiles | Format-Table FullName - throw "Expected exactly one Windows zip artifact for this build, found $($zipFiles.Count)." - } - - Copy-Item -Path $zipFiles[0].FullName -Destination (Join-Path $artifactDir "省心推-win-$env:CLIENT_VERSION.zip") -Force - Get-ChildItem $artifactDir | Format-Table Name, Length - - - name: Upload Windows artifacts - uses: actions/upload-artifact@v3 - with: - name: win - path: ${{ runner.temp }}/desktop-client-win + name: desktop-client + path: ${{ runner.temp }}/desktop-client-artifacts if-no-files-found: error retention-days: 14 @@ -506,13 +458,11 @@ jobs: name: Publish Client Artifacts to NAS needs: - resolve - - build-mac - - build-win + - build-client if: >- always() && needs.resolve.result == 'success' && - (needs.build-mac.result == 'success' || needs.build-mac.result == 'skipped') && - (needs.build-win.result == 'success' || needs.build-win.result == 'skipped') + needs.build-client.result == 'success' runs-on: ubuntu-latest timeout-minutes: 30 env: @@ -536,6 +486,7 @@ jobs: - name: Download client artifacts uses: actions/download-artifact@v3 with: + name: desktop-client path: desktop-artifacts - name: Write manifest