From d37675f5c26bd299b93aae6b491f5fc5ef0f2358 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Fri, 5 Feb 2021 17:38:27 +0800 Subject: [PATCH 01/12] GPG sign for artifacts --- .gitignore | 5 +- build.gradle.kts | 1 + buildSrc/src/main/kotlin/GpgSigner.kt | 100 +++++++++++++++++ buildSrc/src/main/kotlin/JvmPublishing.kt | 1 + buildSrc/src/main/kotlin/MppPublishing.kt | 8 +- buildSrc/src/main/kotlin/PublishingGpgSign.kt | 102 ++++++++++++++++++ buildSrc/src/main/kotlin/Versions.kt | 2 +- 7 files changed, 215 insertions(+), 4 deletions(-) create mode 100644 buildSrc/src/main/kotlin/GpgSigner.kt create mode 100644 buildSrc/src/main/kotlin/PublishingGpgSign.kt diff --git a/.gitignore b/.gitignore index 9315f8357..c1d9012a0 100644 --- a/.gitignore +++ b/.gitignore @@ -45,4 +45,7 @@ keys.properties token.txt bintray.user.txt -bintray.key.txt \ No newline at end of file +bintray.key.txt + +# For gpg sign +/build-gpg-sign diff --git a/build.gradle.kts b/build.gradle.kts index a166695cf..b3f335cc8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -64,6 +64,7 @@ configure { } project.ext.set("isAndroidSDKAvailable", false) +GpgSigner.setup(project) tasks.register("publishMiraiCoreArtifactsToMavenLocal") { group = "mirai" diff --git a/buildSrc/src/main/kotlin/GpgSigner.kt b/buildSrc/src/main/kotlin/GpgSigner.kt new file mode 100644 index 000000000..4aa623a5d --- /dev/null +++ b/buildSrc/src/main/kotlin/GpgSigner.kt @@ -0,0 +1,100 @@ +/* + * Copyright 2019-2021 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ + + +import org.gradle.api.Project +import java.io.File + +open class GpgSigner(private val workdir: File) { + private val workdirParent by lazy { workdir.parentFile ?: error("Assertion error: No parent file of $workdir") } + private val workdirName by lazy { workdir.name } + + fun verbose(msg: String) { + println("[GPG SIGN] [Verbose] $msg") + } + + @Suppress("RemoveExplicitTypeArguments") + private val verbosePrintOnce by lazy { + verbose("GPG Signer working dir: $workdir") + verbose("GPG command working dir: $workdirParent") + } + + constructor(workdir: String) : this(File(workdir)) + + object NoopSigner : GpgSigner("build/gpg-noop") { + override fun processGpg(vararg cmds: String) { + } + + override fun importKey(file: File) { + } + + override fun doSign(file: File) { + } + } + + companion object { + private var initialized: Boolean = false + var signer: GpgSigner = NoopSigner + fun setup(project: Project) { + if (initialized) return + initialized = true + val rootProject = project.rootProject + val gpg = rootProject.projectDir.resolve("build-gpg-sign") + gpg.mkdirs() + val keyFile = gpg.resolve("keys.gpg") + if (keyFile.isFile) { + val homedir = gpg.resolve("homedir") + signer = GpgSigner(homedir.absolutePath) + if (!homedir.resolve("pubring.kbx").isFile) { + signer.importKey(keyFile) + } + } else { + rootProject.logger.warn("GPG Key not found.") + rootProject.logger.warn("GPG Signer will not setup") + rootProject.logger.warn("Key file location: $keyFile") + } + } + } + + open fun processGpg( + vararg cmds: String + ) { + workdir.mkdirs() + verbosePrintOnce + + val response = ProcessBuilder().command(ArrayList().apply { + add("gpg") + add("--homedir"); add(workdirName) + addAll(cmds) + }.also { + verbose("Processing " + it.joinToString(" ")) + }).directory(workdirParent) + .inheritIO() + .start() + .waitFor() + if (response != 0) { + error("Exit Response $response") + } + } + + open fun importKey(file: File) { + processGpg("--batch", "--import", file.toString()) + } + + open fun doSign(file: File) { + if (!file.isFile) { + println("[GPG SIGN] $file not a file") + return + } + println("[GPG SIGN] Signing $file") + File("${file.path}.asc").delete() + processGpg("-a", "--batch", "--no-tty", "--sign", file.toString()) + } + +} diff --git a/buildSrc/src/main/kotlin/JvmPublishing.kt b/buildSrc/src/main/kotlin/JvmPublishing.kt index 52f42e365..c1e2f2059 100644 --- a/buildSrc/src/main/kotlin/JvmPublishing.kt +++ b/buildSrc/src/main/kotlin/JvmPublishing.kt @@ -115,5 +115,6 @@ inline fun Project.configurePublishing( artifact(sourcesJar.get()) } } + configGpgSign(this@configurePublishing) } } \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/MppPublishing.kt b/buildSrc/src/main/kotlin/MppPublishing.kt index eff90e5ea..2238f5cf5 100644 --- a/buildSrc/src/main/kotlin/MppPublishing.kt +++ b/buildSrc/src/main/kotlin/MppPublishing.kt @@ -42,10 +42,13 @@ fun Project.configureMppPublishing() { .forEach { publication -> val moduleFile = buildDir.resolve("publications/${publication.name}/module.json") if (moduleFile.exists()) { - publication.artifact(object : + val artifact = (object : org.gradle.api.publish.maven.internal.artifact.FileBasedMavenArtifact(moduleFile) { override fun getDefaultExtension() = "module" }) + publication.artifact(artifact) + GpgSigner.signer.doSign(moduleFile) + publication.artifact(GPGSignMavenArtifact(artifact)) } } } @@ -86,6 +89,7 @@ fun Project.configureMppPublishing() { } } } + configGpgSign(this@configureMppPublishing) } } } @@ -129,6 +133,6 @@ val publishPlatformArtifactsInRootModule: Project.(MavenPublication) -> Unit = { } } -private fun MavenArtifact.smartToString(): String { +public fun MavenArtifact.smartToString(): String { return "${file.path}, classifier=${classifier}, ext=${extension}" } diff --git a/buildSrc/src/main/kotlin/PublishingGpgSign.kt b/buildSrc/src/main/kotlin/PublishingGpgSign.kt new file mode 100644 index 000000000..e0a52c3c4 --- /dev/null +++ b/buildSrc/src/main/kotlin/PublishingGpgSign.kt @@ -0,0 +1,102 @@ +/* + * Copyright 2019-2021 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ + +import org.gradle.api.Project +import org.gradle.api.internal.tasks.DefaultTaskDependency +import org.gradle.api.internal.tasks.TaskDependencyInternal +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.maven.MavenArtifact +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.api.publish.maven.internal.artifact.AbstractMavenArtifact +import org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication +import java.io.File + +open class GPGSignMavenArtifact( + private val delegate: MavenArtifact, + private val tasks: TaskDependencyInternal = TaskDependencyInternal.EMPTY +) : AbstractMavenArtifact() { + override fun getFile(): File { + return File(delegate.file.path + ".asc") + } + + override fun shouldBePublished(): Boolean = (delegate as? AbstractMavenArtifact)?.shouldBePublished() ?: true + override fun getDefaultExtension(): String = delegate.extension + ".asc" + override fun getDefaultClassifier(): String = delegate.classifier ?: "" + override fun getDefaultBuildDependencies(): TaskDependencyInternal = tasks +} + +class NameCounter(val name: String) { + var counter = 0 + val nextName: String + get() = name + if (counter == 0) { + counter = 1; "" + } else { + counter++; counter + } +} + +object PublishingAccess { + fun getMetadataArtifacts(publication: MavenPublication): Collection { + if (publication is DefaultMavenPublication) { + return DefaultMavenPublication::class.java.getDeclaredField("metadataArtifacts") + .also { it.isAccessible = true } + .get(publication) as Collection + } + return emptyList() + } +} + +fun PublishingExtension.configGpgSign(project: Project) { + if (GpgSigner.signer === GpgSigner.NoopSigner) { + return + } + val tasks = DefaultTaskDependency() + val signArtifactsGPG = NameCounter("signArtifactsGPG") + + publications.forEach { publication -> + if (publication is MavenPublication) { + val artifacts0: Collection, (MavenArtifact) -> Unit>> = listOf( + publication.artifacts to { publication.artifact(it) }, // main artifacts + PublishingAccess.getMetadataArtifacts(publication).let { artifacts -> // pom files + if (artifacts is MutableCollection) { + artifacts to { artifacts.add(it) } + } else { + artifacts to { publication.artifact(it) } + } + } + ) + val allArtifacts = artifacts0.flatMap { it.first }.toList() + + if (allArtifacts.isNotEmpty()) { + tasks.add(project.tasks.create(signArtifactsGPG.nextName) { + group = "publishing" + doLast { + allArtifacts.forEach { artifact -> + if ((artifact as? AbstractMavenArtifact)?.shouldBePublished() != false) { + GpgSigner.signer.doSign(artifact.file) + } + } + } + + allArtifacts.forEach { + dependsOn(it.buildDependencies) + } + }) + + artifacts0.forEach { (artifacts, artifactsRegister) -> + artifacts.toList().forEach { artifact -> + logPublishing("gpg sign for artifact ${artifact.smartToString()}") + artifactsRegister(GPGSignMavenArtifact(artifact, tasks)) + } + } + } + } + } + +} diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index a6c7824fd..83e5a0200 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -12,7 +12,7 @@ import org.gradle.api.attributes.Attribute object Versions { - const val project = "2.3.2" + const val project = "2.3.2-dev-publish-1" const val core = project const val console = project From 95d6484ec6ed52977c7ff6bc8e4f987734004fa3 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Fri, 5 Feb 2021 22:04:37 +0800 Subject: [PATCH 02/12] GPG sign 2nd verity --- buildSrc/src/main/kotlin/GpgSigner.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/main/kotlin/GpgSigner.kt b/buildSrc/src/main/kotlin/GpgSigner.kt index 4aa623a5d..9b17d7c2d 100644 --- a/buildSrc/src/main/kotlin/GpgSigner.kt +++ b/buildSrc/src/main/kotlin/GpgSigner.kt @@ -48,11 +48,18 @@ open class GpgSigner(private val workdir: File) { val gpg = rootProject.projectDir.resolve("build-gpg-sign") gpg.mkdirs() val keyFile = gpg.resolve("keys.gpg") + val keyFilePub = gpg.resolve("keys.gpg.pub") if (keyFile.isFile) { val homedir = gpg.resolve("homedir") signer = GpgSigner(homedir.absolutePath) if (!homedir.resolve("pubring.kbx").isFile) { signer.importKey(keyFile) + if (keyFilePub.isFile) { + signer.importKey(keyFilePub) + } else { + rootProject.logger.warn("Missing public key storage") + rootProject.logger.warn("GPG Sign 2nd verity may failed.") + } } } else { rootProject.logger.warn("GPG Key not found.") @@ -94,7 +101,8 @@ open class GpgSigner(private val workdir: File) { } println("[GPG SIGN] Signing $file") File("${file.path}.asc").delete() - processGpg("-a", "--batch", "--no-tty", "--sign", file.toString()) + processGpg("-a", "--batch", "--no-tty", "--detach-sig", "--sign", file.toString()) + processGpg("--verify", "$file.asc", file.toString()) } } From ea44735bce8090695190cda3d2d2ba615376a6a4 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Fri, 5 Feb 2021 22:07:35 +0800 Subject: [PATCH 03/12] POM file setup --- buildSrc/src/main/kotlin/JvmPublishing.kt | 15 +++++------ buildSrc/src/main/kotlin/MppPublishing.kt | 9 ++++--- buildSrc/src/main/kotlin/PublishingHelpers.kt | 26 +++++++++++++++++++ 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/buildSrc/src/main/kotlin/JvmPublishing.kt b/buildSrc/src/main/kotlin/JvmPublishing.kt index c1e2f2059..ee0b54258 100644 --- a/buildSrc/src/main/kotlin/JvmPublishing.kt +++ b/buildSrc/src/main/kotlin/JvmPublishing.kt @@ -31,7 +31,7 @@ import org.gradle.kotlin.dsl.registering */ -fun Project.configureBintray() { +fun Project.configureRemoteRepos() { tasks.register("ensureBintrayAvailable") { doLast { if (!project.isBintrayAvailable()) { @@ -63,7 +63,7 @@ inline fun Project.configurePublishing( bintrayPkgName: String = artifactId, vcs: String = "https://github.com/mamoe/mirai" ) { - configureBintray() + configureRemoteRepos() apply() if (!project.isBintrayAvailable()) { @@ -104,13 +104,10 @@ inline fun Project.configurePublishing( setArtifactId(artifactId) version = project.version.toString() - pom.withXml { - val root = asNode() - root.appendNode("description", description) - root.appendNode("name", project.name) - root.appendNode("url", vcs) - root.children().last() - } + setupPom( + project = project, + vcs = vcs + ) artifact(sourcesJar.get()) } diff --git a/buildSrc/src/main/kotlin/MppPublishing.kt b/buildSrc/src/main/kotlin/MppPublishing.kt index 2238f5cf5..f93acf51a 100644 --- a/buildSrc/src/main/kotlin/MppPublishing.kt +++ b/buildSrc/src/main/kotlin/MppPublishing.kt @@ -21,7 +21,7 @@ fun logPublishing(message: String) { } fun Project.configureMppPublishing() { - configureBintray() + configureRemoteRepos() // mirai does some magic on MPP targets afterEvaluate { @@ -64,9 +64,10 @@ fun Project.configureMppPublishing() { logPublishing("Publications: ${publications.joinToString { it.name }}") publications.filterIsInstance().forEach { publication -> - if (publication.name != "kotlinMultiplatform") { - publication.artifact(stubJavadoc) - } + // Maven Central always require javadoc.jar + publication.artifact(stubJavadoc) + + publication.setupPom(project) logPublishing(publication.name) when (val type = publication.name) { diff --git a/buildSrc/src/main/kotlin/PublishingHelpers.kt b/buildSrc/src/main/kotlin/PublishingHelpers.kt index aaf9817b1..6da830f74 100644 --- a/buildSrc/src/main/kotlin/PublishingHelpers.kt +++ b/buildSrc/src/main/kotlin/PublishingHelpers.kt @@ -15,6 +15,7 @@ import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.publish.PublicationContainer +import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.tasks.TaskContainer import org.gradle.kotlin.dsl.ExistingDomainObjectDelegate import org.gradle.kotlin.dsl.RegisteringDomainObjectDelegateProviderWithTypeAndAction @@ -77,3 +78,28 @@ val Project.publications: PublicationContainer } return ret } + +fun MavenPublication.setupPom( + project: Project, + vcs: String = "https://github.com/mamoe/mirai" +) { + pom { + scm { + url.set(vcs) + connection.set("scm:$vcs.git") + developerConnection.set("scm:${vcs.replace("https:", "git:")}.git") + } + + developers { + } + + } + + pom.withXml { + val root = asNode() + root.appendNode("description", project.description) + root.appendNode("name", project.name) + root.appendNode("url", vcs) + } +} + From cd47c60e76a59774598815f39eb6313d81427de1 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sat, 6 Feb 2021 08:15:21 +0800 Subject: [PATCH 04/12] Add the missing values in POM --- buildSrc/src/main/kotlin/PublishingHelpers.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/buildSrc/src/main/kotlin/PublishingHelpers.kt b/buildSrc/src/main/kotlin/PublishingHelpers.kt index 6da830f74..226b0325b 100644 --- a/buildSrc/src/main/kotlin/PublishingHelpers.kt +++ b/buildSrc/src/main/kotlin/PublishingHelpers.kt @@ -90,7 +90,19 @@ fun MavenPublication.setupPom( developerConnection.set("scm:${vcs.replace("https:", "git:")}.git") } + licenses { + license { + name.set("GNU AGPLv3") + url.set("https://github.com/mamoe/mirai/blob/master/LICENSE") + } + } + developers { + developer { + id.set("mamoe") + name.set("Mamoe Technologies") + email.set("support@mamoe.net") + } } } From 0750e81b4508bd6f28a674c136c519e3702801db Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sat, 6 Feb 2021 08:16:29 +0800 Subject: [PATCH 05/12] Setup sonatype remote --- buildSrc/src/main/kotlin/JvmPublishing.kt | 75 +++++++------ buildSrc/src/main/kotlin/keys/SecretKeys.kt | 114 ++++++++++++++++++++ buildSrc/src/main/kotlin/upload/Bintray.kt | 85 ++------------- 3 files changed, 167 insertions(+), 107 deletions(-) create mode 100644 buildSrc/src/main/kotlin/keys/SecretKeys.kt diff --git a/buildSrc/src/main/kotlin/JvmPublishing.kt b/buildSrc/src/main/kotlin/JvmPublishing.kt index ee0b54258..0ff429720 100644 --- a/buildSrc/src/main/kotlin/JvmPublishing.kt +++ b/buildSrc/src/main/kotlin/JvmPublishing.kt @@ -13,6 +13,7 @@ ) import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin +import keys.SecretKeys import org.gradle.api.Project import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.tasks.bundling.Jar @@ -21,16 +22,6 @@ import org.gradle.kotlin.dsl.get import org.gradle.kotlin.dsl.register import org.gradle.kotlin.dsl.registering -/* - * Copyright 2020 Mamoe Technologies and contributors. - * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. - * - * https://github.com/mamoe/mirai/blob/master/LICENSE - */ - - fun Project.configureRemoteRepos() { tasks.register("ensureBintrayAvailable") { doLast { @@ -39,10 +30,27 @@ fun Project.configureRemoteRepos() { } } } + publishing { + // sonatype + val keys = SecretKeys.getCache(project) + repositories { + val sonatype = keys.loadKey("sonatype") + if (sonatype.isValid) { + maven { + // Maven Central + setUrl("https://oss.sonatype.org/service/local/staging/deploy/maven2") - if (isBintrayAvailable()) { - publishing { - repositories { + credentials { + username = sonatype.user + password = sonatype.password + } + } + } else { + println("SonaType is not available") + } + + + if (isBintrayAvailable()) { maven { setUrl("https://api.bintray.com/maven/him188moe/mirai/mirai-core/;publish=1;override=1") @@ -51,7 +59,10 @@ fun Project.configureRemoteRepos() { password = Bintray.getKey(project) } } + } else { + println("bintray isn't available.") } + } } } @@ -66,27 +77,24 @@ inline fun Project.configurePublishing( configureRemoteRepos() apply() - if (!project.isBintrayAvailable()) { - println("bintray isn't available. NO PUBLICATIONS WILL BE SET") - return - } + if (project.isBintrayAvailable()) { + bintray { + user = Bintray.getUser(project) + key = Bintray.getKey(project) - bintray { - user = Bintray.getUser(project) - key = Bintray.getKey(project) + setPublications("mavenJava") + setConfigurations("archives") - setPublications("mavenJava") - setConfigurations("archives") + publish = true + override = true - publish = true - override = true - - pkg.apply { - repo = bintrayRepo - name = bintrayPkgName - setLicenses("AGPLv3") - publicDownloadNumbers = true - vcsUrl = vcs + pkg.apply { + repo = bintrayRepo + name = bintrayPkgName + setLicenses("AGPLv3") + publicDownloadNumbers = true + vcsUrl = vcs + } } } @@ -94,6 +102,10 @@ inline fun Project.configurePublishing( archiveClassifier.set("sources") from(sourceSets["main"].allSource) } + val stubJavadoc = tasks.register("javadocJar", Jar::class) { + @Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") + archiveClassifier.set("javadoc") + } publishing { publications { @@ -110,6 +122,7 @@ inline fun Project.configurePublishing( ) artifact(sourcesJar.get()) + artifact(stubJavadoc.get()) } } configGpgSign(this@configurePublishing) diff --git a/buildSrc/src/main/kotlin/keys/SecretKeys.kt b/buildSrc/src/main/kotlin/keys/SecretKeys.kt new file mode 100644 index 000000000..6338cffec --- /dev/null +++ b/buildSrc/src/main/kotlin/keys/SecretKeys.kt @@ -0,0 +1,114 @@ +/* + * Copyright 2019-2021 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ + +package keys + +import org.gradle.api.Project + +open class SecretKeys( + val type: String, + val user: String, + val password: String +) { + class Invalid( + type: String, + override val isDisabled: Boolean = false + ) : SecretKeys(type, "", "") { + override val isValid: Boolean get() = false + override fun requireNotInvalid(): Nothing { + error( + """ + Key $type not found. + Please lease specify by creating a file $type.key in projectDir/build-secret-keys + or by providing JVM parameter '$type.user', `$type.password` + """.trimIndent() + ) + } + } + + companion object { + val keyCaches = mutableMapOf() + + @JvmStatic + fun getCache(project: Project): ProjectKeysCache = + keyCaches.computeIfAbsent(project, SecretKeys::ProjectKeysCache) + } + + class ProjectKeysCache(val project: Project) { + val keys = mutableMapOf() + fun loadKey(type: String) = keys.computeIfAbsent(type, this::loadKey0) + + private fun loadKey0(type: String): SecretKeys { + + project.parent?.let { parent -> + getCache(parent).loadKey(type).takeIf { + it.isValid || it.isDisabled + }?.let { return it } + } + + val secretKeys = project.projectDir.resolve("build-secret-keys") + + kotlin.run { + val secretKeyFile = secretKeys.resolve("$type.disable").takeIf { it.isFile } + ?: secretKeys.resolve("$type.disable.txt") + if (secretKeyFile.isFile) return Invalid(type, true) // Disabled + } + + // Load from secretKeys/$type.key + kotlin.run { + val secretKeyFile = secretKeys.resolve("$type.key").takeIf { it.isFile } + ?: secretKeys.resolve("$type.key.txt") + if (secretKeyFile.isFile) { + secretKeyFile.bufferedReader().use { + return SecretKeys(type, it.readLine().trim(), it.readLine().trim()) + } + } + } + // Load from project/%type.key, user + kotlin.run { + val userFile = project.projectDir.resolve("$type.user.txt") + val keyFile = project.projectDir.resolve("$type.key.txt") + if (userFile.isFile && keyFile.isFile) { + return SecretKeys(type, userFile.readText().trim(), keyFile.readText().trim()) + } + } + + + // Load from property $type.user, $type.password + + fun findProperty(type: String): String? { + val p = project.findProperty(type) + ?: System.getProperty(type) + ?: System.getenv(type) + + return p?.toString() + } + + val tUser = findProperty("$type.user") + ?: findProperty("${type}_user") + + val tPassword = findProperty("$type.password") + ?: findProperty("$type.passwd") + ?: findProperty("$type.key") + ?: findProperty("${type}_password") + ?: findProperty("${type}_passwd") + ?: findProperty("${type}_key") + + if (tUser != null && tPassword != null) { + return SecretKeys(type, tUser, tPassword) + } + + return Invalid(type) + } + } + + open val isValid: Boolean get() = true + open val isDisabled: Boolean get() = false + open fun requireNotInvalid(): SecretKeys = this +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/upload/Bintray.kt b/buildSrc/src/main/kotlin/upload/Bintray.kt index 1041b7e03..615c330b1 100644 --- a/buildSrc/src/main/kotlin/upload/Bintray.kt +++ b/buildSrc/src/main/kotlin/upload/Bintray.kt @@ -7,18 +7,9 @@ * https://github.com/mamoe/mirai/blob/master/LICENSE */ +import keys.SecretKeys import org.gradle.api.Project -import org.gradle.kotlin.dsl.provideDelegate -import java.io.File -/* - * Copyright 2019-2020 Mamoe Technologies and contributors. - * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 with Mamoe Exceptions 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 with Mamoe Exceptions license that can be found via the following link. - * - * https://github.com/mamoe/mirai/blob/master/LICENSE - */ fun Project.isBintrayAvailable() = Bintray.isBintrayAvailable(project) @Suppress("DuplicatedCode") @@ -34,76 +25,18 @@ object Bintray { @JvmStatic fun getUser(project: Project): String { - kotlin.runCatching { - @Suppress("UNUSED_VARIABLE", "LocalVariableName") - val bintray_user: String by project - return bintray_user - } - - kotlin.runCatching { - @Suppress("UNUSED_VARIABLE", "LocalVariableName") - val bintray_user: String by project.rootProject - return bintray_user - } - - System.getProperty("bintray_user", null)?.let { - return it.trim() - } - - File(File(System.getProperty("user.dir")).parent, "/bintray.user.txt").let { local -> - if (local.exists()) { - return local.readText().trim() - } - } - - File(File(System.getProperty("user.dir")), "/bintray.user.txt").let { local -> - if (local.exists()) { - return local.readText().trim() - } - } - - error( - "Cannot find bintray user, " + - "please specify by creating a file bintray.user.txt in project dir, " + - "or by providing JVM parameter 'bintray_user'" - ) + return SecretKeys.getCache(project) + .loadKey("bintray") + .requireNotInvalid() + .user } @JvmStatic fun getKey(project: Project): String { - kotlin.runCatching { - @Suppress("UNUSED_VARIABLE", "LocalVariableName") - val bintray_key: String by project - return bintray_key - } - - kotlin.runCatching { - @Suppress("UNUSED_VARIABLE", "LocalVariableName") - val bintray_key: String by project.rootProject - return bintray_key - } - - System.getProperty("bintray_key", null)?.let { - return it.trim() - } - - File(File(System.getProperty("user.dir")).parent, "/bintray.key.txt").let { local -> - if (local.exists()) { - return local.readText().trim() - } - } - - File(File(System.getProperty("user.dir")), "/bintray.key.txt").let { local -> - if (local.exists()) { - return local.readText().trim() - } - } - - error( - "Cannot find bintray key, " + - "please specify by creating a file bintray.key.txt in project dir, " + - "or by providing JVM parameter 'bintray_key'" - ) + return SecretKeys.getCache(project) + .loadKey("bintray") + .requireNotInvalid() + .password } } \ No newline at end of file From eacbbef54d317ec7add4f5b62e619e8ccc86c964 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sat, 6 Feb 2021 08:32:01 +0800 Subject: [PATCH 06/12] ignore `build-secret-keys` --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index c1d9012a0..fb2977862 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,5 @@ bintray.key.txt # For gpg sign /build-gpg-sign +# Name for IDEA direction sorting +build-secret-keys/ From 9af889f730ec4dcabdfbef54f146231bf35dc1b1 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sat, 6 Feb 2021 15:41:09 +0800 Subject: [PATCH 07/12] GitHub Workflow --- .github/workflows/bintray.yml | 123 -------------------- .github/workflows/release.yml | 120 +++++++++++++++++++ buildSrc/src/main/kotlin/GpgSigner.kt | 10 +- buildSrc/src/main/kotlin/JvmPublishing.kt | 12 ++ buildSrc/src/main/kotlin/keys/SecretKeys.kt | 11 +- 5 files changed, 147 insertions(+), 129 deletions(-) delete mode 100644 .github/workflows/bintray.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/bintray.yml b/.github/workflows/bintray.yml deleted file mode 100644 index 719ce36bf..000000000 --- a/.github/workflows/bintray.yml +++ /dev/null @@ -1,123 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: Bintray Publish - -# Controls when the action will run. Triggers the workflow on push or pull request -# events but only for the master branch -on: - release: - types: [ created, prereleased ] - push: - tags: - - '*-dev*' - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - publish-mirai: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Checkout submodules - run: git submodule update --init --recursive --remote - - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - - name: chmod -R 777 * - run: chmod -R 777 * - - - name: Init gradle project - run: ./gradlew clean --info - - - name: Check keys - run: > - ./gradlew :mirai-core-utils:ensureBintrayAvailable - :mirai-core-api:ensureBintrayAvailable - :mirai-core:ensureBintrayAvailable - :mirai-console:ensureBintrayAvailable - -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} - -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }} - - - name: fillBuildConstants - run: > - ./gradlew - fillBuildConstants --info --stacktrace - -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} - -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }} - - - name: Assemble - run: ./gradlew assemble --info --stacktrace - - - name: Check - run: ./gradlew check --info --stacktrace - - - name: Gradle :mirai-core-utils:publish - run: > - ./gradlew :mirai-core-utils:publish --info --stacktrace - -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} - -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }} - - - name: Gradle :mirai-core-api:publish - run: > - ./gradlew :mirai-core-api:publish --info --stacktrace - -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} - -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }} - - - name: Gradle :mirai-core:publish - run: > - ./gradlew :mirai-core:publish --info --stacktrace - -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} - -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }} - - - name: Gradle :mirai-core-all:bintrayUpload - run: > - ./gradlew :mirai-core-all:bintrayUpload --info - -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} - -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }} - - - name: Gradle :mirai-console:bintrayUpload - run: > - ./gradlew - :mirai-console:bintrayUpload --info - -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} - -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }} - - - name: Gradle :mirai-console-terminal:bintrayUpload - run: > - ./gradlew - :mirai-console-terminal:bintrayUpload --info - -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} - -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }} - - - name: Gradle :mirai-console-compiler-common:bintrayUpload - run: > - ./gradlew - :mirai-console-compiler-common:bintrayUpload --info - -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} - -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }} - - - name: Gradle :mirai-console-compiler-annotations:bintrayUpload - run: > - ./gradlew - :mirai-console-compiler-annotations:bintrayUpload --info - -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} - -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }} - - - name: Gradle :mirai-console-intellij:bintrayUpload - run: > - ./gradlew - :mirai-console-intellij:bintrayUpload --info - -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} - -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }} - - - name: Publish Gradle plugin - run: > - ./gradlew - :mirai-console-gradle:publishPlugins --info --stacktrace - -Dgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} -Pgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} - -Dgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} -Pgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..933e45141 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,120 @@ +# This is a basic workflow to help you get started with Actions + +name: Release Publish + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the master branch +on: + release: + types: [ created, prereleased ] + push: + tags: + - '*-dev*' + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + publish-mirai: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Checkout submodules + run: git submodule update --init --recursive --remote + + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + + - name: chmod -R 777 * + run: chmod -R 777 * + + - name: Init gradle project + run: ./gradlew clean --info + + - name: Keys setup + shell: bash + run: | + mkdir build-gpg-sign + echo "$GPG_PRIVATE" > build-gpg-sign/keys.gpg + echo "$GPG_PUBLIC_" > build-gpg-sign/keys.gpg.pub + mkdir build-secret-keys + echo "$SONATYPE_USER" > build-secret-keys/sonatype.key + echo "$SONATYPE_KEY" >> build-secret-keys/sonatype.key + echo "$BINTRAY_USER" > build-secret-keys/bintray.key + echo "$BINTRAY_KEY" >> build-secret-keys/bintray.key + env: + GPG_PRIVATE: ${{ secrets.GPG_PRIVATE_KEY }} + GPG_PUBLIC_: ${{ secrets.GPG_PUBLIC_KEY }} + SONATYPE_USER: ${{ secrets.SONATYPE_USER }} + SONATYPE_KEY: ${{ secrets.SONATYPE_KEY }} + BINTRAY_USER: ${{ secrets.BINTRAY_USER }} + BINTRAY_KEY: ${{ secrets.BINTRAY_KEY }} + + - name: Check keys + run: > + ./gradlew + :mirai-core-utils:ensureBintrayAvailable + :mirai-core-api:ensureBintrayAvailable + :mirai-core:ensureBintrayAvailable + :mirai-console:ensureBintrayAvailable + :mirai-core-utils:ensureMavenCentralAvailable + :mirai-core-api:ensureMavenCentralAvailable + :mirai-core:ensureMavenCentralAvailable + :mirai-console:ensureMavenCentralAvailable + + - name: fillBuildConstants + run: > + ./gradlew + fillBuildConstants --info --stacktrace + + - name: Assemble + run: ./gradlew assemble --info --stacktrace + + - name: Check + run: ./gradlew check --info --stacktrace + + - name: Gradle :mirai-core-utils:publish + run: > + ./gradlew :mirai-core-utils:publish --info --stacktrace + + - name: Gradle :mirai-core-api:publish + run: > + ./gradlew :mirai-core-api:publish --info --stacktrace + + - name: Gradle :mirai-core:publish + run: > + ./gradlew :mirai-core:publish --info --stacktrace + + - name: Gradle :mirai-core-all:publish + run: > + ./gradlew :mirai-core-all:publish --info + + - name: Gradle :mirai-console:publish + run: > + ./gradlew + :mirai-console:publish --info + + - name: Gradle :mirai-console-terminal:publish + run: > + ./gradlew + :mirai-console-terminal:publish --info + + - name: Gradle :mirai-console-compiler-common:publish + run: > + ./gradlew + :mirai-console-compiler-common:publish --info + + - name: Gradle :mirai-console-compiler-annotations:publish + run: > + ./gradlew + :mirai-console-compiler-annotations:publish --info + + - name: Publish Gradle plugin + run: > + ./gradlew + :mirai-console-gradle:publishPlugins --info --stacktrace + -Dgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} -Pgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} + -Dgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} -Pgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} diff --git a/buildSrc/src/main/kotlin/GpgSigner.kt b/buildSrc/src/main/kotlin/GpgSigner.kt index 9b17d7c2d..8ee91e941 100644 --- a/buildSrc/src/main/kotlin/GpgSigner.kt +++ b/buildSrc/src/main/kotlin/GpgSigner.kt @@ -57,14 +57,14 @@ open class GpgSigner(private val workdir: File) { if (keyFilePub.isFile) { signer.importKey(keyFilePub) } else { - rootProject.logger.warn("Missing public key storage") - rootProject.logger.warn("GPG Sign 2nd verity may failed.") + println("[GPG SIGN] Missing public key storage") + println("[GPG SIGN] GPG Sign 2nd verity may failed.") } } } else { - rootProject.logger.warn("GPG Key not found.") - rootProject.logger.warn("GPG Signer will not setup") - rootProject.logger.warn("Key file location: $keyFile") + println("[GPG SIGN] GPG Key not found.") + println("[GPG SIGN] GPG Signer will not setup") + println("[GPG SIGN] Key file location: $keyFile") } } } diff --git a/buildSrc/src/main/kotlin/JvmPublishing.kt b/buildSrc/src/main/kotlin/JvmPublishing.kt index 0ff429720..3a996f364 100644 --- a/buildSrc/src/main/kotlin/JvmPublishing.kt +++ b/buildSrc/src/main/kotlin/JvmPublishing.kt @@ -30,6 +30,18 @@ fun Project.configureRemoteRepos() { } } } + tasks.register("ensureMavenCentralAvailable") { + doLast { + if (GpgSigner.signer == GpgSigner.NoopSigner) { + error("GPG Signer isn't available.") + } + val keys = SecretKeys.getCache(project) + if (!keys.loadKey("sonatype").isValid) { + error("Maven Central isn't available.") + } + } + } + publishing { // sonatype val keys = SecretKeys.getCache(project) diff --git a/buildSrc/src/main/kotlin/keys/SecretKeys.kt b/buildSrc/src/main/kotlin/keys/SecretKeys.kt index 6338cffec..e849e5f99 100644 --- a/buildSrc/src/main/kotlin/keys/SecretKeys.kt +++ b/buildSrc/src/main/kotlin/keys/SecretKeys.kt @@ -10,6 +10,7 @@ package keys import org.gradle.api.Project +import java.io.BufferedReader open class SecretKeys( val type: String, @@ -66,7 +67,15 @@ open class SecretKeys( ?: secretKeys.resolve("$type.key.txt") if (secretKeyFile.isFile) { secretKeyFile.bufferedReader().use { - return SecretKeys(type, it.readLine().trim(), it.readLine().trim()) + fun BufferedReader.readLineNonEmpty(): String { + while (true) { + val nextLine = readLine() ?: return "" + if (nextLine.isNotBlank()) { + return nextLine.trim() + } + } + } + return SecretKeys(type, it.readLineNonEmpty(), it.readLineNonEmpty()) } } } From 059d6a2ee533ed0e1a37505a6989681fee244ff8 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sat, 6 Feb 2021 16:31:59 +0800 Subject: [PATCH 08/12] 2.4.0-dev-publish-1 --- .github/workflows/release.yml | 13 +++++++------ buildSrc/src/main/kotlin/Versions.kt | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 933e45141..fc38193ce 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -112,9 +112,10 @@ jobs: ./gradlew :mirai-console-compiler-annotations:publish --info - - name: Publish Gradle plugin - run: > - ./gradlew - :mirai-console-gradle:publishPlugins --info --stacktrace - -Dgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} -Pgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} - -Dgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} -Pgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} +# TEMP DISABLE +# - name: Publish Gradle plugin +# run: > +# ./gradlew +# :mirai-console-gradle:publishPlugins --info --stacktrace +# -Dgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} -Pgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} +# -Dgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} -Pgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index bf7c012ec..59628803c 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -12,7 +12,7 @@ import org.gradle.api.attributes.Attribute object Versions { - const val project = "2.4.0-dev-1" + const val project = "2.4.0-dev-publish-1" const val core = project const val console = project From 9d8781d27cc7f1a1682b458d6e3de76afe2a0813 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sat, 6 Feb 2021 16:38:43 +0800 Subject: [PATCH 09/12] Init keys before project init --- .github/workflows/release.yml | 6 +++--- buildSrc/src/main/kotlin/Versions.kt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fc38193ce..65cc26e44 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -31,9 +31,6 @@ jobs: - name: chmod -R 777 * run: chmod -R 777 * - - name: Init gradle project - run: ./gradlew clean --info - - name: Keys setup shell: bash run: | @@ -53,6 +50,9 @@ jobs: BINTRAY_USER: ${{ secrets.BINTRAY_USER }} BINTRAY_KEY: ${{ secrets.BINTRAY_KEY }} + - name: Init gradle project + run: ./gradlew clean --info + - name: Check keys run: > ./gradlew diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 59628803c..17bfbc4db 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -12,7 +12,7 @@ import org.gradle.api.attributes.Attribute object Versions { - const val project = "2.4.0-dev-publish-1" + const val project = "2.4.0-dev-publish-2" const val core = project const val console = project From fb2632073bfd9d58a84790f98d8557e6c795ded3 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sat, 6 Feb 2021 22:28:09 +0800 Subject: [PATCH 10/12] Auto release to maven central --- .github/workflows/release.yml | 5 +++++ build.gradle.kts | 6 +++--- ci-release-helper/build.gradle.kts | 22 ++++++++++++++++++++++ gradle.properties | 6 ++++-- settings.gradle.kts | 1 + 5 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 ci-release-helper/build.gradle.kts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 65cc26e44..295aba77b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -119,3 +119,8 @@ jobs: # :mirai-console-gradle:publishPlugins --info --stacktrace # -Dgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} -Pgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} # -Dgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} -Pgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} + + - name: Gradle :ci-release-helper:closeAndReleaseRepository + run: > + ./gradlew + :ci-release-helper:closeAndReleaseRepository --info diff --git a/build.gradle.kts b/build.gradle.kts index b3f335cc8..ce6a72482 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -139,9 +139,9 @@ subprojects { tasks.register("cleanExceptIntellij") { group = "build" - allprojects.forEach { - if (it.name != "mirai-console-intellij") - dependsOn(it.tasks.findByName("clean")) + allprojects.forEach { proj -> + if (proj.name != "mirai-console-intellij") + proj.tasks.findByName("clean")?.let { dependsOn(it) } } } diff --git a/ci-release-helper/build.gradle.kts b/ci-release-helper/build.gradle.kts new file mode 100644 index 000000000..3a04e0834 --- /dev/null +++ b/ci-release-helper/build.gradle.kts @@ -0,0 +1,22 @@ +/* + * Copyright 2019-2021 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ +import keys.SecretKeys + +plugins { + id("io.codearte.nexus-staging") version "0.22.0" +} + +description = "Mirai CI Methods for Releasing" + +nexusStaging { + packageGroup = rootProject.group.toString() + val keys = SecretKeys.getCache(project).loadKey("sonatype") + username = keys.user + password = keys.password +} diff --git a/gradle.properties b/gradle.properties index 46f7e3f1c..122691870 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,12 @@ # -# Copyright 2019-2020 Mamoe Technologies and contributors. +# Copyright 2019-2021 Mamoe Technologies and contributors. # # 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. # Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. # # https://github.com/mamoe/mirai/blob/master/LICENSE # + # style guide kotlin.code.style=official # config @@ -17,4 +18,5 @@ org.gradle.vfs.watch=true kotlin.mpp.enableGranularSourceSetsMetadata=true kotlin.native.enableDependencyPropagation=false #kotlin.mpp.enableGranularSourceSetsMetadata=true -systemProp.org.gradle.internal.publish.checksums.insecure=true \ No newline at end of file +systemProp.org.gradle.internal.publish.checksums.insecure=true +gnsp.disableApplyOnlyOnRootProjectEnforcement=true diff --git a/settings.gradle.kts b/settings.gradle.kts index cb6728cbf..4f6140571 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -29,6 +29,7 @@ include(":mirai-core") include(":mirai-core-all") include(":binary-compatibility-validator") +include(":ci-release-helper") fun includeConsoleProjects() { From a0666635d5e6b022972cef5294fca2ec6dc1aa22 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sun, 7 Feb 2021 15:28:29 +0800 Subject: [PATCH 11/12] Keep JCenter package; Re-enable gradle plugin publish --- .github/workflows/release.yml | 13 ++++++------- buildSrc/src/main/kotlin/JvmPublishing.kt | 10 +++++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 295aba77b..9b824d58a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -112,13 +112,12 @@ jobs: ./gradlew :mirai-console-compiler-annotations:publish --info -# TEMP DISABLE -# - name: Publish Gradle plugin -# run: > -# ./gradlew -# :mirai-console-gradle:publishPlugins --info --stacktrace -# -Dgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} -Pgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} -# -Dgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} -Pgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} + - name: Publish Gradle plugin + run: > + ./gradlew + :mirai-console-gradle:publishPlugins --info --stacktrace + -Dgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} -Pgradle.publish.key=${{ secrets.GRADLE_PUBLISH_KEY }} + -Dgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} -Pgradle.publish.secret=${{ secrets.GRADLE_PUBLISH_SECRET }} - name: Gradle :ci-release-helper:closeAndReleaseRepository run: > diff --git a/buildSrc/src/main/kotlin/JvmPublishing.kt b/buildSrc/src/main/kotlin/JvmPublishing.kt index 3a996f364..a7216d82a 100644 --- a/buildSrc/src/main/kotlin/JvmPublishing.kt +++ b/buildSrc/src/main/kotlin/JvmPublishing.kt @@ -22,7 +22,9 @@ import org.gradle.kotlin.dsl.get import org.gradle.kotlin.dsl.register import org.gradle.kotlin.dsl.registering -fun Project.configureRemoteRepos() { +fun Project.configureRemoteRepos( + bintrayPkgName: String = "mirai-core" +) { tasks.register("ensureBintrayAvailable") { doLast { if (!project.isBintrayAvailable()) { @@ -64,7 +66,7 @@ fun Project.configureRemoteRepos() { if (isBintrayAvailable()) { maven { - setUrl("https://api.bintray.com/maven/him188moe/mirai/mirai-core/;publish=1;override=1") + setUrl("https://api.bintray.com/maven/him188moe/mirai/$bintrayPkgName/;publish=1;override=1") credentials { username = Bintray.getUser(project) @@ -86,7 +88,9 @@ inline fun Project.configurePublishing( bintrayPkgName: String = artifactId, vcs: String = "https://github.com/mamoe/mirai" ) { - configureRemoteRepos() + configureRemoteRepos( + bintrayPkgName = bintrayPkgName + ) apply() if (project.isBintrayAvailable()) { From b3e9e2a91b181ed4cf73c8b6ca2142257c459d7c Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Wed, 10 Feb 2021 10:06:41 +0800 Subject: [PATCH 12/12] Remote repositories name --- buildSrc/src/main/kotlin/JvmPublishing.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/buildSrc/src/main/kotlin/JvmPublishing.kt b/buildSrc/src/main/kotlin/JvmPublishing.kt index a7216d82a..ee95e2eea 100644 --- a/buildSrc/src/main/kotlin/JvmPublishing.kt +++ b/buildSrc/src/main/kotlin/JvmPublishing.kt @@ -51,6 +51,7 @@ fun Project.configureRemoteRepos( val sonatype = keys.loadKey("sonatype") if (sonatype.isValid) { maven { + name = "MavenCentral" // Maven Central setUrl("https://oss.sonatype.org/service/local/staging/deploy/maven2") @@ -66,6 +67,7 @@ fun Project.configureRemoteRepos( if (isBintrayAvailable()) { maven { + name = "Bintray" setUrl("https://api.bintray.com/maven/him188moe/mirai/$bintrayPkgName/;publish=1;override=1") credentials {