Sfoglia il codice sorgente

Snapshot publishing

Karlatemp 4 anni fa
parent
commit
b2974ea921

+ 22 - 1
.github/workflows/build.yml

@@ -47,6 +47,14 @@ jobs:
       - name: chmod -R 777 *
         run: chmod -R 777 *
 
+      - name: Pre-Setup snapshot publish
+        if: "${{ github.event.ref == 'refs/heads/kar/snapshot' }}"
+        run: sh ci-release-helper/setup-shapshot.sh
+        env:
+          SNAPSHOTS_PUBLISHING_USER: ${{ secrets.SNAPSHOTS_PUBLISHING_USER }}
+          SNAPSHOTS_PUBLISHING_KEY: ${{ secrets.SNAPSHOTS_PUBLISHING_KEY }}
+          SNAPSHOTS_PUBLISHING_URL: ${{ secrets.SNAPSHOTS_PUBLISHING_URL }}
+
       - name: Init gradle project
         run: ./gradlew clean --scan
 
@@ -58,4 +66,17 @@ jobs:
           ./gradlew check --scan
           -Dmirai.network.show.all.components=true
           -Dkotlinx.coroutines.debug=on
-          -Dmirai.network.show.packet.details=true
+          -Dmirai.network.show.packet.details=true
+
+      - name: Run snapshot publish
+        if: "${{ github.event.ref == 'refs/heads/kar/snapshot' }}"
+        run: >
+          ./gradlew
+          :mirai-core-utils:publishAllPublicationsToSnapshotRepoRepository
+          :mirai-core-api:publishAllPublicationsToSnapshotRepoRepository
+          :mirai-core-core:publishAllPublicationsToSnapshotRepoRepository
+          :mirai-console:publishAllPublicationsToSnapshotRepoRepository
+          :mirai-console-terminal:publishAllPublicationsToSnapshotRepoRepository
+          :mirai-console-compiler-common:publishAllPublicationsToSnapshotRepoRepository
+          :mirai-console-compiler-annotations:publishAllPublicationsToSnapshotRepoRepository
+          --info --scan

+ 10 - 0
build.gradle.kts

@@ -74,6 +74,16 @@ analyzes.CompiledCodeVerify.run { registerAllVerifyTasks() }
 allprojects {
     group = "net.mamoe"
     version = Versions.project
+    val currentProj = this@allprojects
+    if (currentProj != rootProject) {
+        val rfm = currentProj.projectDir.relativeTo(rootProject.projectDir)
+        if (rfm.path.contains("mirai-core")) {
+            version = Versions.core
+        }
+        if (rfm.path.contains("mirai-console")) {
+            version = Versions.console
+        }
+    }
 
     repositories {
         // mavenLocal() // cheching issue cause compiler exception

+ 3 - 0
buildSrc/src/main/kotlin/GpgSigner.kt

@@ -42,6 +42,9 @@ open class GpgSigner(private val workdir: File) {
         private var initialized: Boolean = false
         var signer: GpgSigner = NoopSigner
         fun setup(project: Project) {
+            if (PublishSettings.isSnapshot) {
+                return
+            }
             if (initialized) return
             initialized = true
             val rootProject = project.rootProject

+ 25 - 2
buildSrc/src/main/kotlin/JvmPublishing.kt

@@ -21,10 +21,14 @@ import org.gradle.kotlin.dsl.apply
 import org.gradle.kotlin.dsl.get
 import org.gradle.kotlin.dsl.register
 import org.gradle.kotlin.dsl.registering
+import java.util.*
 
 fun Project.configureRemoteRepos() {
     tasks.register("ensureMavenCentralAvailable") {
         doLast {
+            if (PublishSettings.isSnapshot) {
+                return@doLast
+            }
             if (GpgSigner.signer == GpgSigner.NoopSigner) {
                 error("GPG Signer isn't available.")
             }
@@ -54,6 +58,23 @@ fun Project.configureRemoteRepos() {
             } else {
                 println("SonaType is not available")
             }
+            if (PublishSettings.isSnapshot) {
+                maven {
+                    name = "SnapshotRepo"
+                    isAllowInsecureProtocol = true
+                    setUrl(
+                        String(
+                            Base64.getDecoder().decode(
+                                PublishSettings["snapshot.remote"]
+                            )
+                        )
+                    )
+                    credentials {
+                        username = PublishSettings["snapshot.user"]
+                        password = PublishSettings["snapshot.key"]
+                    }
+                }
+            }
         }
     }
 }
@@ -89,8 +110,10 @@ inline fun Project.configurePublishing(
                     vcs = vcs
                 )
 
-                artifact(sourcesJar.get())
-                artifact(stubJavadoc.get())
+                if (!PublishSettings.isSnapshot) {
+                    artifact(sourcesJar.get())
+                    artifact(stubJavadoc.get())
+                }
             }
         }
         configGpgSign(this@configurePublishing)

+ 32 - 0
buildSrc/src/main/kotlin/PublishSettings.kt

@@ -0,0 +1,32 @@
+import java.util.*
+
+/*
+ * 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/dev/LICENSE
+ */
+
+object PublishSettings {
+    val projKeySettings = findProjectDir().resolve("keys.properties").let { store ->
+        println("SST: $store")
+        val prop = Properties()
+        kotlin.runCatching {
+            if (store.isFile) {
+                store.bufferedReader().use { prop.load(it) }
+            }
+        }.onFailure { it.printStackTrace(System.out) }
+        prop
+    }
+
+    val isSnapshot = projKeySettings.getProperty("isSnapshot")?.toBoolean() ?: false
+
+    operator fun get(key: String): String = projKeySettings.getProperty(key) ?: error("No property $key")
+    operator fun get(key: String, def: String): String = projKeySettings.getProperty(key, def) ?: def
+
+    fun getIfSnapshot(key: String): String? = if (isSnapshot) {
+        projKeySettings.getProperty(key)
+    } else null
+}

+ 3 - 0
buildSrc/src/main/kotlin/PublishingGpgSign.kt

@@ -53,6 +53,9 @@ object PublishingAccess {
 }
 
 fun PublishingExtension.configGpgSign(project: Project) {
+    if (PublishSettings.isSnapshot) {
+        return
+    }
     if (GpgSigner.signer === GpgSigner.NoopSigner) {
         return
     }

+ 6 - 6
buildSrc/src/main/kotlin/Versions.kt

@@ -14,9 +14,9 @@ import org.gradle.api.attributes.Attribute
 object Versions {
     const val project = "2.7-M2"
 
-    const val core = project
-    const val console = project
-    const val consoleTerminal = project
+    val core = PublishSettings.getIfSnapshot("version.mirai.core") ?: project
+    val console = PublishSettings.getIfSnapshot("version.mirai.console") ?: project
+    val consoleTerminal: String = console
 
     const val kotlinCompiler = "1.5.10"
     const val kotlinStdlib = "1.5.10"
@@ -101,9 +101,9 @@ const val `kotlin-test` = "org.jetbrains.kotlin:kotlin-test:${Versions.kotlinStd
 const val `kotlin-test-junit5` = "org.jetbrains.kotlin:kotlin-test-junit5:${Versions.kotlinStdlib}"
 
 
-const val `mirai-core-api` = "net.mamoe:mirai-core-api:${Versions.core}"
-const val `mirai-core` = "net.mamoe:mirai-core:${Versions.core}"
-const val `mirai-core-utils` = "net.mamoe:mirai-core-utils:${Versions.core}"
+val `mirai-core-api` = "net.mamoe:mirai-core-api:${Versions.core}"
+val `mirai-core` = "net.mamoe:mirai-core:${Versions.core}"
+val `mirai-core-utils` = "net.mamoe:mirai-core-utils:${Versions.core}"
 
 const val yamlkt = "net.mamoe.yamlkt:yamlkt:${Versions.yamlkt}"
 

+ 11 - 0
buildSrc/src/main/kotlin/utils.kt

@@ -7,6 +7,7 @@
  * https://github.com/mamoe/mirai/blob/dev/LICENSE
  */
 
+import java.io.File
 import java.io.InputStream
 import java.io.OutputStream
 import java.security.MessageDigest
@@ -60,3 +61,13 @@ fun InputStream.md5(): ByteArray {
     }
     return digest.digest()
 }
+
+fun findProjectDir(): File {
+    val current = File(".").absoluteFile
+    fun tryFind(file: File): File? {
+        if (file.resolve("mirai-core").isDirectory) return file
+        file.parentFile?.let { return tryFind(it) }
+        return null
+    }
+    return tryFind(current) ?: current
+}

+ 26 - 0
ci-release-helper/setup-shapshot.sh

@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+
+#
+# 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/dev/LICENSE
+#
+
+echo "isSnapshot=true" > keys.properties
+
+echo "snapshot.user=$SNAPSHOTS_PUBLISHING_USER" >> keys.properties
+echo "snapshot.key=$SNAPSHOTS_PUBLISHING_KEY"   >> keys.properties
+echo "snapshot.url=$SNAPSHOTS_PUBLISHING_URL"   >> keys.properties
+echo "snapshot.remote=$( echo "$SNAPSHOTS_PUBLISHING_URL" | base64 )"
+
+tmp=$(git rev-parse HEAD)
+
+echo "version.mirai.core=$tmp" >> keys.properties
+
+cd mirai-console || exit
+tmp=$(git rev-parse HEAD)
+cd ..
+echo "version.mirai.console=$tmp" >> keys.properties