Skip to content

Commit

Permalink
Release maker bug fix & script update (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
yjf2002ghty authored Mar 23, 2024
1 parent 42412ce commit 8f255fb
Show file tree
Hide file tree
Showing 13 changed files with 450 additions and 84 deletions.
29 changes: 3 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: CI
on: [push, pull_request]
on: [push, pull_request, workflow_dispatch]
jobs:
lint:
runs-on: ubuntu-20.04
Expand All @@ -11,28 +11,5 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: git clone https://github.com/daeken/ldid.git
- run: cd ldid && ./make.sh
- run: rm -rf ./release_make/release-builds
- run: mkdir -p ./release_make/release-builds/win/x64
- run: mkdir -p ./release_make/release-builds/linux/x64
- run: mkdir -p ./release_make/release-builds/macos/x64
- run: mkdir -p ./release_make/release-builds/win/arm64
- run: mkdir -p ./release_make/release-builds/linux/arm64
- run: mkdir -p ./release_make/release-builds/macos/arm64
- run: npm install pkg
- run: npm install [email protected]
- run: if [[ "$(npx pkg ./release_make --target win-x64 --output ./release-builds/win/x64/FairyGround.exe | grep 'Failed to make bytecode')" == "" ]]; then echo "Pass."; else echo "Fail: Bytecode generation failed. Trying --no-bytecode..." & npx pkg ./release_make --no-bytecode --public --public-packages --target win-x64 --output ./release-builds/win/x64/FairyGround.exe; fi
- run: if [[ "$(npx pkg ./release_make --target linux-x64 --output ./release-builds/linux/x64/FairyGround | grep 'Failed to make bytecode')" == "" ]]; then echo "Pass."; else echo "Fail: Bytecode generation failed. Trying --no-bytecode..." & npx pkg ./release_make --no-bytecode --public --public-packages --target linux-x64 --output ./release-builds/linux/x64/FairyGround; fi
- run: if [[ "$(npx pkg ./release_make --target win-arm64 --output ./release-builds/win/arm64/FairyGround.exe | grep 'Failed to make bytecode')" == "" ]]; then echo "Pass."; else echo "Fail: Bytecode generation failed. Trying --no-bytecode..." & npx pkg ./release_make --no-bytecode --public --public-packages --target win-arm64 --output ./release-builds/win/arm64/FairyGround.exe; fi
- run: if [[ "$(npx pkg ./release_make --target linux-arm64 --output ./release-builds/linux/arm64/FairyGround | grep 'Failed to make bytecode')" == "" ]]; then echo "Pass."; else echo "Fail: Bytecode generation failed. Trying --no-bytecode..." & npx pkg ./release_make --no-bytecode --public --public-packages --target linux-arm64 --output ./release-builds/linux/arm64/FairyGround; fi
- run: export PATH="$PATH:$(pwd)/ldid" && if [[ "$(npx pkg ./release_make --target macos-x64 --output ./release-builds/macos/x64/FairyGround.app | grep 'Failed to make bytecode')" == "" ]]; then echo "Pass."; else echo "Fail: Bytecode generation failed. Trying --no-bytecode..." & npx pkg ./release_make --no-bytecode --public --public-packages --target macos-x64 --output ./release-builds/macos/x64/FairyGround.app; fi
- run: export PATH="$PATH:$(pwd)/ldid" && if [[ "$(npx pkg ./release_make --target macos-arm64 --output ./release-builds/macos/arm64/FairyGround.app | grep 'Failed to make bytecode')" == "" ]]; then echo "Pass."; else echo "Fail: Bytecode generation failed. Trying --no-bytecode..." & npx pkg ./release_make --no-bytecode --public --public-packages --target macos-arm64 --output ./release-builds/macos/arm64/FairyGround.app; fi
- run: npm install
- run: npm run build
- run: cp -r ./public ./release_make/release-builds/win/x64/
- run: cp -r ./public ./release_make/release-builds/win/arm64/
- run: cp -r ./public ./release_make/release-builds/linux/x64/
- run: cp -r ./public ./release_make/release-builds/linux/arm64/
- run: cp -r ./public ./release_make/release-builds/macos/x64/
- run: cp -r ./public ./release_make/release-builds/macos/arm64/
- run: chmod 744 ./release_make/CI.sh
- run: ./release_make/CI.sh
105 changes: 105 additions & 0 deletions release_make/CI.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/bash

echo "[Warning] This script is intended to be run in Github Actions for continuous integration purposes."
echo "[Warning] If this is your own platform instead of Github Actions platform, use \"./make.sh\"."

function Error() {
echo "[Error] CI build test failed."
exit 1
}

export nodeversion="node18"

cd ./release_make

chmod -R 744 $(pwd)/ldid

if [ "$(lscpu | grep 'x86_64')" != "" ]; then
export PATH="$PATH:$(pwd)/ldid/linux/x64"
elif [ "$(lscpu | grep 'ARM64')" != "" ]; then
export PATH="$PATH:$(pwd)/ldid/linux/arm64"
else
echo Unknown CPU architecture:
lscpu | grep 'Architecture:'
Error
fi

rm -rf ./release-builds
mkdir -p ./release-builds/win/x64
mkdir -p ./release-builds/linux/x64
mkdir -p ./release-builds/win/arm64
mkdir -p ./release-builds/linux/arm64
mkdir -p ./release-builds/macos/x64
mkdir -p ./release-builds/macos/arm64

npm install || Error
npm install pkg || Error

function TryNoByteCode() {
npx pkg . --no-bytecode --public --public-packages --target $1 --output $2 >/tmp/make_fairyground.log 2>&1
if [ "$(grep 'Error' /tmp/make_fairyground.log)" != "" ]; then
echo "[Error] CI failed. Check the log below to see what\'s going on. File: /tmp/make_fairyground.log"
cat /tmp/make_fairyground.log
return 11
fi
if [ "$(grep 'Warning' /tmp/make_fairyground.log)" != "" ]; then
cat /tmp/make_fairyground.log
fi
return 0
}

function Make() {
npx pkg . --target $1 --output $2 >/tmp/make_fairyground.log 2>&1
if [ "$(grep 'Error' /tmp/make_fairyground.log)" != "" ]; then
echo "[Warning] Fail: Bytecode generation failed. Trying --no-bytecode..."
TryNoByteCode $1 $2
if [ $? -eq 11 ]; then
return 11
fi
echo "[Info] Pass: $1"
return 0
fi
if [ "$(grep 'Failed to make bytecode' /tmp/make_fairyground.log)" != "" ]; then
echo "[Warning] Fail: Bytecode generation failed. Trying --no-bytecode..."
TryNoByteCode $1 $2
if [ $? -eq 11 ]; then
return 11
fi
echo "[Info] Pass: $1"
return 0
fi
if [ "$(grep 'Warning' /tmp/make_fairyground.log)" != "" ]; then
cat /tmp/make_fairyground.log
fi
echo "[Info] Pass: $1"
return 0
}


Make "$nodeversion"-win-x64 ./release-builds/win/x64/FairyGround.exe
if [ $? -eq 11 ]; then Error; fi
Make "$nodeversion"-linux-x64 ./release-builds/linux/x64/FairyGround
if [ $? -eq 11 ]; then Error; fi
Make "$nodeversion"-win-arm64 ./release-builds/win/arm64/FairyGround.exe
if [ $? -eq 11 ]; then Error; fi
Make "$nodeversion"-linux-arm64 ./release-builds/linux/arm64/FairyGround
if [ $? -eq 11 ]; then Error; fi
Make "$nodeversion"-macos-x64 ./release-builds/macos/x64/FairyGround.app
if [ $? -eq 11 ]; then Error; fi
Make "$nodeversion"-macos-arm64 ./release-builds/macos/arm64/FairyGround.app
if [ $? -eq 11 ]; then Error; fi

cd ..
npm install || Error
npm run build || Error
cp -r ./public ./release_make/release-builds/win/x64/
cp -r ./public ./release_make/release-builds/linux/x64/
cp -r ./public ./release_make/release-builds/win/arm64/
cp -r ./public ./release_make/release-builds/linux/arm64/
cp -r ./public ./release_make/release-builds/macos/x64/
cp -r ./public ./release_make/release-builds/macos/arm64/
echo "[Warning] The macOS executables are not suitably signed yet. If you want them to work, you need to be an Apple Developer and sign it with your signing certificate."
echo "[Warning] Use codesign on macOS to sign your executable. If you don't have a Mac, you can use a virtual machine."
echo "[Warning] If you want to build a macOS virtual machine, please visit https://www.sysnettechsolutions.com/en/install-macos-vmware/"
echo "[Info] CI build test OK."
exit 0
29 changes: 23 additions & 6 deletions release_make/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,44 @@ Running make scripts here will apply the changes you have made in fairyground at

## Usage

First install dependencies in the parent directory.
Make sure that you have read & execute permission of this directory and its sub directories.

Install dependencies in this directory (Make sure that the working directory is this directory!)
First install dependencies in the parent directory (The root directory of fairyground). If you have done this before, you can skip this step.

```bash
#In the parent directory
npm install
```

Run make script (Make sure that the working directory is this directory!)
Install dependencies in this directory (Make sure that the working directory is this directory, same as the directory where this document is placed.). If you have done this before, you can skip this step.

```bash
#In this directory
npm install
```

Run make script (Make sure that the working directory is this directory, same as the directory where this document is placed.)

```batch
::Windows
::If your build platform is Windows
make.bat
```
```bash
#Linux
#If your build platform is Linux
./make.sh
```
```zsh
#If your build platform is macOS
./make_macos.sh
```

If no errors occurred, you should see the make results at .\release-builds, containing both linux and windows version. You can see the binary files in "win" and "linux" directory.
If no errors occurred, you should see the make results at .\release-builds, containing linux, windows and macOS versions. You can see the binary files in "win", "macos" and "linux" directory.

You can execute these binary executables to check if it's working correctly.

Note that macOS executables may be killed on launch due to signature problems. If this occurs, you will need to use codesign or ldid utility to sign the executable.

If you want to run macOS in a virtual machine, you can visit [https://www.sysnettechsolutions.com/en/install-macos-vmware/](https://www.sysnettechsolutions.com/en/install-macos-vmware/) for guidance.

Then you can put the "release-builds" directory into an archive (TAR.GZ, ZIP or others) and publish this release.

2 changes: 1 addition & 1 deletion release_make/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function openDefaultBrowser(url) {
exec('start ' + url);
break;
default:
exec('xdg-open', [url]);
exec('xdg-open ' + url);
}
}

Expand Down
Binary file added release_make/ldid/iphoneos/arm64/ldid
Binary file not shown.
Binary file added release_make/ldid/linux/arm64/ldid
Binary file not shown.
Binary file added release_make/ldid/linux/x64/ldid
Binary file not shown.
Binary file added release_make/ldid/macos/arm64/ldid
Binary file not shown.
Binary file added release_make/ldid/macos/x64/ldid
Binary file not shown.
Binary file added release_make/ldid/win/x64/ldid.exe
Binary file not shown.
127 changes: 102 additions & 25 deletions release_make/make.bat
Original file line number Diff line number Diff line change
@@ -1,39 +1,116 @@
@echo off
SETLOCAL ENABLEEXTENSIONS
set nodeversion=node18
cd /d "%~dp0"
rd /s /q .\release-builds
md .\release-builds || goto error
md .\release-builds\win || goto error
md .\release-builds\linux || goto error
md .\release-builds\macos || goto error
md .\release-builds\win\x64 || goto error
md .\release-builds\linux\x64 || goto error
md .\release-builds\win\arm64 || goto error
md .\release-builds\linux\arm64 || goto error
md .\release-builds\macos\x64 || goto error
md .\release-builds\macos\arm64 || goto error
md .\release-builds || goto Error
md .\release-builds\win || goto Error
md .\release-builds\linux || goto Error
md .\release-builds\macos || goto Error
md .\release-builds\win\x64 || goto Error
md .\release-builds\linux\x64 || goto Error
md .\release-builds\win\arm64 || goto Error
md .\release-builds\linux\arm64 || goto Error
md .\release-builds\macos\x64 || goto Error
md .\release-builds\macos\arm64 || goto Error

echo What is the CPU architecture of your build platform (This computer)? (Enter x86_64 or ARM64)
set /P input=^>
if "%input%"=="ARM64" (
set arch=arm64
) else if "%input%"=="x86_64" (
set arch=x64
) else (
echo Bad input. Build failed.
pause
exit /b 1
)

set PATH=%PATH%;%~dp0ldid\win\%arch%

::Platforms include x86, x64, arm, arm64
(start /wait "" npm install -g pkg ^& exit) || goto error
(start /wait "" pkg . --target win-x64 --output .\release-builds\win\x64\FairyGround.exe ^& exit) || goto error
(start /wait "" pkg . --target linux-x64 --output .\release-builds\linux\x64\FairyGround ^& exit) || goto error
(start /wait "" pkg . --target win-arm64 --output .\release-builds\win\arm64\FairyGround.exe ^& exit) || goto error
(start /wait "" pkg . --target linux-arm64 --output .\release-builds\linux\arm64\FairyGround ^& exit) || goto error
(start /wait "" pkg . --target macos-x64 --output .\release-builds\macos\x64\FairyGround ^& exit) || goto error
(start /wait "" pkg . --target macos-arm64 --output .\release-builds\macos\arm64\FairyGround ^& exit) || goto error
set result=
start /wait "" cmd.exe /C npm install pkg ^> %TEMP%\make_fairyground.log ^& exit
FOR /F "usebackq" %%i IN (`findstr /L /I "Error" "%TEMP%\make_fairyground.log"`) DO set result=%%i
if not "%result%"=="" (goto Error)

call :Make %nodeversion%-win-x64 .\release-builds\win\x64\FairyGround.exe
if "%errorlevel%"=="11" (goto Error)
call :Make %nodeversion%-linux-x64 .\release-builds\linux\x64\FairyGround
if "%errorlevel%"=="11" (goto Error)
call :Make %nodeversion%-win-arm64 .\release-builds\win\arm64\FairyGround.exe
if "%errorlevel%"=="11" (goto Error)
call :Make %nodeversion%-linux-arm64 .\release-builds\linux\arm64\FairyGround
if "%errorlevel%"=="11" (goto Error)
call :Make %nodeversion%-macos-x64 .\release-builds\macos\x64\FairyGround.app
if "%errorlevel%"=="11" (goto Error)
call :Make %nodeversion%-macos-arm64 .\release-builds\macos\arm64\FairyGround.app
if "%errorlevel%"=="11" (goto Error)

cd ..
(start /wait "" npm run buildwithcmd ^& exit) || goto error
xcopy .\public .\release_make\release-builds\win\x64\public /E /H /C /I /Q || goto error
xcopy .\public .\release_make\release-builds\linux\x64\public /E /H /C /I /Q || goto error
xcopy .\public .\release_make\release-builds\win\arm64\public /E /H /C /I /Q || goto error
xcopy .\public .\release_make\release-builds\linux\arm64\public /E /H /C /I /Q || goto error
xcopy .\public .\release_make\release-builds\macos\x64\public /E /H /C /I /Q || goto error
xcopy .\public .\release_make\release-builds\macos\arm64\public /E /H /C /I /Q || goto error
set result=
start /wait "" cmd.exe /C npm run buildwithcmd ^> %TEMP%\make_fairyground.log ^& exit
FOR /F "usebackq" %%i IN (`findstr /L /I "Error" "%TEMP%\make_fairyground.log"`) DO set result=%%i
if not "%result%"=="" (goto Error)

xcopy .\public .\release_make\release-builds\win\x64\public /E /H /C /I /Q || goto Error
xcopy .\public .\release_make\release-builds\linux\x64\public /E /H /C /I /Q || goto Error
xcopy .\public .\release_make\release-builds\win\arm64\public /E /H /C /I /Q || goto Error
xcopy .\public .\release_make\release-builds\linux\arm64\public /E /H /C /I /Q || goto Error
xcopy .\public .\release_make\release-builds\macos\x64\public /E /H /C /I /Q || goto Error
xcopy .\public .\release_make\release-builds\macos\arm64\public /E /H /C /I /Q || goto Error
echo Release build finished. Check "%~dp0release-builds\" to see the results.
echo [Warning] The macOS executables are not suitably signed yet. If you want them to work, you need to be an Apple Developer and sign it with your signing certificate.
echo [Warning] Use codesign on macOS to sign your executable. If you don't have a Mac, you can use a virtual machine.
echo [Warning] If you want to build a macOS virtual machine, please visit https://www.sysnettechsolutions.com/en/install-macos-vmware/
pause
exit /b 0

:error
:Error
echo Release build failed.
pause
exit /b 1

:Make
start /WAIT /MIN "" cmd.exe /C ^(npx pkg . --target %~1 --output %2 ^& exit ^) ^> %TEMP%\make_fairyground.log 2^>^&1
set result=
FOR /F "usebackq" %%i IN (`findstr /L /I "Error" "%TEMP%\make_fairyground.log"`) DO set result=%%i
if not "%result%"=="" (
echo Fail: Bytecode generation failed. Trying --no-bytecode...
call :TryNoByteCode %~1 %2
if "%errorlevel%"=="11" (exit /b 11)
echo Pass: %~1
exit /b 0
)
set result=
FOR /F "usebackq" %%i IN (`findstr /L /I "Failed to make bytecode" "%TEMP%\make_fairyground.log"`) DO set result=%%i
if not "%result%"=="" (
echo Fail: Bytecode generation failed. Trying --no-bytecode...
call :TryNoByteCode %~1 %2
if "%errorlevel%"=="11" (exit /b 11)
echo Pass: %~1
exit /b 0
)
set result=
FOR /F "usebackq" %%i IN (`findstr /L /I "Warning" "%TEMP%\make_fairyground.log"`) DO set result=%%i
if not "%result%"=="" (
type "%TEMP%\make_fairyground.log"
)
echo Pass: %~1
exit /b 0

:TryNoByteCode
start /WAIT /MIN "" cmd.exe /C ^(npx pkg . --no-bytecode --public --public-packages --target %~1 --output %2 ^& exit ^) ^> %TEMP%\make_fairyground.log 2^>^&1
set result=
FOR /F "usebackq" %%i IN (`findstr /L /I "Error" "%TEMP%\make_fairyground.log"`) DO set result=%%i
if not "%result%"=="" (
echo Error: Build failed. Check the log below to see what's going on. File: %TEMP%\make_fairyground.log
type "%TEMP%\make_fairyground.log"
exit /b 11
)
set result=
FOR /F "usebackq" %%i IN (`findstr /L /I "Warning" "%TEMP%\make_fairyground.log"`) DO set result=%%i
if not "%result%"=="" (
type "%TEMP%\make_fairyground.log"
)
exit /b 0
Loading

0 comments on commit 8f255fb

Please sign in to comment.