Skip to content

Commit

Permalink
undo
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr3zee committed Sep 23, 2024
1 parent ee524bf commit 95408f5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 25 deletions.
37 changes: 24 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport
import util.getSpacePassword
import util.getSpacePasswordOrNull
import util.kotlinVersionParsed
import util.libs

Expand Down Expand Up @@ -70,33 +70,44 @@ 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 usePrivateRegistry = isCI || localYarnUpdate.orNull?.toBooleanStrictOrNull() == true

val registryUrl = "https://packages.jetbrains.team/npm/p/krpc/build-deps/"
val registryUrl = if (usePrivateRegistry) {
"https://packages.jetbrains.team/npm/p/krpc/build-deps/"
} else {
"https://registry.npmjs.org"
}

// 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 buildNpmConfigFile = File(project.rootDir, "build/js/.npmrc")

val spacePassword: String = project.getSpacePassword()
val spacePassword: String? = project.getSpacePasswordOrNull()

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

val outputYarnText = """
registry: "$registryUrl"
""".trimIndent()

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

if (usePrivateRegistry) {
if (spacePassword == null) {
error("Expected space password for NPM log in")
}

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

outputNpmText += '\n' + """
always-auth: true
${registryUrl.removePrefix("https:")}:_authToken=$spacePassword
""".trimIndent()
}

buildYarnConfigFile.createNewFile()
buildYarnConfigFile.writeText(outputYarnText)
buildNpmConfigFile.createNewFile()
Expand Down
30 changes: 18 additions & 12 deletions gradle-conventions-settings/src/main/kotlin/util/properties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,26 @@ fun Project.getLocalProperties(): Properties {
}
}

private const val SPACE_USERNAME = "kotlinx.rpc.team.space.username"
private const val SPACE_USERNAME_ENV = "kotlinx_rpc_team_space_username"

fun Project.getSpaceUsername(): String {
val username = "kotlinx.rpc.team.space.username"
val usernameEnv = "kotlinx_rpc_team_space_username"
return getLocalProperties()[username] as String?
?: providers.gradleProperty(username).orNull
?: System.getenv(usernameEnv)?.ifEmpty { null }
?: requiredPropertyError(username, usernameEnv)
return getLocalProperties()[SPACE_USERNAME] as String?
?: providers.gradleProperty(SPACE_USERNAME).orNull
?: System.getenv(SPACE_USERNAME_ENV)?.ifEmpty { null }
?: requiredPropertyError(SPACE_USERNAME, SPACE_USERNAME_ENV)
}

private const val SPACE_PASSWORD = "kotlinx.rpc.team.space.password"
private const val SPACE_PASSWORD_ENV = "kotlinx_rpc_team_space_password"

fun Project.getSpacePassword(): String {
val password = "kotlinx.rpc.team.space.password"
val passwordEnv = "kotlinx_rpc_team_space_password"
return getLocalProperties()[password] as String?
?: providers.gradleProperty(password).orNull
?: System.getenv(passwordEnv)?.ifEmpty { null }
?: requiredPropertyError(password, passwordEnv)
return getSpacePasswordOrNull()
?: requiredPropertyError(SPACE_PASSWORD, SPACE_PASSWORD_ENV)
}

fun Project.getSpacePasswordOrNull(): String? {
return getLocalProperties()[SPACE_PASSWORD] as String?
?: providers.gradleProperty(SPACE_PASSWORD).orNull
?: System.getenv(SPACE_PASSWORD_ENV)?.ifEmpty { null }
}

0 comments on commit 95408f5

Please sign in to comment.