Skip to content

Commit

Permalink
Update repos to use private mirrors on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr3zee committed Sep 12, 2024
1 parent 73e0466 commit 40ff647
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 56 deletions.
30 changes: 19 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport
import util.getSpacePassword
import util.kotlinVersionParsed
import util.libs
Expand Down Expand Up @@ -65,27 +66,33 @@ 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 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 spacePassword: String? = getSpacePassword()

doLast {
var outputYarnYmlText = "npmRegistryServer: \"$registryUrl\""
val spacePassword: String = getSpacePassword()

if (spacePassword != null) {
if (spacePassword.split(".").size != 3) {
error("Unexpected Space Token format")
}
if (!isCI && localYarnUpdate.orNull?.toBooleanStrictOrNull() != true) {
return@doLast
}

outputYarnYmlText += "npmAlwaysAuth: true"
outputYarnYmlText += "npmAuthToken: \"$spacePassword\""
if (spacePassword.split(".").size != 3) {
error("Unexpected Space Token format")
}

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

buildYarnConfigFile.createNewFile()
buildYarnConfigFile.writeText("registry: $registryUrl")
buildYarnYmlConfigFile.createNewFile()
Expand All @@ -96,8 +103,6 @@ val executeNpmLogin by tasks.registering {
outputs.file(buildYarnYmlConfigFile).withPropertyName("buildOutputYarnYmlFile")
}

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 All @@ -120,6 +125,9 @@ rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlu

if (isCI) {
downloadBaseUrl = "https://packages.jetbrains.team/files/p/krpc/build-deps/"
yarnLockMismatchReport = YarnLockMismatchReport.FAIL
} else {
yarnLockMismatchReport = YarnLockMismatchReport.WARNING
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
@file:Suppress("DuplicatedCode", "MISSING_DEPENDENCY_CLASS")

pluginManagement {
fun logAbsentProperty(name: String, env: String): Nothing? {
logger.info("Property '$name' (or env var '$env') is not present for repository credentials.")
val isCI = System.getenv("TEAMCITY_VERSION") != null

return null
fun requiredPropertyError(name: String, env: String): Nothing {
throw GradleException("Property '$name' (or env var '$env') is not present for repository credentials.")
}

@Suppress("RemoveRedundantQualifierName")
fun getLocalProperties(): java.util.Properties {
return java.util.Properties().apply {
val propertiesDir = File(
Expand All @@ -29,22 +28,22 @@ pluginManagement {
}
}

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

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

/**
Expand All @@ -57,14 +56,9 @@ pluginManagement {
name = repoName.split("-").joinToString("") { it.replaceFirstChar { c -> c.titlecase() } }
url = uri("https://packages.jetbrains.team/maven/p/krpc/$repoName")

val username = getSpaceUsername()
val password = getSpacePassword()

if (username != null && password != null) {
credentials {
this.username = username
this.password = password
}
credentials {
username = getSpaceUsername()
password = getSpacePassword()
}
}
}
Expand All @@ -73,16 +67,21 @@ pluginManagement {
fun RepositoryHandler.buildDepsEap() = jbTeamPackages(repoName = "build-deps-eap")

repositories {
buildDeps()
buildDepsEap()
if (isCI) {
buildDeps()
buildDepsEap()
} else {
mavenCentral()
gradlePluginPortal()
}
}
}

gradle.rootProject {
fun logAbsentProperty(name: String, env: String): Nothing? {
logger.info("Property '$name' (or env var '$env') is not present for repository credentials.")
val isCI = System.getenv("TEAMCITY_VERSION") != null

return null
fun requiredPropertyError(name: String, env: String): Nothing {
throw GradleException("Property '$name' (or env var '$env') is not present for repository credentials.")
}

fun getLocalProperties(): java.util.Properties {
Expand All @@ -102,22 +101,22 @@ gradle.rootProject {
}
}

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

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

/**
Expand All @@ -131,14 +130,9 @@ gradle.rootProject {

url = uri("https://packages.jetbrains.team/maven/p/krpc/$repoName")

val username = getSpaceUsername()
val password = getSpacePassword()

if (username != null && password != null) {
credentials {
this.username = username
this.password = password
}
credentials {
username = getSpaceUsername()
password = getSpacePassword()
}
}
}
Expand All @@ -149,13 +143,27 @@ gradle.rootProject {
allprojects {
buildscript {
repositories {
buildDeps()
buildDepsEap()
if (isCI) {
buildDeps()
buildDepsEap()
} else {
mavenCentral()
gradlePluginPortal()
}
}
}

repositories {
buildDeps()
buildDepsEap()
if (isCI) {
buildDeps()
buildDepsEap()
} else {
mavenCentral()
maven("https://www.jetbrains.com/intellij-repository/releases")
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
maven("https://maven.pkg.jetbrains.space/public/p/ktor/eap")
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
}
}
}
}
15 changes: 7 additions & 8 deletions gradle-conventions-settings/src/main/kotlin/util/properties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@

package util

import org.gradle.api.GradleException
import org.gradle.api.Project
import java.io.File
import java.util.*

fun Project.logAbsentProperty(name: String, env: String): Nothing? {
logger.info("Property '$name' (or env var '$env') is not present for repository credentials.")

return null
fun requiredPropertyError(name: String, env: String): Nothing {
throw GradleException("Property '$name' (or env var '$env') is not present for repository credentials.")
}

fun Project.getLocalProperties(): Properties {
Expand All @@ -33,20 +32,20 @@ fun Project.getLocalProperties(): Properties {
}
}

fun Project.getSpaceUsername(): String? {
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 }
?: logAbsentProperty(username, usernameEnv)
?: requiredPropertyError(username, usernameEnv)
}

fun Project.getSpacePassword(): String? {
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 }
?: logAbsentProperty(password, passwordEnv)
?: requiredPropertyError(password, passwordEnv)
}
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ systemProp.org.gradle.kotlin.dsl.precompiled.accessors.strict=true
# Using compileOnly dependencies in these targets is not currently supported
# because compileOnly dependencies must be present during the compilation of projects that depend on this project.
kotlin.suppressGradlePluginWarnings=IncorrectCompileOnlyDependencyWarning

# uncomment to update yarn.lock locally
# Space credentials required - JB team only
#kotlinx.rpc.localYarnUpdate=true

0 comments on commit 40ff647

Please sign in to comment.