Skip to content

Commit

Permalink
Github Actions: Split installer into native-image and installer steps.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lymia committed Dec 20, 2023
1 parent b994516 commit ec10b8d
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 72 deletions.
86 changes: 70 additions & 16 deletions .github/workflows/build_dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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:
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions project/PatchBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
24 changes: 3 additions & 21 deletions scripts/ci/build-installer_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 0 additions & 31 deletions scripts/ci/build-installer_win32.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
40 changes: 40 additions & 0 deletions scripts/ci/build-ni_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

#
# Copyright (c) 2015-2023 Lymia Kanokawa <[email protected]>
#
# 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
61 changes: 61 additions & 0 deletions scripts/ci/build-ni_win32.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#
# Copyright (c) 2015-2023 Lymia Kanokawa <[email protected]>
#
# 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"
2 changes: 1 addition & 1 deletion scripts/res/installer.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit ec10b8d

Please sign in to comment.