From 417cc58c3782e0c999b54768842aeaf7528615b4 Mon Sep 17 00:00:00 2001 From: Manuel Andruccioli Date: Fri, 15 Mar 2024 19:22:30 +0100 Subject: [PATCH] fix(ci): windows stuffs --- .github/workflows/build-and-deploy.yml | 9 --------- .../utils/NpmCommandsExtension.kt | 14 ++++++++++++-- .../gradle/TypescriptPluginTest.kt | 6 +++--- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index 699dbe8..ac66407 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -3,10 +3,6 @@ on: workflow_call: workflow_dispatch: -defaults: - run: - shell: bash - jobs: build: strategy: @@ -20,11 +16,6 @@ jobs: steps: - name: Checkout uses: DanySK/action-checkout@0.2.14 - - uses: actions/setup-node@v4 - if: matrix.os == 'windows-2022' - with: - node-version: 18 - cache: 'npm' - uses: DanySK/build-check-deploy-gradle-action@2.4.8 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/src/main/kotlin/io/github/zuccherosintattico/utils/NpmCommandsExtension.kt b/src/main/kotlin/io/github/zuccherosintattico/utils/NpmCommandsExtension.kt index 524cf25..f27b44d 100644 --- a/src/main/kotlin/io/github/zuccherosintattico/utils/NpmCommandsExtension.kt +++ b/src/main/kotlin/io/github/zuccherosintattico/utils/NpmCommandsExtension.kt @@ -7,6 +7,16 @@ import com.lordcodes.turtle.ShellScript */ object NpmCommandsExtension { + private fun String.cmdIfOnWindows(): String = System.getProperty("os.name").let { os -> + when { + os.contains("Windows") -> "$this.cmd" + else -> this + } + } + + private val npmCommand: String = "npm".cmdIfOnWindows() + private val npxCommand: String = "npx".cmdIfOnWindows() + /** * Install the dependencies. */ @@ -15,10 +25,10 @@ object NpmCommandsExtension { /** * Run the NPM command. */ - fun ShellScript.npmCommand(vararg arguments: String): String = command("npm", arguments.toList()) + fun ShellScript.npmCommand(vararg arguments: String): String = command(npmCommand, arguments.toList()) /** * Run the NPX command. */ - fun ShellScript.npxCommand(vararg arguments: String): String = command("npx", arguments.toList()) + fun ShellScript.npxCommand(vararg arguments: String): String = command(npxCommand, arguments.toList()) } diff --git a/src/test/kotlin/io/github/zuccherosintattico/gradle/TypescriptPluginTest.kt b/src/test/kotlin/io/github/zuccherosintattico/gradle/TypescriptPluginTest.kt index f7a18d7..4be0ac5 100644 --- a/src/test/kotlin/io/github/zuccherosintattico/gradle/TypescriptPluginTest.kt +++ b/src/test/kotlin/io/github/zuccherosintattico/gradle/TypescriptPluginTest.kt @@ -45,19 +45,19 @@ class TypescriptPluginTest : AnnotationSpec() { build() } - private fun Path.stringWalk(): List = toFile().walk().map { it.relativeTo(toFile()).toString() }.toList() + private fun Path.walkRelative(): List = toFile().walk().map { it.relativeTo(toFile()) }.toList() @Test fun `test base configuration`() { val testFolder = getTempDirectoryWithResources() testFolder.executeGradleTask("compileTypescript", "--stacktrace") - testFolder.stringWalk() shouldContainAll listOf( + testFolder.walkRelative() shouldContainAll listOf( "build/dist", "build/dist/index.js", "build/dist/person.js", "node_modules", "package-lock.json", - ) + ).map { File(it) } } }