Skip to content

Commit 75ccefa

Browse files
committed
Work around actions/toolkit#1925 better and more completely
1 parent 00f1a06 commit 75ccefa

File tree

2 files changed

+10
-55
lines changed

2 files changed

+10
-55
lines changed

gradle/build-logic/src/main/kotlin/net/kautler/node.gradle.kts

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package net.kautler
1818

1919
import net.kautler.dao.action.GitHubAction
20-
import net.kautler.util.npm
2120
import org.gradle.accessors.dm.LibrariesForLibs
2221
import org.gradle.accessors.dm.LibrariesForKotlinWrappers
2322
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec
@@ -156,6 +155,12 @@ dependencies {
156155
val syncDistribution by tasks.registering(Sync::class) {
157156
from(setupWslDistributionFiles)
158157
into(layout.buildDirectory.dir("distributions"))
158+
// work-around for https://github.com/actions/toolkit/issues/1925
159+
filesMatching("index.mjs") {
160+
filter {
161+
it.replace("stats = yield exports.stat", "stats = yield exports.lstat")
162+
}
163+
}
159164
}
160165

161166
tasks.assemble {

src/jsMain/kotlin/net/kautler/github/action/setup_wsl/SetupWsl.kt

+4-54
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import actions.exec.ExecOptions
3737
import actions.exec.exec
3838
import actions.io.mkdirP
3939
import actions.io.mv
40-
import actions.io.rmRF
4140
import actions.io.which
4241
import actions.tool.cache.cacheDir
4342
import actions.tool.cache.downloadTool
@@ -58,7 +57,6 @@ import node.buffer.BufferEncoding
5857
import node.fs.exists
5958
import node.fs.mkdtemp
6059
import node.fs.readdir
61-
import node.fs.stat
6260
import node.fs.writeFile
6361
import node.os.tmpdir
6462
import node.path.path
@@ -71,12 +69,6 @@ import kotlin.time.Duration.Companion.minutes
7169
import kotlin.time.Duration.Companion.seconds
7270
import actions.tool.cache.extractZip as toolCacheExtractZip
7371

74-
private const val BAD_WSL_EXE_PATH =
75-
"C:\\Users\\runneradmin\\AppData\\Local\\Microsoft\\WindowsApps\\wsl.exe"
76-
77-
private const val BAD_WSLCONFIG_EXE_PATH =
78-
"C:\\Users\\runneradmin\\AppData\\Local\\Microsoft\\WindowsApps\\wslconfig.exe"
79-
8072
suspend fun wslOutput(vararg args: String): String {
8173
val stdoutBuilder = StringBuilder()
8274
val stdoutBuilderUtf16Le = StringBuilder()
@@ -387,31 +379,12 @@ suspend fun verifyWindowsEnvironment() {
387379
}
388380

389381
suspend fun installWsl() {
390-
// part of work-around for https://github.com/actions/toolkit/issues/1925
391-
val deleteWslExe =
392-
runCatching { stat(BAD_WSL_EXE_PATH).isFile() }
393-
.getOrDefault(false)
394-
.not()
395-
val deleteWslConfigExe =
396-
runCatching { stat(BAD_WSLCONFIG_EXE_PATH).isFile() }
397-
.getOrDefault(false)
398-
.not()
399-
400382
exec(
401383
commandLine = "pwsh",
402384
args = arrayOf("-Command", """Start-Process wsl "--install --no-distribution""""),
403385
options = ExecOptions(ignoreReturnCode = true)
404386
)
405-
406-
waitForWslStatusNotContaining("is not installed", 5.minutes) {
407-
// part of work-around for https://github.com/actions/toolkit/issues/1925
408-
if (deleteWslExe) {
409-
rmRF(BAD_WSL_EXE_PATH)
410-
}
411-
if (deleteWslConfigExe) {
412-
rmRF(BAD_WSLCONFIG_EXE_PATH)
413-
}
414-
}
387+
waitForWslStatusNotContaining("is not installed", 5.minutes)
415388
}
416389

417390
suspend fun installDistribution() {
@@ -420,31 +393,12 @@ suspend fun installDistribution() {
420393
)
421394

422395
if (wslVersion() != 1u) {
423-
// part of work-around for https://github.com/actions/toolkit/issues/1925
424-
val deleteWslExe =
425-
runCatching { stat(BAD_WSL_EXE_PATH).isFile() }
426-
.getOrDefault(false)
427-
.not()
428-
val deleteWslConfigExe =
429-
runCatching { stat(BAD_WSLCONFIG_EXE_PATH).isFile() }
430-
.getOrDefault(false)
431-
.not()
432-
433396
retry(10) {
434397
executeWslCommand(
435398
wslArguments = arrayOf("--update")
436399
)
437400
}
438-
439-
// part of work-around for https://github.com/actions/toolkit/issues/1925
440-
waitForWslStatusNotContaining("WSL is finishing an upgrade...") {
441-
if (deleteWslExe) {
442-
rmRF(BAD_WSL_EXE_PATH)
443-
}
444-
if (deleteWslConfigExe) {
445-
rmRF(BAD_WSLCONFIG_EXE_PATH)
446-
}
447-
}
401+
waitForWslStatusNotContaining("WSL is finishing an upgrade...")
448402
}
449403

450404
exec(
@@ -456,17 +410,13 @@ suspend fun installDistribution() {
456410

457411
suspend fun waitForWslStatusNotContaining(
458412
text: String,
459-
duration: Duration = 30.seconds,
460-
preAction: suspend () -> Unit = {}
413+
duration: Duration = 30.seconds
461414
) {
462415
(2..duration.inWholeSeconds)
463416
.asFlow()
464417
.onEach { delay(1.seconds) }
465418
.onStart { emit(1) }
466-
.map {
467-
preAction()
468-
wslOutput("--status")
469-
}
419+
.map { wslOutput("--status") }
470420
.firstOrNull { !it.contains(text) }
471421
}
472422

0 commit comments

Comments
 (0)