From 0a8d2c01003693406690e3aa4fe539621ecb035f Mon Sep 17 00:00:00 2001 From: Hinton Date: Thu, 7 Nov 2024 10:21:04 +0100 Subject: [PATCH] Switch to using tar command directly --- .github/workflows/build-browser.yml | 8 +- apps/browser/package.json | 20 +-- apps/browser/scripts/dist.ps1 | 156 ------------------------ apps/browser/scripts/package-safari.ps1 | 112 +++++++++++++++++ 4 files changed, 126 insertions(+), 170 deletions(-) delete mode 100755 apps/browser/scripts/dist.ps1 create mode 100755 apps/browser/scripts/package-safari.ps1 diff --git a/.github/workflows/build-browser.yml b/.github/workflows/build-browser.yml index d667971ee33..b45e48fac43 100644 --- a/.github/workflows/build-browser.yml +++ b/.github/workflows/build-browser.yml @@ -170,7 +170,7 @@ jobs: uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 with: name: dist-chrome-MV3-${{ env._BUILD_NUMBER }}.zip - path: browser-source/apps/browser/dist/dist-chrome-mv3.zip + path: browser-source/apps/browser/dist/dist-chrome.zip if-no-files-found: error - name: Build Edge @@ -192,7 +192,7 @@ jobs: uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 with: name: DO-NOT-USE-FOR-PROD-dist-edge-MV3-${{ env._BUILD_NUMBER }}.zip - path: browser-source/apps/browser/dist/dist-edge-mv3.zip + path: browser-source/apps/browser/dist/dist-edge.zip if-no-files-found: error - name: Build Firefox @@ -214,7 +214,7 @@ jobs: uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 with: name: DO-NOT-USE-FOR-PROD-dist-firefox-MV3-${{ env._BUILD_NUMBER }}.zip - path: browser-source/apps/browser/dist/dist-firefox-mv3.zip + path: browser-source/apps/browser/dist/dist-firefox.zip if-no-files-found: error - name: Build Opera @@ -236,7 +236,7 @@ jobs: uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 with: name: DO-NOT-USE-FOR-PROD-dist-opera-MV3-${{ env._BUILD_NUMBER }}.zip - path: browser-source/apps/browser/dist/dist-opera-mv3.zip + path: browser-source/apps/browser/dist/dist-opera.zip if-no-files-found: error build-safari: diff --git a/apps/browser/package.json b/apps/browser/package.json index bae707266eb..5338b7889cd 100644 --- a/apps/browser/package.json +++ b/apps/browser/package.json @@ -9,21 +9,21 @@ "build:opera": "cross-env BROWSER=opera webpack", "build:safari": "cross-env BROWSER=safari webpack", "build:watch": "npm run build:watch:chrome", - "build:watch:chrome": "cross-env BROWSER=chrome MANIFEST_VERSION=3 webpack --watch", - "build:watch:edge": "cross-env BROWSER=edge webpack --watch", - "build:watch:firefox": "cross-env BROWSER=firefox webpack --watch", - "build:watch:opera": "cross-env BROWSER=opera webpack --watch", - "build:watch:safari": "cross-env BROWSER=safari webpack --watch", + "build:watch:chrome": "npm run build:chrome -- --watch", + "build:watch:edge": "npm run build:edge -- --watch", + "build:watch:firefox": "npm run build:firefox -- --watch", + "build:watch:opera": "npm run build:opera -- --watch", + "build:watch:safari": "npm run build:safari -- --watch", "build:prod:chrome": "cross-env NODE_ENV=production NODE_OPTIONS=\"--max-old-space-size=4096\" npm run build:chrome", "build:prod:edge": "cross-env NODE_ENV=production NODE_OPTIONS=\"--max-old-space-size=4096\" npm run build:edge", "build:prod:firefox": "cross-env NODE_ENV=production NODE_OPTIONS=\"--max-old-space-size=4096\" npm run build:firefox", "build:prod:opera": "cross-env NODE_ENV=production NODE_OPTIONS=\"--max-old-space-size=4096\" npm run build:opera", "build:prod:safari": "cross-env NODE_ENV=production NODE_OPTIONS=\"--max-old-space-size=4096\" npm run build:safari", - "dist:chrome": "npm run build:prod:chrome && cross-env MANIFEST_VERSION=3 ./scripts/dist.ps1 chrome", - "dist:edge": "npm run build:prod:edge && ./scripts/dist.ps1 edge", - "dist:firefox": "npm run build:prod:firefox && ./scripts/dist.ps1 firefox", - "dist:opera": "npm run build:prod:opera && ./scripts/dist.ps1 opera", - "dist:safari": "npm run build:prod:safari && ./scripts/dist.ps1 safari", + "dist:chrome": "npm run build:prod:chrome && tar -czf dist/dist-chrome.zip ./build", + "dist:edge": "npm run build:prod:edge && tar -czf dist/dist-edge.zip ./build", + "dist:firefox": "npm run build:prod:firefox && tar -czf dist/dist-firefox.zip ./build", + "dist:opera": "npm run build:prod:opera && tar -czf dist/dist-opera.zip ./build", + "dist:safari": "npm run build:prod:safari && ./scripts/package-safari.ps1", "dist:edge:mv3": "cross-env MANIFEST_VERSION=3 npm run dist:edge", "dist:firefox:mv3": "cross-env MANIFEST_VERSION=3 npm run dist:firefox", "dist:opera:mv3": "cross-env MANIFEST_VERSION=3 npm run dist:opera", diff --git a/apps/browser/scripts/dist.ps1 b/apps/browser/scripts/dist.ps1 deleted file mode 100755 index 20b92fcaff9..00000000000 --- a/apps/browser/scripts/dist.ps1 +++ /dev/null @@ -1,156 +0,0 @@ -#!/usr/bin/env pwsh - -#### -# Performs the last step of the build process, zipping the built files. For Mac, it also builds the safari extension. -#### - -param ( - [Parameter(Mandatory = $false)] - [String] $browser -) - -if (-not $browser) { - $browser = $env:BROWSER - if (-not $browser) { - Write-Error "Missing mandatory Browser environment variable." - exit 1 - } - - if ($browser -notin 'chrome', 'edge', 'firefox', 'opera', 'safari') { - Write-Error "Invalid browser specified. Valid options are: chrome, edge, firefox, opera, safari." - exit 1 - } -} - -$manifestVersion = $env:MANIFEST_VERSION -if (-not $manifestVersion) { - $manifestVersion = 2 -} - -$buildDir = Join-Path $PSScriptRoot "../build" -$distDir = Join-Path $PSScriptRoot "../dist" - -Write-Output $PSScriptRoot - -if (-not (Test-Path $buildDir)) { - Write-Output "No build directory found. Exiting..." - exit -} - -# Create dist directory if it doesn't exist -if (-not (Test-Path $distDir)) { - New-Item -ItemType Directory -Path $distDir -} - -if ($browser -ne 'safari') { - if ($manifestVersion -eq 2) { - $distPath = Join-Path $distDir "dist-$browser.zip" - } - else { - $distPath = Join-Path $distDir "dist-$browser-mv3.zip" - } - - if (Test-Path $distPath) { - Remove-Item $distPath - } - - # Compress build directory - if (Test-Path $buildDir) { - Compress-Archive -Path $buildDir -DestinationPath $distPath - Write-Output "Zipped $buildDir into $distPath" - } -} -else { - $subBuildPaths = @("mas", "masdev", "dmg") - $safariSrc = Join-Path $PSScriptRoot "../src/safari" - $safariDistPath = Join-Path -Path $distDir -ChildPath "Safari" - - if (-not (Test-Path $safariDistPath)) { - New-Item -ItemType Directory -Path $safariDistPath - } - - # Delete old safari dists - Remove-Item -LiteralPath $safariDistPath -Force -Recurse - - - foreach ($subBuildPath in $subBuildPaths) { - $safariBuildPath = Join-Path -Path $safariDistPath -ChildPath $subBuildPath - $builtAppexPath = Join-Path -Path $safariBuildPath -ChildPath "build/Release/safari.appex" - $builtAppexFrameworkPath = Join-Path -Path $safariBuildPath -ChildPath "build/Release/safari.appex/Contents/Frameworks/" - $entitlementsPath = Join-Path -Path $safariSrc -ChildPath "safari/safari.entitlements" - - switch ($subBuildPath) { - "mas" { - $codesignArgs = @( - "--verbose", - "--force", - "--sign", - "3rd Party Mac Developer Application: Bitwarden Inc", - "--entitlements", - $entitlementsPath - ) - } - "masdev" { - $codesignArgs = @( - "--verbose", - "--force", - "--sign", - "E7C9978F6FBCE0553429185C405E61F5380BE8EB", - "--entitlements", - $entitlementsPath - ) - } - "dmg" { - $codesignArgs = @( - "--verbose", - "--force", - "-o", - "runtime", - "--sign", - "Developer ID Application: 8bit Solutions LLC", - "--entitlements", - $entitlementsPath - ) - } - } - - # Copy safari src - Copy-Item -Path $safariSrc -Destination $safariBuildPath -Recurse - - # Copy build - $target = Join-Path -Path $safariBuildPath -ChildPath "safari/app" - Copy-Item -Path $buildDir -Destination $target -Recurse - - # Update versions - $jsonFilePath = Join-Path $buildDir "manifest.json" - $jsonContent = Get-Content -Path $jsonFilePath -Raw - $jsonObject = $jsonContent | ConvertFrom-Json - - $infoFile = Join-Path -Path $safariBuildPath -ChildPath "safari/Info.plist" - (Get-Content $infoFile).Replace('0.0.1', $jsonObject.version).Replace('0.0.2', $jsonObject.version) | Set-Content $infoFile - - $projectFile = Join-Path -Path $safariBuildPath -ChildPath "desktop.xcodeproj/project.pbxproj" - (Get-Content $projectFile).Replace('../../../build', "../safari/app") | Set-Content $projectFile - - # Build using xcode - $xcodeBuildArgs = @( - "-project", - (Join-Path $safariBuildPath "desktop.xcodeproj"), - "-alltargets", - "-configuration", - "Release" - ) - $proc = Start-Process "xcodebuild" -ArgumentList $xcodeBuildArgs -NoNewWindow -PassThru - $proc.WaitForExit() - - # Codesign - $libs = Get-ChildItem -Path $builtAppexFrameworkPath -Filter "*.dylib" - foreach ($lib in $libs) { - $proc = Start-Process "codesign" -ArgumentList ($codesignArgs + $lib.FullName) -NoNewWindow -PassThru - $proc.WaitForExit() - } - - $proc = Start-Process "codesign" -ArgumentList ($codesignArgs + $builtAppexPath) -NoNewWindow -PassThru - $proc.WaitForExit() - } -} diff --git a/apps/browser/scripts/package-safari.ps1 b/apps/browser/scripts/package-safari.ps1 new file mode 100755 index 00000000000..e73c6ea3143 --- /dev/null +++ b/apps/browser/scripts/package-safari.ps1 @@ -0,0 +1,112 @@ +#!/usr/bin/env pwsh + +#### +# Builds the safari appex. +#### + +$buildDir = Join-Path $PSScriptRoot "../build" +$distDir = Join-Path $PSScriptRoot "../dist" + +Write-Output $PSScriptRoot + +if (-not (Test-Path $buildDir)) { + Write-Output "No build directory found. Exiting..." + exit +} + +# Create dist directory if it doesn't exist +if (-not (Test-Path $distDir)) { + New-Item -ItemType Directory -Path $distDir +} + +$subBuildPaths = @("mas", "masdev", "dmg") +$safariSrc = Join-Path $PSScriptRoot "../src/safari" +$safariDistPath = Join-Path -Path $distDir -ChildPath "Safari" + +if (-not (Test-Path $safariDistPath)) { + New-Item -ItemType Directory -Path $safariDistPath +} + +# Delete old safari dists +Remove-Item -LiteralPath $safariDistPath -Force -Recurse + +foreach ($subBuildPath in $subBuildPaths) { + $safariBuildPath = Join-Path -Path $safariDistPath -ChildPath $subBuildPath + $builtAppexPath = Join-Path -Path $safariBuildPath -ChildPath "build/Release/safari.appex" + $builtAppexFrameworkPath = Join-Path -Path $safariBuildPath -ChildPath "build/Release/safari.appex/Contents/Frameworks/" + $entitlementsPath = Join-Path -Path $safariSrc -ChildPath "safari/safari.entitlements" + + switch ($subBuildPath) { + "mas" { + $codesignArgs = @( + "--verbose", + "--force", + "--sign", + "3rd Party Mac Developer Application: Bitwarden Inc", + "--entitlements", + $entitlementsPath + ) + } + "masdev" { + $codesignArgs = @( + "--verbose", + "--force", + "--sign", + "E7C9978F6FBCE0553429185C405E61F5380BE8EB", + "--entitlements", + $entitlementsPath + ) + } + "dmg" { + $codesignArgs = @( + "--verbose", + "--force", + "-o", + "runtime", + "--sign", + "Developer ID Application: 8bit Solutions LLC", + "--entitlements", + $entitlementsPath + ) + } + } + + # Copy safari src + Copy-Item -Path $safariSrc -Destination $safariBuildPath -Recurse + + # Copy build + $target = Join-Path -Path $safariBuildPath -ChildPath "safari/app" + Copy-Item -Path $buildDir -Destination $target -Recurse + + # Update versions + $jsonFilePath = Join-Path $buildDir "manifest.json" + $jsonContent = Get-Content -Path $jsonFilePath -Raw + $jsonObject = $jsonContent | ConvertFrom-Json + + $infoFile = Join-Path -Path $safariBuildPath -ChildPath "safari/Info.plist" + (Get-Content $infoFile).Replace('0.0.1', $jsonObject.version).Replace('0.0.2', $jsonObject.version) | Set-Content $infoFile + + $projectFile = Join-Path -Path $safariBuildPath -ChildPath "desktop.xcodeproj/project.pbxproj" + (Get-Content $projectFile).Replace('../../../build', "../safari/app") | Set-Content $projectFile + + # Build using xcode + $xcodeBuildArgs = @( + "-project", + (Join-Path $safariBuildPath "desktop.xcodeproj"), + "-alltargets", + "-configuration", + "Release" + ) + $proc = Start-Process "xcodebuild" -ArgumentList $xcodeBuildArgs -NoNewWindow -PassThru + $proc.WaitForExit() + + # Codesign + $libs = Get-ChildItem -Path $builtAppexFrameworkPath -Filter "*.dylib" + foreach ($lib in $libs) { + $proc = Start-Process "codesign" -ArgumentList ($codesignArgs + $lib.FullName) -NoNewWindow -PassThru + $proc.WaitForExit() + } + + $proc = Start-Process "codesign" -ArgumentList ($codesignArgs + $builtAppexPath) -NoNewWindow -PassThru + $proc.WaitForExit() +}