mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-28 01:10:17 +08:00
Setup bintray publishing wokrflow
This commit is contained in:
parent
e713247fb3
commit
dd55f9d0bd
48
.github/workflows/bintray.yml
vendored
Normal file
48
.github/workflows/bintray.yml
vendored
Normal file
@ -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: Check keys
|
||||
run: ./gradlew :mirai-console:ensureBintrayAvailable -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 -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
.gitignore
vendored
3
.gitignore
vendored
@ -41,3 +41,6 @@ local.properties
|
||||
# Maven publishing credits
|
||||
keys.properties
|
||||
/plugins/
|
||||
|
||||
bintray.user.txt
|
||||
bintray.key.txt
|
@ -112,17 +112,20 @@ subprojects {
|
||||
}
|
||||
|
||||
|
||||
fun Project.findLatestFile(): Map.Entry<String, File>? {
|
||||
fun Project.findLatestFile(): Map.Entry<String, File> {
|
||||
return File(projectDir, "build/libs").walk()
|
||||
.filter { it.isFile }
|
||||
.onEach { println("all files=$it") }
|
||||
.filter { it.name.matches(Regex("""${project.name}-([0-9]|\.)*\.jar""")) }
|
||||
.filter { it.name.matches(Regex("""${project.name}-[0-9][0-9]*(\.[0-9]*)*.*\.jar""")) }
|
||||
.onEach { println("matched file: ${it.name}") }
|
||||
.associateBy { it.nameWithoutExtension.substringAfterLast('-') }
|
||||
.onEach { println("versions: $it") }
|
||||
.maxBy {
|
||||
it.key.split('.').foldRightIndexed(0) { index: Int, s: String, acc: Int ->
|
||||
acc + 100.0.pow(2 - index).toInt() * (s.toIntOrNull() ?: 0)
|
||||
.maxBy { (version, file) ->
|
||||
version.split('.').let {
|
||||
if (it.size == 2) it + "0"
|
||||
else it
|
||||
}.reversed().foldIndexed(0) { index: Int, acc: Int, s: String ->
|
||||
acc + 100.0.pow(index).toInt() * (s.toIntOrNull() ?: 0)
|
||||
}
|
||||
}
|
||||
} ?: error("cannot find any file to upload")
|
||||
}
|
||||
|
102
buildSrc/src/main/kotlin/upload/Bintray.kt
Normal file
102
buildSrc/src/main/kotlin/upload/Bintray.kt
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@file:Suppress("DuplicatedCode")
|
||||
|
||||
package upload
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.provideDelegate
|
||||
import java.io.File
|
||||
|
||||
object Bintray {
|
||||
|
||||
@JvmStatic
|
||||
fun isBintrayAvailable(project: Project): Boolean {
|
||||
return kotlin.runCatching {
|
||||
getUser(project)
|
||||
getKey(project)
|
||||
}.isSuccess
|
||||
}
|
||||
|
||||
@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'"
|
||||
)
|
||||
}
|
||||
|
||||
@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'"
|
||||
)
|
||||
}
|
||||
|
||||
}
|
@ -15,12 +15,16 @@ import io.ktor.client.request.post
|
||||
import io.ktor.client.statement.HttpResponse
|
||||
import io.ktor.http.isSuccess
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.provideDelegate
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.InvocationKind
|
||||
import kotlin.contracts.contract
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
object CuiCloud {
|
||||
@ -77,13 +81,26 @@ object CuiCloud {
|
||||
val cuiCloudUrl = getUrl(project)
|
||||
val key = getKey(project)
|
||||
|
||||
|
||||
val bytes = file.readBytes()
|
||||
|
||||
runBlocking {
|
||||
uploadToCuiCloud(
|
||||
cuiCloudUrl,
|
||||
key,
|
||||
"/mirai/${project.name}/${file.nameWithoutExtension}.mp4",
|
||||
file.readBytes()
|
||||
)
|
||||
var first = true
|
||||
retryCatching(1000) {
|
||||
if (!first) {
|
||||
println()
|
||||
println()
|
||||
println("Upload failed. Waiting 15s")
|
||||
delay(15_000)
|
||||
}
|
||||
first = false
|
||||
uploadToCuiCloud(
|
||||
cuiCloudUrl,
|
||||
key,
|
||||
"/mirai/${project.name}/${file.nameWithoutExtension}.mp4",
|
||||
bytes
|
||||
)
|
||||
}.getOrThrow()
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,6 +146,30 @@ object CuiCloud {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "RESULT_CLASS_IN_RETURN_TYPE")
|
||||
@kotlin.internal.InlineOnly
|
||||
internal inline fun <R> retryCatching(n: Int, block: () -> R): Result<R> {
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.AT_LEAST_ONCE)
|
||||
}
|
||||
require(n >= 0) { "param n for retryCatching must not be negative" }
|
||||
var exception: Throwable? = null
|
||||
repeat(n) {
|
||||
try {
|
||||
return Result.success(block())
|
||||
} catch (e: Throwable) {
|
||||
try {
|
||||
exception?.addSuppressed(e)
|
||||
} catch (e: Throwable) {
|
||||
}
|
||||
exception = e
|
||||
}
|
||||
}
|
||||
return Result.failure(exception!!)
|
||||
}
|
||||
|
||||
inline fun <E> buildList(builderAction: MutableList<E>.() -> Unit): List<E> {
|
||||
return ArrayList<E>().apply(builderAction)
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ object Versions {
|
||||
}
|
||||
|
||||
object Kotlin {
|
||||
const val stdlib = "1.3.71"
|
||||
const val stdlib = "1.3.72"
|
||||
const val coroutines = "1.3.5"
|
||||
const val serialization = "0.20.0"
|
||||
const val ktor = "1.3.2"
|
||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
||||
#Wed Mar 04 22:27:09 CST 2020
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStorePath=wrapper/dists
|
||||
|
@ -1,5 +1,3 @@
|
||||
import java.util.*
|
||||
|
||||
plugins {
|
||||
id("kotlinx-serialization")
|
||||
id("org.openjfx.javafxplugin") version "0.0.8"
|
||||
@ -28,26 +26,7 @@ tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>() {
|
||||
|
||||
version = Versions.Mirai.consoleGraphical
|
||||
|
||||
description = "Console Graphical Version with plugin support for mirai"
|
||||
bintray {
|
||||
val keyProps = Properties()
|
||||
val keyFile = file("../keys.properties")
|
||||
if (keyFile.exists()) keyFile.inputStream().use { keyProps.load(it) }
|
||||
if (keyFile.exists()) keyFile.inputStream().use { keyProps.load(it) }
|
||||
|
||||
user = keyProps.getProperty("bintrayUser")
|
||||
key = keyProps.getProperty("bintrayKey")
|
||||
setPublications("mavenJava")
|
||||
setConfigurations("archives")
|
||||
|
||||
pkg.apply {
|
||||
repo = "mirai"
|
||||
name = "mirai-console-graphical"
|
||||
setLicenses("AGPLv3")
|
||||
publicDownloadNumbers = true
|
||||
vcsUrl = "https://github.com/mamoe/mirai"
|
||||
}
|
||||
}
|
||||
description = "Graphical frontend for mirai-console"
|
||||
|
||||
dependencies {
|
||||
compileOnly("net.mamoe:mirai-core:${Versions.Mirai.core}")
|
||||
@ -71,34 +50,4 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
|
||||
val sourcesJar by tasks.registering(Jar::class) {
|
||||
classifier = "sources"
|
||||
from(sourceSets.main.get().allSource)
|
||||
}
|
||||
|
||||
|
||||
publishing {
|
||||
/*
|
||||
repositories {
|
||||
maven {
|
||||
// change to point to your repo, e.g. http://my.org/repo
|
||||
url = uri("$buildDir/repo")
|
||||
}
|
||||
}*/
|
||||
publications {
|
||||
register("mavenJava", MavenPublication::class) {
|
||||
from(components["java"])
|
||||
|
||||
groupId = rootProject.group.toString()
|
||||
artifactId = "mirai-console-graphical"
|
||||
version = Versions.Mirai.consoleGraphical
|
||||
|
||||
pom.withXml {
|
||||
val root = asNode()
|
||||
root.appendNode("description", description)
|
||||
root.appendNode("name", project.name)
|
||||
root.appendNode("url", "https://github.com/mamoe/mirai")
|
||||
root.children().last()
|
||||
}
|
||||
|
||||
artifact(sourcesJar.get())
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import upload.Bintray
|
||||
import java.util.*
|
||||
|
||||
plugins {
|
||||
@ -36,65 +37,8 @@ dependencies {
|
||||
|
||||
version = Versions.Mirai.console
|
||||
|
||||
description = "Console with plugin support for mirai"
|
||||
bintray {
|
||||
val keyProps = Properties()
|
||||
val keyFile = file("../keys.properties")
|
||||
if (keyFile.exists()) keyFile.inputStream().use { keyProps.load(it) }
|
||||
if (keyFile.exists()) keyFile.inputStream().use { keyProps.load(it) }
|
||||
description = "Console backend for mirai"
|
||||
|
||||
user = keyProps.getProperty("bintrayUser")
|
||||
key = keyProps.getProperty("bintrayKey")
|
||||
setPublications("mavenJava")
|
||||
setConfigurations("archives")
|
||||
|
||||
pkg.apply {
|
||||
repo = "mirai"
|
||||
name = "mirai-console"
|
||||
setLicenses("AGPLv3")
|
||||
publicDownloadNumbers = true
|
||||
vcsUrl = "https://github.com/mamoe/mirai"
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
val sourcesJar by tasks.registering(Jar::class) {
|
||||
classifier = "sources"
|
||||
from(sourceSets.main.get().allSource)
|
||||
}
|
||||
|
||||
publishing {
|
||||
/*
|
||||
repositories {
|
||||
maven {
|
||||
// change to point to your repo, e.g. http://my.org/repo
|
||||
url = uri("$buildDir/repo")
|
||||
}
|
||||
}*/
|
||||
publications {
|
||||
register("mavenJava", MavenPublication::class) {
|
||||
from(components["java"])
|
||||
|
||||
groupId = rootProject.group.toString()
|
||||
artifactId = "mirai-console"
|
||||
version = version
|
||||
|
||||
pom.withXml {
|
||||
val root = asNode()
|
||||
root.appendNode("description", description)
|
||||
root.appendNode("name", project.name)
|
||||
root.appendNode("url", "https://github.com/mamoe/mirai")
|
||||
root.children().last()
|
||||
}
|
||||
|
||||
artifact(sourcesJar.get())
|
||||
}
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
maven("https://dl.bintray.com/kotlin/kotlin-eap")
|
||||
mavenCentral()
|
||||
}
|
||||
val compileKotlin: KotlinCompile by tasks
|
||||
compileKotlin.kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
@ -110,3 +54,70 @@ java {
|
||||
tasks.withType(JavaCompile::class.java) {
|
||||
options.encoding = "UTF8"
|
||||
}
|
||||
|
||||
|
||||
|
||||
tasks.register("ensureBintrayAvailable") {
|
||||
doLast {
|
||||
if (!Bintray.isBintrayAvailable(project)) {
|
||||
error("bintray isn't available. ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Bintray.isBintrayAvailable(project)) {
|
||||
bintray {
|
||||
val keyProps = Properties()
|
||||
val keyFile = file("../keys.properties")
|
||||
if (keyFile.exists()) keyFile.inputStream().use { keyProps.load(it) }
|
||||
if (keyFile.exists()) keyFile.inputStream().use { keyProps.load(it) }
|
||||
|
||||
user = Bintray.getUser(project)
|
||||
key = Bintray.getKey(project)
|
||||
setPublications("mavenJava")
|
||||
setConfigurations("archives")
|
||||
|
||||
pkg.apply {
|
||||
repo = "mirai"
|
||||
name = "mirai-console"
|
||||
setLicenses("AGPLv3")
|
||||
publicDownloadNumbers = true
|
||||
vcsUrl = "https://github.com/mamoe/mirai-console"
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
val sourcesJar by tasks.registering(Jar::class) {
|
||||
classifier = "sources"
|
||||
from(sourceSets.main.get().allSource)
|
||||
}
|
||||
|
||||
publishing {
|
||||
/*
|
||||
repositories {
|
||||
maven {
|
||||
// change to point to your repo, e.g. http://my.org/repo
|
||||
url = uri("$buildDir/repo")
|
||||
}
|
||||
}*/
|
||||
publications {
|
||||
register("mavenJava", MavenPublication::class) {
|
||||
from(components["java"])
|
||||
|
||||
groupId = rootProject.group.toString()
|
||||
artifactId = "mirai-console"
|
||||
version = version
|
||||
|
||||
pom.withXml {
|
||||
val root = asNode()
|
||||
root.appendNode("description", description)
|
||||
root.appendNode("name", project.name)
|
||||
root.appendNode("url", "https://github.com/mamoe/mirai")
|
||||
root.children().last()
|
||||
}
|
||||
|
||||
artifact(sourcesJar.get())
|
||||
}
|
||||
}
|
||||
}
|
||||
} else println("bintray isn't available. NO PUBLICATIONS WILL BE SET")
|
Loading…
Reference in New Issue
Block a user