Skip to content

Commit

Permalink
Update script for win
Browse files Browse the repository at this point in the history
  • Loading branch information
pankaj443 committed May 17, 2024
1 parent 6363eb8 commit ade8d84
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 45 deletions.
25 changes: 11 additions & 14 deletions .github/workflows/executable_win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,15 @@ jobs:
node-version: 14
architecture: x64
- run: ./scripts/executable_win.sh
- name: Sign binary
uses: lando/code-sign-action@v2
env:
WINDOWS_CERT: ${{secrets.WINDOWS_CERT}}
WINDOWS_CERT_KEY: ${{secrets.WINDOWS_CERT_KEY}}
- name: Verify executable
run: ./percy --version
- name: Upload assets
uses: softprops/action-gh-release@d99959edae48b5ffffd7b00da66dcdb0a33a52ee
with:
file: percy.exe
certificate-data: ${{ secrets.WINDOWS_CERT }}
certificate-password: ${{ secrets.WINDOWS_CERT_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 }}
files: |
percy-win.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80 changes: 49 additions & 31 deletions scripts/executable_win.sh
Original file line number Diff line number Diff line change
@@ -1,51 +1,69 @@
#!/bin/bash
set -e -o pipefail
@echo off
setlocal enabledelayedexpansion

function cleanup {
rm -rf build
}
REM Function for cleanup
:cleanup
rmdir /s /q build

brew install gnu-sed
REM Install gnu-sed using Homebrew for Windows
choco install gnu-sed

REM Install pkg globally using npm
npm install -g pkg

REM Install project dependencies using yarn
yarn install

REM Build project using yarn
yarn build

# Remove type from package.json files
REM 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))
REM Create array of package.json files
set "array="
for /f %%a in ('dir /b /s /ad ./packages/*/package.json') do (
set "array=!array! %%a"
)

# 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
REM Delete package.json filepath where type module is not defined
set "delete=./packages/dom/package.json ./packages/sdk-utils/package.json"
for %%d in (%delete%) do (
set "array=!array:%%d=!"
)

# 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
REM Remove type module from package.json where present
for %%p in (%array%) do (
if not "%%p" == "" (
gsed -i '/"type": "module",/{s///;h};${x;/./{x;q0};x;q1}' %%p
)
)

echo "import { cli } from '@percy/cli';\
$(cat ./packages/cli/dist/percy.js)" > ./packages/cli/dist/percy.js
REM Concatenate percy.js content with import statement
echo import { cli } from '@percy/cli'; >> ./packages/cli/dist/percy.js
type ./packages/cli/dist/percy.js >> ./packages/cli/dist/percy.js.tmp
move /y ./packages/cli/dist/percy.js.tmp ./packages/cli/dist/percy.js

REM Update NODE_ENV for executable in run.cjs
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
REM Convert ES6 code to cjs
npm run build_cjs
cp -R ./build/* packages/
xcopy /s /y /q build\* packages\

# Create executables
REM Create executables using pkg
pkg ./packages/cli/bin/run.js -d

# Rename executables
mv run-win.exe percy.exe && chmod +x percy.exe
REM Rename executables
ren run-win.exe percy.exe
icacls percy.exe /grant:r Everyone:F

REM Sign win exe
echo %WINDOWS_CERT% | base64 -d > CodeSigning.p12
signtool.exe sign /fd SHA256 /f CodeSigning.p12 /p "%WINDOWS_CERT_KEY%" percy.exe

REM Create zip file for uploading as assets
powershell Compress-Archive -Path percy.exe -DestinationPath percy-win.zip

cleanup
REM Call cleanup function
call :cleanup

0 comments on commit ade8d84

Please sign in to comment.