Skip to content

Commit 56e481b

Browse files
committed
Fixed yarn install on CI
Update repos to use private mirrors on CI
1 parent a90f747 commit 56e481b

File tree

4 files changed

+94
-56
lines changed

4 files changed

+94
-56
lines changed

build.gradle.kts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*/
44

55
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
6+
import util.getSpacePassword
7+
import util.getSpaceUsername
68
import util.kotlinVersionParsed
79
import util.libs
810

@@ -65,38 +67,44 @@ if (kotlinVersionFull != kotlinGPVersion) {
6567
}
6668

6769
val executeNpmLogin by tasks.registering {
70+
val isCI = System.getenv("TEAMCITY_VERSION") != null
71+
val localYarnUpdate = project.providers.gradleProperty("kotlinx.rpc.localYarnUpdate")
72+
73+
if (!isCI && localYarnUpdate.orNull?.toBooleanStrictOrNull() != true) {
74+
return@registering
75+
}
76+
6877
val registryUrl = "https://packages.jetbrains.team/npm/p/krpc/build-deps/"
6978

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

74-
val spaceUsername: String? = getSpaceUsername()
75-
val spacePassword: String? = getSpacePassword()
83+
val spacePassword: String = project.getSpacePassword()
7684

7785
doLast {
78-
if (spaceUsername == null || spacePassword == null) {
79-
return@doLast
80-
}
81-
8286
if (spacePassword.split(".").size != 3) {
8387
error("Unexpected Space Token format")
8488
}
8589

86-
val outputYarnYmlText = """
87-
npmRegistryServer: "$registryUrl"
88-
npmAlwaysAuth: true
89-
npmAuthToken: "$spacePassword"
90+
val outputYarnText = """
91+
registry: "$registryUrl"
92+
""".trimIndent()
93+
94+
val outputNpmText = """
95+
registry: "$registryUrl"
96+
always-auth: true
97+
${registryUrl.removePrefix("https:")}:_authToken=$spacePassword
9098
""".trimIndent()
9199

92100
buildYarnConfigFile.createNewFile()
93-
buildYarnConfigFile.writeText("registry: $registryUrl")
94-
buildYarnYmlConfigFile.createNewFile()
95-
buildYarnYmlConfigFile.writeText(outputYarnYmlText)
101+
buildYarnConfigFile.writeText(outputYarnText)
102+
buildNpmConfigFile.createNewFile()
103+
buildNpmConfigFile.writeText(outputNpmText)
96104
}
97105

98106
outputs.file(buildYarnConfigFile).withPropertyName("buildOutputYarnFile")
99-
outputs.file(buildYarnYmlConfigFile).withPropertyName("buildOutputYarnYmlFile")
107+
outputs.file(buildNpmConfigFile).withPropertyName("buildOutputNpmFile")
100108
}
101109

102110
val isCI = System.getenv("TEAMCITY_VERSION") != null
@@ -123,6 +131,9 @@ rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlu
123131

124132
if (isCI) {
125133
downloadBaseUrl = "https://packages.jetbrains.team/files/p/krpc/build-deps/"
134+
yarnLockMismatchReport = YarnLockMismatchReport.FAIL
135+
} else {
136+
yarnLockMismatchReport = YarnLockMismatchReport.WARNING
126137
}
127138
}
128139
}

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

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@
44

55
@file:Suppress("DuplicatedCode", "MISSING_DEPENDENCY_CLASS")
66

7-
import java.util.*
8-
97
pluginManagement {
10-
fun logAbsentProperty(name: String): Nothing? {
11-
logger.info("Property '$name' is not present for repository credentials.")
8+
val isCI = System.getenv("TEAMCITY_VERSION") != null
129

13-
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.")
1412
}
1513

16-
@Suppress("RemoveRedundantQualifierName")
1714
fun getLocalProperties(): java.util.Properties {
1815
return java.util.Properties().apply {
1916
val propertiesDir = File(
@@ -31,20 +28,22 @@ pluginManagement {
3128
}
3229
}
3330

34-
fun getSpaceUsername(): String? {
31+
fun getSpaceUsername(): String {
3532
val username = "kotlinx.rpc.team.space.username"
33+
val usernameEnv = "kotlinx_rpc_team_space_username"
3634
return getLocalProperties()[username] as String?
3735
?: settings.providers.gradleProperty(username).orNull
38-
?: System.getenv(username)?.ifEmpty { null }
39-
?: logAbsentProperty(username)
36+
?: System.getenv(usernameEnv)?.ifEmpty { null }
37+
?: requiredPropertyError(username, usernameEnv)
4038
}
4139

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

5049
/**
@@ -56,6 +55,7 @@ pluginManagement {
5655
maven {
5756
name = repoName.split("-").joinToString("") { it.replaceFirstChar { c -> c.titlecase() } }
5857
url = uri("https://packages.jetbrains.team/maven/p/krpc/$repoName")
58+
5959
credentials {
6060
username = getSpaceUsername()
6161
password = getSpacePassword()
@@ -67,20 +67,25 @@ pluginManagement {
6767
fun RepositoryHandler.buildDepsEap() = jbTeamPackages(repoName = "build-deps-eap")
6868

6969
repositories {
70-
buildDeps()
71-
buildDepsEap()
70+
if (isCI) {
71+
buildDeps()
72+
buildDepsEap()
73+
} else {
74+
mavenCentral()
75+
gradlePluginPortal()
76+
}
7277
}
7378
}
7479

7580
gradle.rootProject {
76-
fun logAbsentProperty(name: String): Nothing? {
77-
logger.info("Property '$name' is not present for repository credentials.")
81+
val isCI = System.getenv("TEAMCITY_VERSION") != null
7882

79-
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.")
8085
}
8186

82-
fun getLocalProperties(): Properties {
83-
return Properties().apply {
87+
fun getLocalProperties(): java.util.Properties {
88+
return java.util.Properties().apply {
8489
val propertiesDir = File(
8590
rootDir.path
8691
.removeSuffix("/gradle-conventions")
@@ -96,20 +101,22 @@ gradle.rootProject {
96101
}
97102
}
98103

99-
fun getSpaceUsername(): String? {
104+
fun getSpaceUsername(): String {
100105
val username = "kotlinx.rpc.team.space.username"
106+
val usernameEnv = "kotlinx_rpc_team_space_username"
101107
return getLocalProperties()[username] as String?
102108
?: settings.providers.gradleProperty(username).orNull
103-
?: System.getenv(username)?.ifEmpty { null }
104-
?: logAbsentProperty(username)
109+
?: System.getenv(usernameEnv)?.ifEmpty { null }
110+
?: requiredPropertyError(username, usernameEnv)
105111
}
106112

107-
fun getSpacePassword(): String? {
113+
fun getSpacePassword(): String {
108114
val password = "kotlinx.rpc.team.space.password"
115+
val passwordEnv = "kotlinx_rpc_team_space_password"
109116
return getLocalProperties()[password] as String?
110117
?: settings.providers.gradleProperty(password).orNull
111-
?: System.getenv(password)?.ifEmpty { null }
112-
?: logAbsentProperty(password)
118+
?: System.getenv(passwordEnv)?.ifEmpty { null }
119+
?: requiredPropertyError(password, passwordEnv)
113120
}
114121

115122
/**
@@ -122,6 +129,7 @@ gradle.rootProject {
122129
name = repoName.split("-").joinToString("") { it.replaceFirstChar { c -> c.titlecase() } }
123130

124131
url = uri("https://packages.jetbrains.team/maven/p/krpc/$repoName")
132+
125133
credentials {
126134
username = getSpaceUsername()
127135
password = getSpacePassword()
@@ -135,13 +143,28 @@ gradle.rootProject {
135143
allprojects {
136144
buildscript {
137145
repositories {
138-
buildDeps()
139-
buildDepsEap()
146+
if (isCI) {
147+
buildDeps()
148+
buildDepsEap()
149+
} else {
150+
mavenCentral()
151+
gradlePluginPortal()
152+
}
140153
}
141154
}
155+
142156
repositories {
143-
buildDeps()
144-
buildDepsEap()
157+
if (isCI) {
158+
buildDeps()
159+
buildDepsEap()
160+
} else {
161+
mavenCentral()
162+
gradlePluginPortal()
163+
maven("https://www.jetbrains.com/intellij-repository/releases")
164+
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
165+
maven("https://maven.pkg.jetbrains.space/public/p/ktor/eap")
166+
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
167+
}
145168
}
146169
}
147170
}

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77
package util
88

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

12-
fun Project.logAbsentProperty(name: String): Nothing? {
13-
logger.info("Property '$name' is not present.")
14-
15-
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.")
1616
}
1717

18-
fun Project.getLocalProperties(): java.util.Properties {
19-
return java.util.Properties().apply {
18+
fun Project.getLocalProperties(): Properties {
19+
return Properties().apply {
2020
val propertiesDir = File(
2121
rootDir.path
2222
.removeSuffix("/gradle-conventions")
@@ -32,18 +32,20 @@ fun Project.getLocalProperties(): java.util.Properties {
3232
}
3333
}
3434

35-
fun Project.getSpaceUsername(): String? {
35+
fun Project.getSpaceUsername(): String {
3636
val username = "kotlinx.rpc.team.space.username"
37+
val usernameEnv = "kotlinx_rpc_team_space_username"
3738
return getLocalProperties()[username] as String?
3839
?: providers.gradleProperty(username).orNull
39-
?: System.getenv(username)?.ifEmpty { null }
40-
?: logAbsentProperty(username)
40+
?: System.getenv(usernameEnv)?.ifEmpty { null }
41+
?: requiredPropertyError(username, usernameEnv)
4142
}
4243

43-
fun Project.getSpacePassword(): String? {
44+
fun Project.getSpacePassword(): String {
4445
val password = "kotlinx.rpc.team.space.password"
46+
val passwordEnv = "kotlinx_rpc_team_space_password"
4547
return getLocalProperties()[password] as String?
4648
?: providers.gradleProperty(password).orNull
47-
?: System.getenv(password)?.ifEmpty { null }
48-
?: logAbsentProperty(password)
49+
?: System.getenv(passwordEnv)?.ifEmpty { null }
50+
?: requiredPropertyError(password, passwordEnv)
4951
}

settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pluginManagement {
1515

1616
includeBuild("gradle-plugin")
1717

18+
apply(from = "gradle-conventions-settings/src/main/kotlin/conventions-repositories.settings.gradle.kts")
19+
1820
resolutionStrategy {
1921
eachPlugin {
2022
if (requested.id.id == "kotlinx-atomicfu") {

0 commit comments

Comments
 (0)