Skip to content

Commit c53f0ff

Browse files
HChenXlingqiqi5211
authored andcommitted
[skp] feat: refactor GitHub Packages Registry credentials management.
1 parent e1ba724 commit c53f0ff

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

settings.gradle.kts

+26-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
@file:Suppress("UnstableApiUsage")
22

3+
var gprUser = System.getenv("GIT_ACTOR") ?:""
4+
var gprKey = System.getenv("GIT_TOKEN") ?: ""
5+
6+
val gprInfoFile = File(rootProject.projectDir, "signing.properties")
7+
8+
if (gprInfoFile.exists()) {
9+
val gprInfo = java.util.Properties().apply {
10+
gprInfoFile.inputStream().use { load(it) }
11+
}
12+
13+
// 在构建时请在 signing.properties 中添加 gpr.user(github 用户名)和 gpr.key(GitHub 个人令牌密钥)
14+
// 提交时请勿提交以上字段,以免个人账号泄露
15+
//
16+
// When constructing, add gpr.user (Github user name) and gpr.key (Github personal token key) to signing.propertiess.
17+
// Do not submit the above fields when submitted to avoid leakage of personal accounts
18+
gprUser = gprInfo.getProperty("gpr.user") ?: ""
19+
gprKey = gprInfo.getProperty("gpr.key") ?: ""
20+
21+
if (gprUser.isEmpty() || gprKey.isEmpty()) {
22+
throw GradleException("\'gpr.user\' and \'gpr.key\' must be set in \'signing.properties\'")
23+
}
24+
}
25+
326
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
427

528
pluginManagement {
@@ -12,22 +35,16 @@ pluginManagement {
1235

1336
dependencyResolutionManagement {
1437
repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS
15-
// 在构建时请在 gradle.properties 中添加 gpr.user(github 用户名)和 gpr.key(GitHub 个人令牌密钥)
16-
// 提交时请勿提交以上字段,以免个人账号泄露
17-
//
18-
// When constructing, add GPR.USER (Github user name) and GPR.KEY (Github personal token key) to Gradle.properties.
19-
// Do not submit the above fields when submitted to avoid leakage of personal accounts
20-
val gprUser = settings.providers.gradleProperty("gpr.user")
21-
val gprKey = settings.providers.gradleProperty("gpr.key")
38+
2239
repositories {
2340
google()
2441
mavenCentral()
2542
mavenLocal()
2643
maven {
2744
url = uri("https://maven.pkg.github.com/ReChronoRain/HyperCeiler")
2845
credentials {
29-
username = gprUser.orNull ?: System.getenv("GIT_ACTOR")
30-
password = gprKey.orNull ?: System.getenv("GIT_TOKEN")
46+
username = gprUser
47+
password = gprKey
3148
}
3249
}
3350
maven("https://jitpack.io")

signing.properties.example

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ storeFile=
22
storePassword=
33
keyAlias=
44
keyPassword=
5+
6+
gpr.user=
7+
gpr.key=

0 commit comments

Comments
 (0)