From 123be07e10b191e7db9f91ad22338954d4f2f40d Mon Sep 17 00:00:00 2001 From: pankaj443 Date: Fri, 17 May 2024 15:41:17 +0530 Subject: [PATCH] Add steps to sign win binary --- .../{executable.yml => executable_mac.yml} | 8 +- .github/workflows/executable_win.yml | 35 +++++++++ scripts/{executable.sh => executable_mac.sh} | 4 +- scripts/executable_win.sh | 76 +++++++++++++++++++ 4 files changed, 117 insertions(+), 6 deletions(-) rename .github/workflows/{executable.yml => executable_mac.yml} (88%) create mode 100644 .github/workflows/executable_win.yml rename scripts/{executable.sh => executable_mac.sh} (96%) create mode 100755 scripts/executable_win.sh diff --git a/.github/workflows/executable.yml b/.github/workflows/executable_mac.yml similarity index 88% rename from .github/workflows/executable.yml rename to .github/workflows/executable_mac.yml index 5b0e39e84..834101834 100644 --- a/.github/workflows/executable.yml +++ b/.github/workflows/executable_mac.yml @@ -1,7 +1,8 @@ name: Build Executables on: - release: - types: [published] + push: + pull_request: + workflow_dispatch: jobs: lint: name: Build Executables @@ -12,7 +13,7 @@ jobs: with: node-version: 14 architecture: x64 - - run: ./scripts/executable.sh + - run: ./scripts/executable_mac.sh env: APPLE_DEV_CERT: ${{secrets.APPLE_DEV_CERT}} APPLE_ID_USERNAME: ${{secrets.APPLE_ID_USERNAME}} @@ -25,6 +26,5 @@ jobs: files: | percy-osx.zip percy-linux.zip - percy-win.zip env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/executable_win.yml b/.github/workflows/executable_win.yml new file mode 100644 index 000000000..cca851251 --- /dev/null +++ b/.github/workflows/executable_win.yml @@ -0,0 +1,35 @@ +name: Build Executables +on: + push: + pull_request: + workflow_dispatch: +jobs: + lint: + name: Build Executables + runs-on: windows-latest + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-node@v4 + with: + node-version: 14 + architecture: x64 + - run: ./scripts/executable_win.sh + - name: Sign binary + uses: lando/code-sign-action@v2 + with: + file: path/to/binary + certificate-data: ${{ secrets.WINDOWS_CERT }} + certificate-password: ${{ secrets.WINDOWS_CERT_KEY }} + # env: + # APPLE_DEV_CERT: ${{secrets.APPLE_DEV_CERT}} + # APPLE_ID_USERNAME: ${{secrets.APPLE_ID_USERNAME}} + # APPLE_ID_KEY: ${{secrets.APPLE_ID_KEY}} + # - name: Verify executable + # run: ./percy --version + # - name: Upload assets + # uses: softprops/action-gh-release@d99959edae48b5ffffd7b00da66dcdb0a33a52ee + # with: + # files: | + # percy-win.zip + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/scripts/executable.sh b/scripts/executable_mac.sh similarity index 96% rename from scripts/executable.sh rename to scripts/executable_mac.sh index c4e642539..78b8feddb 100755 --- a/scripts/executable.sh +++ b/scripts/executable_mac.sh @@ -50,7 +50,7 @@ pkg ./packages/cli/bin/run.js -d # Rename executables mv run-linux percy && chmod +x percy mv run-macos percy-osx && chmod +x percy-osx -mv run-win.exe percy.exe && chmod +x percy.exe +# mv run-win.exe percy.exe && chmod +x percy.exe # Sign & Notrize mac app echo "$APPLE_DEV_CERT" | base64 -d > AppleDevIDApp.p12 @@ -69,7 +69,7 @@ codesign --force --verbose=4 -s "Developer ID Application: BrowserStack Inc (76 zip percy-linux.zip percy mv percy-osx percy zip percy-osx.zip percy -zip percy-win.zip percy.exe +# zip percy-win.zip percy.exe xcrun notarytool submit --apple-id "$APPLE_ID_USERNAME" --password $APPLE_ID_KEY --team-id 763K6K6H44 percy-osx.zip --wait diff --git a/scripts/executable_win.sh b/scripts/executable_win.sh new file mode 100755 index 000000000..d7eb62877 --- /dev/null +++ b/scripts/executable_win.sh @@ -0,0 +1,76 @@ +#!/bin/bash +set -e -o pipefail + +function cleanup { + rm -rf build + # rm AppleDevIDApp.p12 + # security delete-keychain percy.keychain +} + +brew install gnu-sed +npm install -g pkg + +yarn install +yarn build + +# Remove type from package.json files +gsed -i '/"type": "module",/{s///;h};${x;/./{x;q0};x;q1}' ./package.json + +# Create array of package.json files +array=($(ls -d ./packages/*/package.json)) + +# Delete package.json filepath where type module is not defined +delete=(./packages/dom/package.json ./packages/sdk-utils/package.json) +for del in ${delete[@]} +do + array=("${array[@]/$del}") +done + +# Remove type module from package.json where present +for package in "${array[@]}" +do + if [ ! -z "$package" ] + then + gsed -i '/"type": "module",/{s///;h};${x;/./{x;q0};x;q1}' $package + fi +done + +echo "import { cli } from '@percy/cli';\ +$(cat ./packages/cli/dist/percy.js)" > ./packages/cli/dist/percy.js + +gsed -i '/Update NODE_ENV for executable/{s//\nprocess.env.NODE_ENV = "executable";/;h};${x;/./{x;q0};x;q1}' ./packages/cli/bin/run.cjs + +# Convert ES6 code to cjs +npm run build_cjs +cp -R ./build/* packages/ + +# Create executables +pkg ./packages/cli/bin/run.js -d + +# # Rename executables +# mv run-linux percy && chmod +x percy +# mv run-macos percy-osx && chmod +x percy-osx +mv run-win.exe percy.exe && chmod +x percy.exe + +# # Sign & Notrize mac app +# echo "$APPLE_DEV_CERT" | base64 -d > AppleDevIDApp.p12 + +# security create-keychain -p percy percy.keychain +# security import AppleDevIDApp.p12 -t agg -k percy.keychain -P ChaiTime -A +# security list-keychains -s ~/Library/Keychains/percy.keychain +# security default-keychain -s ~/Library/Keychains/percy.keychain +# security unlock-keychain -p "percy" ~/Library/Keychains/percy.keychain +# security set-keychain-settings -t 3600 -l ~/Library/Keychains/percy.keychain +# security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k percy ~/Library/Keychains/percy.keychain-db + +# codesign --force --verbose=4 -s "Developer ID Application: BrowserStack Inc (763K6K6H44)" --options runtime --entitlements scripts/files/entitlement.plist --keychain ~/Library/Keychains/percy.keychain percy-osx + +# # Create zip file for uploading as assets +# zip percy-linux.zip percy +# mv percy-osx percy +# zip percy-osx.zip percy +# zip percy-win.zip percy.exe + +# xcrun notarytool submit --apple-id "$APPLE_ID_USERNAME" --password $APPLE_ID_KEY --team-id 763K6K6H44 percy-osx.zip --wait + +cleanup