From ec10b8de65023d2dbe3dd79bbb2af92dc4424c97 Mon Sep 17 00:00:00 2001 From: Alissa Rao Date: Tue, 19 Dec 2023 15:52:30 -0800 Subject: [PATCH] Github Actions: Split installer into native-image and installer steps. --- .github/workflows/build_dist.yml | 86 ++++++++++++++++++++++------ project/PatchBuild.scala | 7 ++- scripts/ci/build-installer_linux.sh | 24 +------- scripts/ci/build-installer_win32.ps1 | 31 ---------- scripts/ci/build-ni_linux.sh | 40 +++++++++++++ scripts/ci/build-ni_win32.ps1 | 61 ++++++++++++++++++++ scripts/res/installer.nsh | 2 +- 7 files changed, 179 insertions(+), 72 deletions(-) create mode 100755 scripts/ci/build-ni_linux.sh create mode 100644 scripts/ci/build-ni_win32.ps1 diff --git a/.github/workflows/build_dist.yml b/.github/workflows/build_dist.yml index 00999fe..5f4d67d 100644 --- a/.github/workflows/build_dist.yml +++ b/.github/workflows/build_dist.yml @@ -44,19 +44,16 @@ jobs: name: mppatch_ci_natives-linux.tar.gz path: target/mppatch_ci_natives-linux.tar.gz - buildInstallerLinux: + buildNativeImageLinux: runs-on: ubuntu-latest needs: - buildNative steps: - # Install packages + # Initialize - uses: actions/setup-java@v3 with: distribution: 'liberica' java-version: '21' - - run: sudo apt install libfuse2 - - # Initialize git - uses: actions/checkout@v2 with: submodules: 'recursive' @@ -71,35 +68,29 @@ jobs: - run: rm -rf target/mppatch_ci_natives-linux # Do the actual build - - run: scripts/ci/build-installer_linux.sh + - run: scripts/ci/build-ni_linux.sh # Upload artifacts - uses: actions/upload-artifact@v3 with: - name: mppatch_ci_installer-linux - path: target/MPPatch-Installer_* + name: mppatch_ci_ni-linux + path: target/native-image-linux/* - buildInstallerWindows: + buildNativeImageWindows: runs-on: windows-latest needs: - buildNative steps: - # Install packages + # Initialize - uses: actions/setup-java@v3 with: distribution: 'liberica' java-version: '21' - - # Initialize git - uses: actions/checkout@v2 with: submodules: 'recursive' - run: git fetch --prune --unshallow --tags - # Install dependencies - - uses: ilammy/msvc-dev-cmd@v1 - - run: choco install nsis - # Download artifacts - uses: actions/download-artifact@v3 with: @@ -109,6 +100,69 @@ jobs: - run: rm -Recurse -Force -Verbose target/mppatch_ci_natives-linux # Do the actual build + - uses: ilammy/msvc-dev-cmd@v1 + - run: pwsh -file scripts/ci/build-ni_win32.ps1 + + # Upload artifacts + - uses: actions/upload-artifact@v3 + with: + name: mppatch_ci_ni-win32 + path: target/native-image-win32/* + + buildInstallerLinux: + runs-on: ubuntu-latest + needs: + - buildNativeImageLinux + steps: + # Initialize + - uses: actions/setup-java@v3 + with: + distribution: 'liberica' + java-version: '21' + - uses: actions/checkout@v2 + with: + submodules: 'recursive' + - run: git fetch --prune --unshallow --tags + - run: sudo apt install libfuse2 + + # Download artifacts + - uses: actions/download-artifact@v3 + with: + name: mppatch_ci_ni-linux + path: target/native-image-linux + + # Do the actual build + - run: scripts/ci/build-installer_linux.sh + + # Upload artifacts + - uses: actions/upload-artifact@v3 + with: + name: mppatch_ci_installer-linux + path: target/MPPatch-Installer_* + + buildInstallerWindows: + runs-on: windows-latest + needs: + - buildNativeImageWindows + steps: + # Initialize + - uses: actions/setup-java@v3 + with: + distribution: 'liberica' + java-version: '21' + - uses: actions/checkout@v2 + with: + submodules: 'recursive' + - run: git fetch --prune --unshallow --tags + + # Download artifacts + - uses: actions/download-artifact@v3 + with: + name: mppatch_ci_ni-win32 + path: target/native-image-win32 + + # Do the actual build + - run: choco install nsis - run: pwsh -file scripts/ci/build-installer_win32.ps1 # Upload artifacts diff --git a/project/PatchBuild.scala b/project/PatchBuild.scala index 19f93ef..613c596 100644 --- a/project/PatchBuild.scala +++ b/project/PatchBuild.scala @@ -129,8 +129,9 @@ object PatchBuild { } object Keys { - val nativesDir = TaskKey[File]("patch-natives-dir") - val patchFiles = TaskKey[Map[String, Array[Byte]]]("patch-build-files") - val buildDylibDir = TaskKey[File]("build-dylib-dir") + val nativesDir = TaskKey[File]("patch-natives-dir") + val patchFiles = TaskKey[Map[String, Array[Byte]]]("patch-build-files") + val buildDylibDir = TaskKey[File]("build-dylib-dir") + val buildPatchPackage = TaskKey[Unit]("mppatch-build-patch-package") } } diff --git a/scripts/ci/build-installer_linux.sh b/scripts/ci/build-installer_linux.sh index fc072c0..8bd3885 100755 --- a/scripts/ci/build-installer_linux.sh +++ b/scripts/ci/build-installer_linux.sh @@ -24,40 +24,22 @@ . scripts/ci/install-deps.sh -echo "Extracting native tarballs..." -rm -rfv target/native-bin || exit 1 -mkdir -vp target/native-bin || exit 1 -cd target/native-bin || exit 1 - tar -xv -f ../../target/mppatch_ci_natives-linux.tar.gz -cd ../.. || exit 1 - echo "Gathering facts from SBT..." sbt "print scalaVersion" || exit 1 # get project files cached, required to wrangle CI VERSION="$(sbt "print version" --error || exit 1)" VERSION="$(echo "$VERSION" | head -n 1 | tr -d '\n')" -echo "VERSION=$VERSION" APPIMAGE_NAME="MPPatch-Installer_linux_$VERSION.AppImage" -ASSEMBLY_NAME="MPPatch-Installer_universal_$VERSION.jar" - -echo "Building assembly jar..." -ASSEMBLY_JAR="$(sbt "print assembly" --error || exit 1)" -echo "ASSEMBLY_JAR=$ASSEMBLY_JAR" -cp "$(echo "$ASSEMBLY_JAR" | head -n 1 | tr -d '\n')" target/"$ASSEMBLY_NAME" || exit 1 echo "Cleaning up after previous scripts..." -rm -rfv target/native-image target/dist-build || exit 1 -mkdir -p target/native-image target/dist-build || exit 1 - -echo "Building Linux installer...." -sbt nativeImage || exit 1 -chmod +x target/native-image/*.so || exit 1 +rm -rfv target/dist-build || exit 1 +mkdir -p target/dist-build || exit 1 echo "Building AppDir for Linux installer..." mkdir -pv target/dist-build/linux/AppDir || exit 1 # Build basic directory structure cd target/dist-build/linux/AppDir || exit 1 - cp -rv ../../../native-image/* . || exit 1 + cp -rv ../../../native-image-linux/* . || exit 1 mkdir -pv usr/bin usr/lib usr/share/applications usr/share/icons/hicolor/scalable/apps || exit 1 mv -v mppatch-installer usr/bin/ || exit 1 mv -v *.so usr/lib/ || exit 1 diff --git a/scripts/ci/build-installer_win32.ps1 b/scripts/ci/build-installer_win32.ps1 index f8f78ce..fb32bd3 100644 --- a/scripts/ci/build-installer_win32.ps1 +++ b/scripts/ci/build-installer_win32.ps1 @@ -25,43 +25,12 @@ $ErrorActionPreference = "Stop" # Install graalvm scripts/ci/install-deps.ps1 -# Extract native tarballs -echo "Extracting native tarballs..." -if (Test-Path target/native-bin) { - rm -Recurse -Force -Verbose target/native-bin -} -New-Item target/native-bin -ItemType Directory -ea 0 -Verbose -cd target/native-bin - tar -xv -f ../../target/mppatch_ci_natives-linux.tar.gz -cd ../.. - # Find the current version $VERSION = "$( sbt "print version" --error )".Trim() $VERSION = $VERSION.Split(" ")[0].Trim() # fix a weird Github Actions difference $FILE_VERSION = "$VERSION".Split("-")[0] $FILE_VERSION = "$FILE_VERSION.$( git rev-list HEAD --count )" $INSTALLER_NAME = "MPPatch-Installer_win32_$VERSION.exe" -echo "VERSION=$VERSION" -echo "FILE_VERSION=$FILE_VERSION" -echo "INSTALLER_NAME=$INSTALLER_NAME" - -# Build the native-image -echo "Building native-image installer" -if (Test-Path target/native-image) { - rm -Recurse -Force -Verbose target/native-image -} -sbt nativeImage -target/deps/rcedit.exe "target/native-image/mppatch-installer.exe" ` - --set-version-string "FileDescription" "MPPatch Installer - Native Image Installer" ` - --set-file-version "$FILE_VERSION" ` - --set-version-string "ProductName" "MPPatch" ` - --set-product-version "$VERSION" ` - --set-version-string "LegalCopyright" "(C) Lymia Kanokawa; available under the MIT License" ` - --set-version-string "OriginalFilename" "mppatch-installer.exe" ` - --set-version-string "Comments" "This is the internal installer. It should not be downloaded seperately." ` - --set-icon "scripts/res/mppatch-installer.ico" ` - --application-manifest "scripts/res/win32-manifest.xml" -editbin /SUBSYSTEM:WINDOWS "target/native-image/mppatch-installer.exe" # Build NSIS image echo "Building NSIS installer wrapper" diff --git a/scripts/ci/build-ni_linux.sh b/scripts/ci/build-ni_linux.sh new file mode 100755 index 0000000..b4a1d31 --- /dev/null +++ b/scripts/ci/build-ni_linux.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# +# Copyright (c) 2015-2023 Lymia Kanokawa +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + +. scripts/ci/install-deps.sh + +echo "Extracting native tarballs..." +rm -rfv target/native-bin || exit 1 +mkdir -vp target/native-bin || exit 1 +cd target/native-bin || exit 1 + tar -xv -f ../../target/mppatch_ci_natives-linux.tar.gz +cd ../.. || exit 1 + +echo "Cleaning up after previous scripts..." +rm -rfv target/native-image-linux || exit 1 +mkdir -p target/native-image-linux || exit 1 + +echo "Building Linux installer...." +sbt nativeImage || exit 1 +chmod +x target/native-image-linux/*.so || exit 1 diff --git a/scripts/ci/build-ni_win32.ps1 b/scripts/ci/build-ni_win32.ps1 new file mode 100644 index 0000000..9724c46 --- /dev/null +++ b/scripts/ci/build-ni_win32.ps1 @@ -0,0 +1,61 @@ +# +# Copyright (c) 2015-2023 Lymia Kanokawa +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + +$ErrorActionPreference = "Stop" + +# Install graalvm +scripts/ci/install-deps.ps1 + +# Extract native tarballs +echo "Extracting native tarballs..." +if (Test-Path target/native-bin) { + rm -Recurse -Force -Verbose target/native-bin +} +New-Item target/native-bin -ItemType Directory -ea 0 -Verbose +cd target/native-bin + tar -xv -f ../../target/mppatch_ci_natives-linux.tar.gz +cd ../.. + +# Find the current version +$VERSION = "$( sbt "print version" --error )".Trim() +$VERSION = $VERSION.Split(" ")[0].Trim() # fix a weird Github Actions difference +$FILE_VERSION = "$VERSION".Split("-")[0] +$FILE_VERSION = "$FILE_VERSION.$( git rev-list HEAD --count )" +$INSTALLER_NAME = "MPPatch-Installer_win32_$VERSION.exe" + +# Build the native-image +echo "Building native-image installer" +if (Test-Path target/native-image-win32) { + rm -Recurse -Force -Verbose target/native-image-win32 +} +sbt nativeImage +target/deps/rcedit.exe "target/native-image-win32/mppatch-installer.exe" ` + --set-version-string "FileDescription" "MPPatch Installer - Native Image Installer" ` + --set-file-version "$FILE_VERSION" ` + --set-version-string "ProductName" "MPPatch" ` + --set-product-version "$VERSION" ` + --set-version-string "LegalCopyright" "(C) Lymia Kanokawa; available under the MIT License" ` + --set-version-string "OriginalFilename" "mppatch-installer.exe" ` + --set-version-string "Comments" "This is the internal installer. It should not be downloaded seperately." ` + --set-icon "scripts/res/mppatch-installer.ico" ` + --application-manifest "scripts/res/win32-manifest.xml" +editbin /SUBSYSTEM:WINDOWS "target/native-image-win32/mppatch-installer.exe" diff --git a/scripts/res/installer.nsh b/scripts/res/installer.nsh index 19df023..e67c56b 100644 --- a/scripts/res/installer.nsh +++ b/scripts/res/installer.nsh @@ -28,7 +28,7 @@ Section "Extract and execute wrapped installer" RMDir /r $TEMP\MPPatchInstaller SetOutPath $TEMP\MPPatchInstaller - File ..\..\target\native-image\* + File ..\..\target\native-image-win32\* System::Call 'Kernel32::SetEnvironmentVariable(t, t)i ("NSIS_LAUNCH_MARKER", "018c6bba-54e0-7cf2-b16a-7b6abb9215e0").r0' System::Call 'Kernel32::SetEnvironmentVariable(t, t)i ("NSIS_LAUNCH_EXE", "$EXEPATH").r0'