Skip to content

Commit

Permalink
Fixed yarn install on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr3zee committed Sep 12, 2024
1 parent 7f86ae7 commit 8f6f839
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,43 +66,49 @@ if (kotlinVersion != kotlinGPVersion) {
error("KGP version mismatch. Project version: $kotlinVersion, KGP version: $kotlinGPVersion")
}

val isCI = System.getenv("TEAMCITY_VERSION") != null
val localYarnUpdate = providers.gradleProperty("kotlinx.rpc.localYarnUpdate")

val executeNpmLogin by tasks.registering {
val isCI = System.getenv("TEAMCITY_VERSION") != null
val localYarnUpdate = project.providers.gradleProperty("kotlinx.rpc.localYarnUpdate")

if (!isCI && localYarnUpdate.orNull?.toBooleanStrictOrNull() != true) {
return@registering
}

val registryUrl = "https://packages.jetbrains.team/npm/p/krpc/build-deps/"

// To prevent leaking of credentials in VCS on dev machine use the build directory config file
val buildYarnConfigFile = File(project.rootDir, "build/js/.yarnrc")
val buildYarnYmlConfigFile = File(project.rootDir, "build/js/.yarnrc.yml")
val buildNpmConfigFile = File(project.rootDir, "build/js/.npmrc")

doLast {
val spacePassword: String = getSpacePassword()

if (!isCI && localYarnUpdate.orNull?.toBooleanStrictOrNull() != true) {
return@doLast
}
val spacePassword: String = project.getSpacePassword()

doLast {
if (spacePassword.split(".").size != 3) {
error("Unexpected Space Token format")
}

val outputYarnYmlText = """
npmRegistryServer: \"$registryUrl\"
npmAlwaysAuth: true
npmAuthToken: "$spacePassword"
val outputYarnText = """
registry: "$registryUrl"
""".trimIndent()

val outputNpmText = """
registry: "$registryUrl"
always-auth: true
${registryUrl.removePrefix("https:")}:_authToken=$spacePassword
""".trimIndent()

buildYarnConfigFile.createNewFile()
buildYarnConfigFile.writeText("registry: $registryUrl")
buildYarnYmlConfigFile.createNewFile()
buildYarnYmlConfigFile.writeText(outputYarnYmlText)
buildYarnConfigFile.writeText(outputYarnText)
buildNpmConfigFile.createNewFile()
buildNpmConfigFile.writeText(outputNpmText)
}

outputs.file(buildYarnConfigFile).withPropertyName("buildOutputYarnFile")
outputs.file(buildYarnYmlConfigFile).withPropertyName("buildOutputYarnYmlFile")
outputs.file(buildNpmConfigFile).withPropertyName("buildOutputNpmFile")
}

val isCI = System.getenv("TEAMCITY_VERSION") != null

plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin::class.java).configureEach {
rootProject.extensions.configure(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension::class.java) {
download = true
Expand Down

0 comments on commit 8f6f839

Please sign in to comment.