2
0
Эх сурвалжийг харах

Add bintray publisher workflow

Him188 5 жил өмнө
parent
commit
40c22f42e5

+ 48 - 0
.github/workflows/bintray.yml

@@ -0,0 +1,48 @@
+# 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
+
+# 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"
+  build:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+      - name: Set up JDK 1.8
+        uses: actions/setup-java@v1
+        with:
+          java-version: 1.8
+      - name: Grant execute permission for gradlew
+        run: chmod +x gradlew
+      - name: Gradle clean
+        run: ./gradlew clean
+      - name: Gradle build
+        run: ./gradlew build # if test's failed, don't publish
+      - name: Gradle :mirai-core:bintrayUpload
+        run: ./gradlew :mirai-core:bintrayUpload -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }}
+      - name: Gradle :mirai-core-qqandroid:bintrayUpload
+        run: ./gradlew :mirai-core-qqandroid:bintrayUpload -Dbintray_user=${{ secrets.BINTRAY_USER }} -Pbintray_user=${{ secrets.BINTRAY_USER }} -Dbintray_key=${{ secrets.BINTRAY_KEY }} -Pbintray_key=${{ secrets.BINTRAY_KEY }}
+
+
+#      - name: Upload artifact
+#        uses: actions/upload-artifact@v1.0.0
+#        with:
+#          # Artifact name
+#          name: mirai-core
+#          # Directory containing files to upload
+#          path: "mirai-core/build/libs/mirai-core-*-all.jar"
+#      - name: Upload artifact
+#        uses: actions/upload-artifact@v1.0.0
+#        with:
+#          # Artifact name
+#          name: mirai-core-qqandroid-all
+#          # Directory containing files to upload
+#          path: "mirai-core-qqandroid/build/libs/mirai-core-qqandroid-*-all.jar"

+ 3 - 1
.gitignore

@@ -43,4 +43,6 @@ local.properties
 keys.properties
 /plugins/
 
-token.txt
+token.txt
+bintray.user.txt
+bintray.key.txt

+ 79 - 0
buildSrc/src/main/kotlin/upload/Bintray.kt

@@ -0,0 +1,79 @@
+package upload
+
+import org.gradle.api.Project
+import org.gradle.kotlin.dsl.provideDelegate
+import java.io.File
+
+/*
+ * 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
+ */
+object Bintray {
+
+    @JvmStatic
+    fun getUser(project: Project): String {
+        kotlin.runCatching {
+            @Suppress("UNUSED_VARIABLE", "LocalVariableName")
+            val bintray_user: String by project
+            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'"
+        )
+    }
+
+    @JvmStatic
+    fun getKey(project: Project): String {
+        kotlin.runCatching {
+            @Suppress("UNUSED_VARIABLE", "LocalVariableName")
+            val bintray_key: String by project
+            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'"
+        )
+    }
+
+}

+ 0 - 104
gradle/publish-japt.gradle

@@ -1,104 +0,0 @@
-// 部分源码来自 kotlinx.coroutines
-
-def pomConfig = {
-    licenses {
-        license {
-            name "AGPL-V3"
-            url "https://www.gnu.org/licenses/agpl-3.0.txt"
-            distribution "repo"
-        }
-    }
-    developers {
-        developer {
-            id "mamoe"
-            name "Mamoe Technologies"
-        }
-    }
-    scm {
-        url "https://github.com/mamoe/mirai"
-    }
-}
-
-bintray {
-    def keyProps = new Properties()
-    def keyFile = file("../keys.properties")
-    if (keyFile.exists()) keyFile.withInputStream { keyProps.load(it) }
-
-    user = keyProps.getProperty("bintrayUser")
-    key = keyProps.getProperty("bintrayKey")
-
-    pkg {
-        repo = 'mirai'
-        name = "mirai-japt"
-        licenses = ['AGPL']
-        vcsUrl = 'https://github.com/mamoe/mirai'
-    }
-}
-
-afterEvaluate {
-    project.publishing.publications.forEach { publication ->
-        publication.pom.withXml {
-            def root = asNode()
-            //root.appendNode('groupId', project.group)
-            //root.appendNode('artifactId', project.name)
-            //root.appendNode('version', project.version)
-            root.appendNode('name', project.name)
-            root.appendNode('description', project.description)
-            root.appendNode('url', 'https://github.com/mamoe/mirai')
-            root.children().last() + pomConfig
-        }
-    }
-}
-
-bintrayUpload.doFirst {
-    publications = project.publishing.publications
-}
-
-bintrayUpload.dependsOn {
-    def list = new LinkedList<Task>()
-    list.add(tasks.getByName("build"))
-
-    list.addAll(tasks.findAll { task -> task.name.contains('Jar') })
-    list.addAll(tasks.findAll { task -> task.name.startsWith('generateMetadataFileFor') })
-    list.addAll(tasks.findAll { task -> task.name.startsWith('generatePomFileFor') })
-
-    list
-}
-
-
-// empty xxx-javadoc.jar
-task javadocJar(type: Jar) {
-    archiveClassifier = 'javadoc'
-}
-
-publishing {
-    publications.all {
-        // add empty javadocs (no need for MPP root publication which publishes only pom file)
-        if (it.name != 'kotlinMultiplatform') {
-            it.artifact(javadocJar)
-        }
-
-        // Rename MPP artifacts for backward compatibility
-        def type = it.name
-        switch (type) {
-            case 'kotlinMultiplatform':
-                it.artifactId = "$project.name"
-                break
-            case 'metadata':
-                it.artifactId = "$project.name-common"
-                break
-            case 'jvm':
-                it.artifactId = "$project.name"
-                break
-            case 'js':
-            case 'native':
-                it.artifactId = "$project.name-$type"
-                break
-        }
-
-        // disable metadata everywhere, but in native modules
-        if (type == 'maven' || type == 'metadata' || type == 'jvm' || type == 'js') {
-            moduleDescriptorGenerator = null
-        }
-    }
-}

+ 6 - 8
gradle/publish.gradle

@@ -1,3 +1,5 @@
+import upload.Bintray
+
 // 部分源码来自 kotlinx.coroutines
 // Source code from kotlinx.coroutines
 
@@ -22,12 +24,8 @@ def pomConfig = {
 }
 
 bintray {
-    def keyProps = new Properties()
-    def keyFile = file("../keys.properties")
-    if (keyFile.exists()) keyFile.withInputStream { keyProps.load(it) }
-
-    user = keyProps.getProperty("bintrayUser")
-    key = keyProps.getProperty("bintrayKey")
+    user = Bintray.getUser(project)
+    key = Bintray.getKey(project)
 
     pkg {
         repo = 'mirai'
@@ -67,14 +65,14 @@ bintrayUpload.dependsOn {
     list
 }
 
-try{
+try {
 
 // empty xxx-javadoc.jar
     task javadocJar(type: Jar) {
         archiveClassifier = 'javadoc'
     }
 
-} catch (Exception e){
+} catch (Exception ignored) {
 
 }
 publishing {