Skip to content

Commit

Permalink
[skp] feat: refactor GitHub Packages Registry credentials management.
Browse files Browse the repository at this point in the history
  • Loading branch information
HChenX authored and lingqiqi5211 committed Feb 3, 2025
1 parent e1ba724 commit c53f0ff
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
35 changes: 26 additions & 9 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
@file:Suppress("UnstableApiUsage")

var gprUser = System.getenv("GIT_ACTOR") ?:""
var gprKey = System.getenv("GIT_TOKEN") ?: ""

val gprInfoFile = File(rootProject.projectDir, "signing.properties")

if (gprInfoFile.exists()) {
val gprInfo = java.util.Properties().apply {
gprInfoFile.inputStream().use { load(it) }
}

// 在构建时请在 signing.properties 中添加 gpr.user(github 用户名)和 gpr.key(GitHub 个人令牌密钥)
// 提交时请勿提交以上字段,以免个人账号泄露
//
// When constructing, add gpr.user (Github user name) and gpr.key (Github personal token key) to signing.propertiess.
// Do not submit the above fields when submitted to avoid leakage of personal accounts
gprUser = gprInfo.getProperty("gpr.user") ?: ""
gprKey = gprInfo.getProperty("gpr.key") ?: ""

if (gprUser.isEmpty() || gprKey.isEmpty()) {
throw GradleException("\'gpr.user\' and \'gpr.key\' must be set in \'signing.properties\'")
}
}

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

pluginManagement {
Expand All @@ -12,22 +35,16 @@ pluginManagement {

dependencyResolutionManagement {
repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS
// 在构建时请在 gradle.properties 中添加 gpr.user(github 用户名)和 gpr.key(GitHub 个人令牌密钥)
// 提交时请勿提交以上字段,以免个人账号泄露
//
// When constructing, add GPR.USER (Github user name) and GPR.KEY (Github personal token key) to Gradle.properties.
// Do not submit the above fields when submitted to avoid leakage of personal accounts
val gprUser = settings.providers.gradleProperty("gpr.user")
val gprKey = settings.providers.gradleProperty("gpr.key")

repositories {
google()
mavenCentral()
mavenLocal()
maven {
url = uri("https://maven.pkg.github.com/ReChronoRain/HyperCeiler")
credentials {
username = gprUser.orNull ?: System.getenv("GIT_ACTOR")
password = gprKey.orNull ?: System.getenv("GIT_TOKEN")
username = gprUser
password = gprKey
}
}
maven("https://jitpack.io")
Expand Down
3 changes: 3 additions & 0 deletions signing.properties.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ storeFile=
storePassword=
keyAlias=
keyPassword=

gpr.user=
gpr.key=

0 comments on commit c53f0ff

Please sign in to comment.