Skip to content

Commit

Permalink
feat: Add native image plugin for native builds
Browse files Browse the repository at this point in the history
fix: Incorrectly reading HTTP last edited header
fix: Configs throwing an error if trying to delete untracked files in folders that dont exist
  • Loading branch information
0ffz committed Nov 16, 2024
1 parent 619cede commit e0674bb
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 17 deletions.
19 changes: 13 additions & 6 deletions .github/workflows/publish-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,28 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up JDK
uses: actions/setup-java@v3
- uses: graalvm/setup-graalvm@v1
with:
distribution: temurin
java-version: 17
java-version: '23'
distribution: 'graalvm'
github-token: ${{ secrets.GITHUB_TOKEN }}
cache: gradle

- name: Run gradle build and publish
- name: Grant execute permission for gradlew
shell: bash
run: chmod +x gradlew

- name: Run gradle publish and build
run: >
gradle publish shadowDistZip
-PmineinabyssMavenUsername=${{ secrets.MAVEN_PUBLISH_USERNAME }} -PmineinabyssMavenPassword=${{ secrets.MAVEN_PUBLISH_PASSWORD }}
- name: Run native compile
run: ./gradlew nativeCompile

- uses: MineInAbyss/publish-action@develop
with:
run-gradle-build: false
release-files: |
keepup-cli/build/distributions/keepup*.zip
keepup-cli/build/native/nativeCompile/keepup*.zip
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ tasks.dependencyUpdates {
isNonStable(candidate.version)
}
}

subprojects {
apply(plugin = "kotlin")
kotlin {
jvmToolchain(22)
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
kotlin.code.style=official
group=com.mineinabyss
version=3.1.0
version=3.1.1
idofrontVersion=0.25.6
11 changes: 6 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[versions]
clikt = "5.0.1"
hocon = "1.4.3"
kaml = "0.61.0"
kotlin = "2.0.20"
kaml = "0.65.0"
kotlin = "2.0.21"
kotlinx-coroutines = "1.9.0"
kotlinx-serialization = "1.7.3"
ktor = "2.3.12"
mordant = "3.0.0"
ktor = "3.0.1"
mordant = "3.0.1"
slf4j = "2.0.16"
turtle = "0.10.0"

Expand All @@ -23,8 +23,9 @@ slf4j = { module = "org.slf4j:slf4j-nop", version.ref = "slf4j" }
turtle = { module = "com.lordcodes.turtle:turtle", version.ref = "turtle" }

[plugins]
graalvm-nativeimage = "org.graalvm.buildtools.native:0.10.3"
kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
shadow = "com.github.johnrengelman.shadow:8.1.1"
versionCatalogUpdate = "nl.littlerobots.version-catalog-update:0.8.4"
versionCatalogUpdate = "nl.littlerobots.version-catalog-update:0.8.5"
versions = "com.github.ben-manes.versions:0.51.0"
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ConfigTreeBuilder {
onUntracked: (Path) -> Unit,
) {
val deleteDir = (root / deleteUnder)
if (deleteDir.notExists()) return
deleteDir.visitFileTree {
onPreVisitDirectory { directory, attr ->
if ("${directory.relativeTo(deleteDir).pathString}/" in config.keep)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.json.Json
import java.nio.file.Path
import kotlin.io.path.div
import kotlin.time.Duration.Companion.seconds

/**
* Ex url "github:MineInAbyss/Idofront:v0.20.6:*.jar"
Expand Down Expand Up @@ -63,7 +64,7 @@ class GithubDownload(
) {
val response = client.get {
timeout {
requestTimeoutMillis = HttpTimeout.INFINITE_TIMEOUT_MS
requestTimeoutMillis = 30.seconds.inWholeMilliseconds
}
if (config.overrideGithubRelease == LATEST)
url("https://api.github.com/repos/${artifact.repo}/releases")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import io.ktor.util.cio.*
import io.ktor.utils.io.*
import java.nio.file.Path
import kotlin.io.path.*
import kotlin.time.Duration.Companion.seconds

class HttpDownloader(
val client: HttpClient,
Expand All @@ -22,17 +23,17 @@ class HttpDownloader(
override suspend fun download(): List<DownloadResult> {
val cacheFile = targetDir.resolve("$fileName.cache")
val targetFile = targetDir.resolve(fileName)
val headers = client.head(source.query).headers
val lastModified = headers["Last-Modified"]?.fromHttpToGmtDate()
val length = headers["Content-Length"]?.toLongOrNull()
val headers = client.head(source.query)
val length = headers.contentLength()
val lastModified = headers.lastModified()

val cache = "Last-Modified: $lastModified, Content-Length: $length"
if (targetFile.exists() && cacheFile.exists() && cacheFile.readText() == cache)
return listOf(DownloadResult.SkippedBecauseCached(targetFile, source.keyInConfig))

client.get(source.query) {
timeout {
requestTimeoutMillis = HttpTimeout.INFINITE_TIMEOUT_MS
requestTimeoutMillis = 30.seconds.inWholeMilliseconds
}
}
.bodyAsChannel()
Expand Down
14 changes: 14 additions & 0 deletions keepup-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
alias(libs.plugins.kotlinJvm)
alias(libs.plugins.kotlinx.serialization)
alias(libs.plugins.shadow)
alias(libs.plugins.graalvm.nativeimage)
application
}

Expand Down Expand Up @@ -40,3 +41,16 @@ tasks {
}
}
}

graalvmNative {
binaries {
named("main") {
fallback.set(false)
verbose.set(false)

buildArgs.addAll("--initialize-at-build-time", "-Os")
imageName.set("keepup")
runtimeArgs.add("-Xmx10m")
}
}
}

0 comments on commit e0674bb

Please sign in to comment.