Skip to content

Instantly share code, notes, and snippets.

@fourlastor
Last active September 15, 2022 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fourlastor/9087b45c50437ea24da2d233a5280709 to your computer and use it in GitHub Desktop.
Save fourlastor/9087b45c50437ea24da2d233a5280709 to your computer and use it in GitHub Desktop.
Github actions jpackage
#!/bin/sh
SELF=$(readlink -f "$0")
HERE=${SELF%/*}
export PATH="$HERE/bin:$PATH"
export ALSOFT_DRIVERS=pulse # not sure if necessary tbh
exec "yourgame" "$@"
jpackageImage.dependsOn dist
dist.dependsOn classes
eclipse.project.name = appName + "-desktop"
jpackageImage.doFirst {
// Generate temporary properties files for extra launchers
file("$buildDir/yourgame-debug.properties").with { propFile ->
propFile.delete()
propFile.withOutputStream { it << """
|win-console=true
|icon=
""".stripMargin()}
}
file("$buildDir/yourgame-dev.properties").with { propFile ->
propFile.delete()
propFile.withOutputStream { it << """
|win-console=true
|icon=
|arguments=dev
""".stripMargin()}
}
}
def imageDir = "$buildDir/yourgame/jpackage"
runtime {
options = ['--strip-debug',
'--compress', '2',
'--no-header-files',
'--no-man-pages',
'--strip-native-commands']
modules = [
'java.base' ,
'java.desktop',
'java.logging',
'jdk.incubator.foreign',
'jdk.unsupported',
]
distDir = file(buildDir)
jpackage {
jpackageHome = property('com.your.game.jpackage.home')
skipInstaller = true
mainJar = "${appName}.jar"
imageName = "${appName}"
imageOutputDir = file("$imageDir")
imageOptions += ['--add-launcher', "yourgame-debug=$buildDir/yourgame-debug.properties"]
imageOptions += ['--add-launcher', "yourgame-dev=$buildDir/yourgame-dev.properties"]
def currentOs = org.gradle.internal.os.OperatingSystem.current()
if (currentOs.windows) {
imageOptions += ["--icon", rootProject.file("jpackage/in/icons/yourgame.ico")]
} else if (currentOs.linux) {
imageOptions += ["--icon", rootProject.file("jpackage/in/icons/yourgame.png")]
} else if (currentOs.macOsX) {
// TODO icon missing
// imageOptions = ["--icon", rootProject.file("jpackage/in/icons/yourgame.icns")]
}
}
}
def version = property("com.your.game.version") // just a property in gradle.properties
def appDir = "$buildDir/yourgame/appimage"
def appDirName = 'yourgame.AppDir'
def appImageName = 'yourgame-x64'
task prepareAppImageFiles(type: Copy) {
group = "yourgame"
dependsOn jpackageImage
from rootProject.file('appimagetool')
from(file("$imageDir/yourgame/")) {
into "$appDirName"
}
from(rootProject.file('yourgame.AppDir.Template')) {
into "$appDirName"
}
from(rootProject.file("jpackage/in/icons/yourgame.png")) {
into "$appDirName"
}
into rootProject.file("$appDir")
}
task buildAppImage(type: Exec) {
group = "yourgame"
dependsOn prepareAppImageFiles
workingDir "$appDir"
commandLine './appimagetool', '-n', "$appDir/$appDirName", "$appDir/$appImageName"
}
task packageLinux(type: Zip) {
group = "yourgame"
dependsOn buildAppImage
archiveFileName = 'yourgame-linux64.zip'
from rootProject.file('jpackage/in/dist-extras')
from(file("$appDir/$appImageName"))
destinationDirectory = rootProject.file('jpackage/out')
into "yourgame-v$version-linux-64"
}
task packageWindows(type: Zip) {
group = "yourgame"
dependsOn jpackageImage
archiveFileName = 'yourgame-windows64.zip'
from rootProject.file('jpackage/in/dist-extras')
from(file("$imageDir/yourgame/"))
destinationDirectory = rootProject.file('jpackage/out')
into "yourgame-v$version-windows-64"
}
task packageOtherPlatforms(type: Zip) {
group = "yourgame"
dependsOn jpackageImage
archiveFileName = 'yourgame-otherplatforms.zip'
from rootProject.file('jpackage/in/dist-extras')
from rootProject.file('jpackage/in/otherplatforms')
from file("$imageDir/yourgame/app/yourgame.jar")
destinationDirectory = rootProject.file('jpackage/out')
into "yourgame-v$version-otherplatforms"
}
name: Distribution Builds
on:
# Automatically on every tag starting with v
push:
tags:
- v*
# Manual dispatch for testing
workflow_dispatch:
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-20.04, windows-latest ]
include:
- os: ubuntu-20.04
packageAction: 'packageLinux'
copyAction: |
cp jpackage/out/yourgame-linux64.zip jpackage/out/alternative-old-name-for-old-links-linux64.zip
releaseFiles: |
jpackage/out/yourgame-linux64.zip
jpackage/out/alternative-old-name-for-old-links-linux64.zip
- os: windows-latest
packageAction: 'packageWindows packageOtherPlatforms'
copyAction: |
copy jpackage/out/yourgame-windows64.zip jpackage/out/alternative-old-name-for-old-links-windows64.zip
copy jpackage/out/yourgame-otherplatforms.zip jpackage/out/alternative-old-name-for-old-links-otherplatforms.zip
releaseFiles: |
jpackage/out/yourgame-windows64.zip
jpackage/out/alternative-old-name-for-old-links-windows64.zip
jpackage/out/yourgame-otherplatforms.zip
jpackage/out/alternative-old-name-for-old-links-otherplatforms.zip
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
cache: 'gradle'
- name: Cache appimagetool
if: startsWith(matrix.os, 'ubuntu-')
id: cache-appimagetool
uses: actions/cache@v3
with:
path: appimagetool
key: ${{ runner.os }}-appimagetool
- name: Linux setup
if: startsWith(matrix.os, 'ubuntu-') && steps.cache-appimagetool.outputs.cache-hit != 'true'
run: |
wget -O appimagetool https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage
chmod +x appimagetool
- name: Build
uses: gradle/gradle-build-action@v2
with:
arguments: --no-daemon ${{ matrix.packageAction }}
- name: Old named copies
run: ${{ matrix.copyAction }}
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
files: ${{ matrix.releaseFiles }}
- name: Artifact upload
uses: actions/upload-artifact@v3
# Enable to check run output, keep disabled as it takes a lot of space and time
if: false
with:
name: outputs
path: jpackage/out
retention-days: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment