From c53f0ff7562cda5ea00788a6becf6129f1610843 Mon Sep 17 00:00:00 2001 From: HChenX Date: Mon, 3 Feb 2025 20:52:13 +0800 Subject: [PATCH] [skp] feat: refactor GitHub Packages Registry credentials management. --- settings.gradle.kts | 35 ++++++++++++++++++++++++++--------- signing.properties.example | 3 +++ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 3eb173c9a2..c435cf5cd6 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -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 { @@ -12,13 +35,7 @@ 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() @@ -26,8 +43,8 @@ dependencyResolutionManagement { 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") diff --git a/signing.properties.example b/signing.properties.example index 4d416ab150..2938136489 100644 --- a/signing.properties.example +++ b/signing.properties.example @@ -2,3 +2,6 @@ storeFile= storePassword= keyAlias= keyPassword= + +gpr.user= +gpr.key=