Skip to content

Commit

Permalink
use new path apis
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysdh540 committed Nov 7, 2024
1 parent d665e74 commit 6a6076c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ jobs:
- name: :build
run: ./gradlew build --stacktrace --no-daemon

- name: :smokeTest
id: smokeTest
uses: coactions/setup-xvfb@v1
with:
run: ./gradlew :smokeTest --no-daemon

- name: Upload artifacts
if: always()
uses: actions/upload-artifact@v4
Expand All @@ -45,8 +39,15 @@ jobs:
path: |
**/build/libs/zume*.jar
build/libs/*mappings.txt
- name: :smokeTest
id: smokeTest
uses: coactions/setup-xvfb@v1
with:
run: ./gradlew :smokeTest --no-daemon

- name: test
if: always()
run: echo ${{ steps.smokeTest.outcome }}

- name: Upload test results
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
@file:OptIn(ExperimentalPathApi::class)

package dev.nolij.zumegradle.smoketest

import org.gradle.api.Project
import xyz.wagyourtail.unimined.util.cachingDownload
import java.io.File
import java.nio.file.Files
import kotlin.io.path.*
import kotlin.math.max

fun sleep(millis: Long) {
Expand Down Expand Up @@ -69,12 +65,12 @@ class SmokeTest(
}

private inner class Thread(val config: Config) {
val instancePath = "${workDir}/${config.name}"
val modsPath = "${instancePath}/mods"
val instancePath = File(workDir, config.name)
val modsPath = instancePath.resolve("mods")
val command: Array<String>
val setupLogFile = File("${instancePath}/setup.log")
val testLogFile = File("${instancePath}/test.log")
val gameLogFile = File("${instancePath}/logs/latest.log")
val setupLogFile = instancePath.resolve("setup.log")
val testLogFile = instancePath.resolve("test.log")
val gameLogFile = instancePath.resolve("logs/latest.log")

private var process: Process? = null
private var startTimestamp: Long? = null
Expand All @@ -96,16 +92,13 @@ class SmokeTest(
val done: Boolean get() = failed || stage == ThreadStage.COMPLETED

init {
Path(instancePath).also { path ->
if (!path.exists())
path.createDirectories()
if (!instancePath.exists()) {
instancePath.mkdirs()
}

Path(modsPath).also { modsPath ->
if (modsPath.exists())
modsPath.deleteRecursively()
modsPath.createDirectories()
}
if (modsPath.exists())
modsPath.deleteRecursively()
modsPath.mkdirs()

if (gameLogFile.exists())
gameLogFile.delete()
Expand All @@ -119,10 +112,10 @@ class SmokeTest(
).resolve() + urlDeps.map { project.cachingDownload(it).toFile() }

files.forEach { file ->
Files.copy(file.toPath(), Path("${modsPath}/${file.name}"))
file.copyTo(modsPath.resolve(file.name), overwrite = true)
}

Files.copy(modFile.toPath(), Path("${modsPath}/${modFile.name}"))
modFile.copyTo(modsPath.resolve(modFile.name), overwrite = true)

val extraArgs = mutableListOf<String>()

Expand All @@ -131,15 +124,17 @@ class SmokeTest(
21 to "java-runtime-delta",
8 to "jre-legacy"
)
if (config.jvmVersion != null)
extraArgs.add("--jvm=${mainDir}/jvm/${jvmVersionMap[config.jvmVersion]!!}/bin/java")
if (config.jvmVersion != null) {
val vmName = jvmVersionMap[config.jvmVersion] ?: error("Invalid JVM version: ${config.jvmVersion}")
extraArgs.add("--jvm=${mainDir}/jvm/${vmName}/bin/java")
}

extraArgs.addAll(config.extraArgs)

command = arrayOf(
portableMCBinary,
"--main-dir", mainDir,
"--work-dir", instancePath,
"--work-dir", instancePath.absolutePath,
"start", config.versionString,
*extraArgs.toTypedArray(),
"--jvm-args=-DzumeGradle.auditAndExit=true -Xmx1G",
Expand Down

0 comments on commit 6a6076c

Please sign in to comment.