Skip to content

Commit 40ff647

Browse files
committed
Update repos to use private mirrors on CI
1 parent 73e0466 commit 40ff647

File tree

4 files changed

+75
-56
lines changed

4 files changed

+75
-56
lines changed

build.gradle.kts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
6+
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport
67
import util.getSpacePassword
78
import util.kotlinVersionParsed
89
import util.libs
@@ -65,27 +66,33 @@ if (kotlinVersion != kotlinGPVersion) {
6566
error("KGP version mismatch. Project version: $kotlinVersion, KGP version: $kotlinGPVersion")
6667
}
6768

69+
val isCI = System.getenv("TEAMCITY_VERSION") != null
70+
val localYarnUpdate = providers.gradleProperty("kotlinx.rpc.localYarnUpdate")
71+
6872
val executeNpmLogin by tasks.registering {
6973
val registryUrl = "https://packages.jetbrains.team/npm/p/krpc/build-deps/"
7074

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

75-
val spacePassword: String? = getSpacePassword()
76-
7779
doLast {
78-
var outputYarnYmlText = "npmRegistryServer: \"$registryUrl\""
80+
val spacePassword: String = getSpacePassword()
7981

80-
if (spacePassword != null) {
81-
if (spacePassword.split(".").size != 3) {
82-
error("Unexpected Space Token format")
83-
}
82+
if (!isCI && localYarnUpdate.orNull?.toBooleanStrictOrNull() != true) {
83+
return@doLast
84+
}
8485

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

90+
val outputYarnYmlText = """
91+
npmRegistryServer: \"$registryUrl\"
92+
npmAlwaysAuth: true
93+
npmAuthToken: "$spacePassword"
94+
""".trimIndent()
95+
8996
buildYarnConfigFile.createNewFile()
9097
buildYarnConfigFile.writeText("registry: $registryUrl")
9198
buildYarnYmlConfigFile.createNewFile()
@@ -96,8 +103,6 @@ val executeNpmLogin by tasks.registering {
96103
outputs.file(buildYarnYmlConfigFile).withPropertyName("buildOutputYarnYmlFile")
97104
}
98105

99-
val isCI = System.getenv("TEAMCITY_VERSION") != null
100-
101106
plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin::class.java).configureEach {
102107
rootProject.extensions.configure(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension::class.java) {
103108
download = true
@@ -120,6 +125,9 @@ rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlu
120125

121126
if (isCI) {
122127
downloadBaseUrl = "https://packages.jetbrains.team/files/p/krpc/build-deps/"
128+
yarnLockMismatchReport = YarnLockMismatchReport.FAIL
129+
} else {
130+
yarnLockMismatchReport = YarnLockMismatchReport.WARNING
123131
}
124132
}
125133
}

gradle-conventions-settings/src/main/kotlin/conventions-repositories.settings.gradle.kts

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
@file:Suppress("DuplicatedCode", "MISSING_DEPENDENCY_CLASS")
66

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

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

14-
@Suppress("RemoveRedundantQualifierName")
1514
fun getLocalProperties(): java.util.Properties {
1615
return java.util.Properties().apply {
1716
val propertiesDir = File(
@@ -29,22 +28,22 @@ pluginManagement {
2928
}
3029
}
3130

32-
fun getSpaceUsername(): String? {
31+
fun getSpaceUsername(): String {
3332
val username = "kotlinx.rpc.team.space.username"
3433
val usernameEnv = "kotlinx_rpc_team_space_username"
3534
return getLocalProperties()[username] as String?
3635
?: settings.providers.gradleProperty(username).orNull
3736
?: System.getenv(usernameEnv)?.ifEmpty { null }
38-
?: logAbsentProperty(username, usernameEnv)
37+
?: requiredPropertyError(username, usernameEnv)
3938
}
4039

41-
fun getSpacePassword(): String? {
40+
fun getSpacePassword(): String {
4241
val password = "kotlinx.rpc.team.space.password"
4342
val passwordEnv = "kotlinx_rpc_team_space_password"
4443
return getLocalProperties()[password] as String?
4544
?: settings.providers.gradleProperty(password).orNull
4645
?: System.getenv(passwordEnv)?.ifEmpty { null }
47-
?: logAbsentProperty(password, passwordEnv)
46+
?: requiredPropertyError(password, passwordEnv)
4847
}
4948

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

60-
val username = getSpaceUsername()
61-
val password = getSpacePassword()
62-
63-
if (username != null && password != null) {
64-
credentials {
65-
this.username = username
66-
this.password = password
67-
}
59+
credentials {
60+
username = getSpaceUsername()
61+
password = getSpacePassword()
6862
}
6963
}
7064
}
@@ -73,16 +67,21 @@ pluginManagement {
7367
fun RepositoryHandler.buildDepsEap() = jbTeamPackages(repoName = "build-deps-eap")
7468

7569
repositories {
76-
buildDeps()
77-
buildDepsEap()
70+
if (isCI) {
71+
buildDeps()
72+
buildDepsEap()
73+
} else {
74+
mavenCentral()
75+
gradlePluginPortal()
76+
}
7877
}
7978
}
8079

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

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

8887
fun getLocalProperties(): java.util.Properties {
@@ -102,22 +101,22 @@ gradle.rootProject {
102101
}
103102
}
104103

105-
fun getSpaceUsername(): String? {
104+
fun getSpaceUsername(): String {
106105
val username = "kotlinx.rpc.team.space.username"
107106
val usernameEnv = "kotlinx_rpc_team_space_username"
108107
return getLocalProperties()[username] as String?
109108
?: settings.providers.gradleProperty(username).orNull
110109
?: System.getenv(usernameEnv)?.ifEmpty { null }
111-
?: logAbsentProperty(username, usernameEnv)
110+
?: requiredPropertyError(username, usernameEnv)
112111
}
113112

114-
fun getSpacePassword(): String? {
113+
fun getSpacePassword(): String {
115114
val password = "kotlinx.rpc.team.space.password"
116115
val passwordEnv = "kotlinx_rpc_team_space_password"
117116
return getLocalProperties()[password] as String?
118117
?: settings.providers.gradleProperty(password).orNull
119118
?: System.getenv(passwordEnv)?.ifEmpty { null }
120-
?: logAbsentProperty(password, passwordEnv)
119+
?: requiredPropertyError(password, passwordEnv)
121120
}
122121

123122
/**
@@ -131,14 +130,9 @@ gradle.rootProject {
131130

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

134-
val username = getSpaceUsername()
135-
val password = getSpacePassword()
136-
137-
if (username != null && password != null) {
138-
credentials {
139-
this.username = username
140-
this.password = password
141-
}
133+
credentials {
134+
username = getSpaceUsername()
135+
password = getSpacePassword()
142136
}
143137
}
144138
}
@@ -149,13 +143,27 @@ gradle.rootProject {
149143
allprojects {
150144
buildscript {
151145
repositories {
152-
buildDeps()
153-
buildDepsEap()
146+
if (isCI) {
147+
buildDeps()
148+
buildDepsEap()
149+
} else {
150+
mavenCentral()
151+
gradlePluginPortal()
152+
}
154153
}
155154
}
155+
156156
repositories {
157-
buildDeps()
158-
buildDepsEap()
157+
if (isCI) {
158+
buildDeps()
159+
buildDepsEap()
160+
} else {
161+
mavenCentral()
162+
maven("https://www.jetbrains.com/intellij-repository/releases")
163+
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
164+
maven("https://maven.pkg.jetbrains.space/public/p/ktor/eap")
165+
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
166+
}
159167
}
160168
}
161169
}

gradle-conventions-settings/src/main/kotlin/util/properties.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66

77
package util
88

9+
import org.gradle.api.GradleException
910
import org.gradle.api.Project
1011
import java.io.File
1112
import java.util.*
1213

13-
fun Project.logAbsentProperty(name: String, env: String): Nothing? {
14-
logger.info("Property '$name' (or env var '$env') is not present for repository credentials.")
15-
16-
return null
14+
fun requiredPropertyError(name: String, env: String): Nothing {
15+
throw GradleException("Property '$name' (or env var '$env') is not present for repository credentials.")
1716
}
1817

1918
fun Project.getLocalProperties(): Properties {
@@ -33,20 +32,20 @@ fun Project.getLocalProperties(): Properties {
3332
}
3433
}
3534

36-
fun Project.getSpaceUsername(): String? {
35+
fun Project.getSpaceUsername(): String {
3736
val username = "kotlinx.rpc.team.space.username"
3837
val usernameEnv = "kotlinx_rpc_team_space_username"
3938
return getLocalProperties()[username] as String?
4039
?: providers.gradleProperty(username).orNull
4140
?: System.getenv(usernameEnv)?.ifEmpty { null }
42-
?: logAbsentProperty(username, usernameEnv)
41+
?: requiredPropertyError(username, usernameEnv)
4342
}
4443

45-
fun Project.getSpacePassword(): String? {
44+
fun Project.getSpacePassword(): String {
4645
val password = "kotlinx.rpc.team.space.password"
4746
val passwordEnv = "kotlinx_rpc_team_space_password"
4847
return getLocalProperties()[password] as String?
4948
?: providers.gradleProperty(password).orNull
5049
?: System.getenv(passwordEnv)?.ifEmpty { null }
51-
?: logAbsentProperty(password, passwordEnv)
50+
?: requiredPropertyError(password, passwordEnv)
5251
}

gradle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@ systemProp.org.gradle.kotlin.dsl.precompiled.accessors.strict=true
3838
# Using compileOnly dependencies in these targets is not currently supported
3939
# because compileOnly dependencies must be present during the compilation of projects that depend on this project.
4040
kotlin.suppressGradlePluginWarnings=IncorrectCompileOnlyDependencyWarning
41+
42+
# uncomment to update yarn.lock locally
43+
# Space credentials required - JB team only
44+
#kotlinx.rpc.localYarnUpdate=true

0 commit comments

Comments
 (0)