feat: Support Windows building (#98) #80
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 and Release | ||
| on: | ||
| push: | ||
| tags: | ||
| - 'v*' | ||
| permissions: | ||
| contents: write | ||
| pull_requests: write | ||
| jobs: | ||
| create-release: | ||
| runs-on: lynx-ubuntu-22.04-medium | ||
| outputs: | ||
| upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
| release_type: ${{ steps.release_type.outputs.RELEASE_TYPE }} | ||
| asset_suffix: ${{ steps.release_type.outputs.ASSET_SUFFIX }} | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - name: Set release type | ||
| id: release_type | ||
| run: | | ||
| if [[ ${{ github.ref }} =~ .*-alpha.* ]]; then | ||
| echo "IS_PRERELEASE=true" >> $GITHUB_OUTPUT | ||
| echo "IS_TEMP_VERSION=false" >> $GITHUB_OUTPUT | ||
| echo "RELEASE_TYPE=Alpha" >> $GITHUB_OUTPUT | ||
| echo "ASSET_SUFFIX=alpha" >> $GITHUB_OUTPUT | ||
| elif [[ ${{ github.ref }} =~ .*-beta.* ]]; then | ||
| echo "IS_PRERELEASE=true" >> $GITHUB_OUTPUT | ||
| echo "IS_TEMP_VERSION=false" >> $GITHUB_OUTPUT | ||
| echo "RELEASE_TYPE=Beta" >> $GITHUB_OUTPUT | ||
| echo "ASSET_SUFFIX=beta" >> $GITHUB_OUTPUT | ||
| elif [[ ${{ github.ref }} =~ .*-temp.* ]]; then | ||
| echo "IS_PRERELEASE=false" >> $GITHUB_OUTPUT | ||
| echo "IS_TEMP_VERSION=true" >> $GITHUB_OUTPUT | ||
| echo "RELEASE_TYPE=Temp" >> $GITHUB_OUTPUT | ||
| echo "ASSET_SUFFIX=temp" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "IS_PRERELEASE=false" >> $GITHUB_OUTPUT | ||
| echo "IS_TEMP_VERSION=false" >> $GITHUB_OUTPUT | ||
| echo "RELEASE_TYPE=Release" >> $GITHUB_OUTPUT | ||
| echo "ASSET_SUFFIX=release" >> $GITHUB_OUTPUT | ||
| fi | ||
| - name: Create Release | ||
| id: create_release | ||
| uses: actions/create-release@v1 | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| with: | ||
| tag_name: ${{ github.ref }} | ||
| release_name: ${{ steps.release_type.outputs.RELEASE_TYPE }} ${{ github.ref }} | ||
| draft: false | ||
| prerelease: ${{ steps.release_type.outputs.IS_PRERELEASE }} | ||
| body: | | ||
| ${{ steps.release_type.outputs.IS_PRERELEASE == 'true' && '🚧 This is a pre-release version that may contain unstable features. | ||
| ### Release Notes | ||
| - This is a pre-release version for testing purposes only | ||
| - Not recommended for production use' || steps.release_type.outputs.IS_TEMP_VERSION == 'true' && '⚠️ This is a temporary test version. | ||
| ### Important Notice | ||
| - This version is for testing purposes only | ||
| - Only used for DevTool developers to verify branch code | ||
| - May contain unstable or incomplete features' || github.ref }} | ||
| build-and-upload-macos: | ||
| needs: create-release | ||
| runs-on: lynx-darwin-14-medium | ||
| strategy: | ||
| matrix: | ||
| arch: [arm64, x64] | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| with: | ||
| submodules: recursive | ||
| - name: ln Python | ||
| run: ln -s `which python3` /usr/local/bin/python | ||
| # Node and pnpm setup steps | ||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: 18.20.2 | ||
| - name: Install pnpm | ||
| uses: pnpm/action-setup@v2 | ||
| with: | ||
| version: 7.33.6 | ||
| - name: Get pnpm store directory | ||
| shell: bash | ||
| run: | | ||
| echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV | ||
| - name: Setup pnpm cache | ||
| uses: actions/cache@v3 | ||
| with: | ||
| path: ${{ env.STORE_PATH }} | ||
| key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-pnpm-store- | ||
| - name: Install dependencies | ||
| run: pnpm install | ||
| - name: Fetch depot_tools | ||
| run: pnpm run fetch:depot_tools | ||
| - name: Sync devtools-gn | ||
| run: | | ||
| export PATH=$(pwd)/packages/devtools-frontend-lynx/buildtools/depot_tools:$PATH | ||
| pnpm run sync:devtools-gn | ||
| - name: Build devtools-gn | ||
| run: pnpm run build:devtools | ||
| - name: Sync devtools-dist | ||
| run: pnpm run sync:devtools-dist | ||
| - name: Build lynx-trace | ||
| run: pnpm run build:lynx-trace | ||
| - name: Build all packages | ||
| run: pnpm run build:all | ||
| # Only upload frontend once (in arm64 job) | ||
| - name: Find and Upload Frontend | ||
| if: matrix.arch == 'arm64' | ||
| run: | | ||
| ARCHIVE_PATH=$(find ./packages/devtools-frontend-lynx/output -name "devtool.frontend.lynx_1.0.*.tar.gz" | head -n 1) | ||
| if [ -z "$ARCHIVE_PATH" ]; then | ||
| echo "Error: Frontend archive not found" | ||
| exit 1 | ||
| fi | ||
| echo "Found archive at: ${ARCHIVE_PATH}" | ||
| curl \ | ||
| -X POST \ | ||
| -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
| -H "Content-Type: application/gzip" \ | ||
| --data-binary @"${ARCHIVE_PATH}" \ | ||
| "${{ needs.create-release.outputs.upload_url }}?name=devtool.frontend.lynx-${{ needs.create-release.outputs.asset_suffix }}.tar.gz" | ||
| - name: Install Apple Certificate | ||
| if: matrix.arch == 'arm64' || matrix.arch == 'x64' | ||
| env: | ||
| BUILD_CERTIFICATE_BASE64: ${{ secrets.MACOS_CERTIFICATE }} | ||
| P12_PASSWORD: ${{ secrets.MACOS_CERTIFICATE_PWD }} | ||
| KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }} | ||
| run: | | ||
| security create-keychain -p "$KEYCHAIN_PASSWORD" build.keychain | ||
| security default-keychain -s build.keychain | ||
| security unlock-keychain -p "$KEYCHAIN_PASSWORD" build.keychain | ||
| echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode > certificate.p12 | ||
| security import certificate.p12 -k build.keychain -P "$P12_PASSWORD" -T /usr/bin/codesign | ||
| security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PASSWORD" build.keychain | ||
| rm certificate.p12 | ||
| # Build and upload platform-specific DMG | ||
| - name: Build ${{ matrix.arch }} version | ||
| env: | ||
| APPLE_ID: ${{ secrets.APPLE_ID }} | ||
| APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }} | ||
| APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }} | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| CSC_IDENTITY_AUTO_DISCOVERY: true | ||
| CSC_LINK: ${{ secrets.MACOS_CERTIFICATE }} | ||
| CSC_KEY_PASSWORD: ${{ secrets.MACOS_CERTIFICATE_PWD }} | ||
| run: pnpm run production:mac-${{ matrix.arch }} | ||
| - name: Find DMG Path | ||
| id: find_dmg | ||
| run: | | ||
| DMG_PATH=$(find ./dist -name "*.dmg" | head -n 1) | ||
| if [ -z "$DMG_PATH" ]; then | ||
| echo "Error: DMG file not found" | ||
| exit 1 | ||
| fi | ||
| DMG_FILENAME=$(basename "$DMG_PATH") | ||
| echo "Found DMG at: ${DMG_PATH}" | ||
| echo "dmg_path=${DMG_PATH}" >> $GITHUB_OUTPUT | ||
| echo "dmg_filename=${DMG_FILENAME}" >> $GITHUB_OUTPUT | ||
| - name: Upload ${{ matrix.arch }} DMG | ||
| uses: actions/upload-release-asset@v1 | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| with: | ||
| upload_url: ${{ needs.create-release.outputs.upload_url }} | ||
| asset_path: ${{ steps.find_dmg.outputs.dmg_path }} | ||
| asset_name: ${{ steps.find_dmg.outputs.dmg_filename }} | ||
| asset_content_type: application/x-apple-diskimage | ||
| build-and-upload-windows: | ||
| needs: create-release | ||
| runs-on: lynx-windows-2022-large | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| with: | ||
| submodules: recursive | ||
| # Node and pnpm setup steps | ||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: 18.20.2 | ||
| - name: Install pnpm | ||
| uses: pnpm/action-setup@v2 | ||
| with: | ||
| version: 7.33.6 | ||
| - name: Get pnpm store directory | ||
| shell: pwsh | ||
| run: | | ||
| echo "STORE_PATH=$(pnpm store path --silent)" >> $env:GITHUB_ENV | ||
| - name: Setup pnpm cache | ||
| uses: actions/cache@v3 | ||
| with: | ||
| path: ${{ env.STORE_PATH }} | ||
| key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-pnpm-store- | ||
| - name: Install dependencies | ||
| run: pnpm install | ||
| - name: Fetch depot_tools | ||
| run: pnpm run fetch:depot_tools | ||
| - name: Sync devtools-gn | ||
| shell: pwsh | ||
| run: | | ||
| $env:PATH = "$(Get-Location)\packages\devtools-frontend-lynx\buildtools\depot_tools;$env:PATH" | ||
| pnpm run sync:devtools-gn | ||
| - name: Build devtools-gn | ||
| run: pnpm run build:devtools | ||
| - name: Sync devtools-dist | ||
| run: pnpm run sync:devtools-dist | ||
| - name: Skip lynx-trace build on Windows | ||
| run: pnpm run build:lynx-trace | ||
| - name: Download lynx-trace prebuilt artifact | ||
| uses: robinraju/release-downloader@v1 | ||
| with: | ||
| repository: KananSu/lynx-trace | ||
| latest: true | ||
| fileName: "perfetto-ui-release-*.tar.gz" | ||
| out-file-path: temp-lynx-trace | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Copy lynx-trace to resources | ||
| shell: pwsh | ||
| run: | | ||
| Write-Host "Copying prebuilt lynx-trace artifact..." -ForegroundColor Cyan | ||
| $sourceFile = Get-ChildItem -Path "temp-lynx-trace" -Filter "perfetto-ui-release-*.tar.gz" | Select-Object -First 1 | ||
| $destPath = "packages\lynx-devtool-cli\resources\lynx-trace.tar.gz" | ||
| if ($sourceFile) { | ||
| Copy-Item $sourceFile.FullName $destPath -Force | ||
| Write-Host "✓ lynx-trace artifact copied: $($sourceFile.Name) -> lynx-trace.tar.gz" -ForegroundColor Green | ||
| } else { | ||
| Write-Warning "lynx-trace artifact not found, trace feature will be unavailable" | ||
| Get-ChildItem -Path "temp-lynx-trace" -ErrorAction SilentlyContinue | ||
| } | ||
| - name: Build all packages | ||
| run: pnpm run build:all | ||
| # Upload frontend (only once) | ||
| - name: Find and Upload Frontend | ||
| shell: pwsh | ||
| run: | | ||
| $archivePath = Get-ChildItem -Path ".\packages\devtools-frontend-lynx\output" -Filter "devtool.frontend.lynx_1.0.*.tar.gz" | Select-Object -First 1 -ExpandProperty FullName | ||
| if (-not $archivePath) { | ||
| Write-Error "Error: Frontend archive not found" | ||
| exit 1 | ||
| } | ||
| Write-Host "Found archive at: $archivePath" | ||
| curl.exe ` | ||
| -X POST ` | ||
| -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" ` | ||
| -H "Content-Type: application/gzip" ` | ||
| --data-binary "@$archivePath" ` | ||
| "${{ needs.create-release.outputs.upload_url }}?name=devtool.frontend.lynx-${{ needs.create-release.outputs.asset_suffix }}.tar.gz" | ||
| # Build Windows green package (ZIP - no installer) | ||
| - name: Build Windows version | ||
| shell: pwsh | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| Write-Host "Starting Windows build..." -ForegroundColor Cyan | ||
| powershell -ExecutionPolicy Bypass -File scripts\build-win.ps1 | ||
| - name: Find Windows ZIP file | ||
| id: find_zip | ||
| shell: pwsh | ||
| run: | | ||
| $zip = Get-ChildItem -Path ".\dist" -Filter "Lynx-DevTool-*-x64.zip" | Select-Object -First 1 | ||
| if ($zip) { | ||
| Write-Host "Found ZIP package: $($zip.Name)" -ForegroundColor Green | ||
| Write-Host "Size: $([math]::Round($zip.Length/1MB, 2)) MB" -ForegroundColor Green | ||
| echo "zip_path=$($zip.FullName)" >> $env:GITHUB_OUTPUT | ||
| echo "zip_filename=$($zip.Name)" >> $env:GITHUB_OUTPUT | ||
| } else { | ||
| Write-Error "No ZIP file found in dist directory" | ||
| Get-ChildItem -Path ".\dist" | Format-Table Name | ||
| exit 1 | ||
| } | ||
| - name: Upload Windows ZIP Package | ||
| uses: actions/upload-release-asset@v1 | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| with: | ||
| upload_url: ${{ needs.create-release.outputs.upload_url }} | ||
| asset_path: ${{ steps.find_zip.outputs.zip_path }} | ||
| asset_name: ${{ steps.find_zip.outputs.zip_filename }} | ||
| asset_content_type: application/zip | ||