Commit 8325b7d4 authored by Him188's avatar Him188

Update workflow

parent e3baedff
# This is a basic workflow to help you get started with Actions # This is a basic workflow to help you get started with Actions
name: Shadow name: Shadow Publish
# Controls when the action will run. Triggers the workflow on push or pull request # Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch # events but only for the master branch
...@@ -22,19 +22,27 @@ jobs: ...@@ -22,19 +22,27 @@ jobs:
java-version: 1.8 java-version: 1.8
- name: Grant execute permission for gradlew - name: Grant execute permission for gradlew
run: chmod +x gradlew run: chmod +x gradlew
- name: Build with Gradle and shadowJar - name: Gradle clean
run: ./gradlew :mirai-core:shadowJar :mirai-core-qqandroid:shadowJar run: ./gradlew clean
- name: Upload artifact - name: Gradle build
uses: actions/upload-artifact@v1.0.0 run: ./gradlew build
with: - name: Gradle :mirai-core:githubUpload
# Artifact name run: ./gradlew :mirai-core:githubUpload -Dgithub_token=${{ secrets.MAMOE_TOKEN }}
name: mirai-core-all - name: Gradle :mirai-core-qqandroid:githubUpload
# Directory containing files to upload run: ./gradlew :mirai-core-qqandroid:githubUpload -Dgithub_token=${{ secrets.MAMOE_TOKEN }}
path: "mirai-core/build/libs/mirai-core-*-all.jar"
- name: Upload artifact
uses: actions/upload-artifact@v1.0.0 # - name: Upload artifact
with: # uses: actions/upload-artifact@v1.0.0
# Artifact name # with:
name: mirai-core-qqandroid-all # # Artifact name
# Directory containing files to upload # name: mirai-core
path: "mirai-core-qqandroid/build/libs/mirai-core-qqandroid-*-all.jar" # # 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"
@file:Suppress("UnstableApiUsage") @file:Suppress("UnstableApiUsage", "UNUSED_VARIABLE")
import java.time.Duration import java.time.Duration
import java.util.* import java.util.*
...@@ -60,14 +60,15 @@ subprojects { ...@@ -60,14 +60,15 @@ subprojects {
val shadowJvmJar by tasks.creating(com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar::class) { val shadowJvmJar by tasks.creating(com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar::class) {
group = "mirai" group = "mirai"
val compilation = kotlin.targets.getByName("jvm").compilations["main"] val compilation =
kotlin.targets.first { it.platformType == org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.jvm }.compilations["main"]
dependsOn(compilation.compileKotlinTask) dependsOn(compilation.compileKotlinTask)
configurations = mutableListOf(compilation.compileDependencyFiles as Configuration) configurations = mutableListOf(compilation.compileDependencyFiles as Configuration)
} }
val uploadGitHub by tasks.creating { val githubUpload by tasks.creating {
group = "mirai" group = "mirai"
dependsOn(shadowJvmJar) dependsOn(shadowJvmJar)
...@@ -88,7 +89,7 @@ subprojects { ...@@ -88,7 +89,7 @@ subprojects {
val filename = file.name val filename = file.name
println("Uploading file $filename") println("Uploading file $filename")
runCatching { runCatching {
upload.GitToken.upload( upload.GitHub.upload(
file, file,
"https://api.github.com/repositories/249670490/contents/shadow/${project.name}/$filename" "https://api.github.com/repositories/249670490/contents/shadow/${project.name}/$filename"
) )
......
...@@ -6,15 +6,6 @@ repositories { ...@@ -6,15 +6,6 @@ repositories {
jcenter() jcenter()
} }
kotlin {
sourceSets {
all {
languageSettings.useExperimentalAnnotation("kotlin.Experimental")
}
}
}
dependencies { dependencies {
fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$version" fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$version"
fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version" fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version"
......
...@@ -5,19 +5,35 @@ package upload ...@@ -5,19 +5,35 @@ package upload
import io.ktor.client.HttpClient import io.ktor.client.HttpClient
import io.ktor.client.engine.cio.CIO import io.ktor.client.engine.cio.CIO
import io.ktor.client.features.HttpTimeout import io.ktor.client.features.HttpTimeout
import io.ktor.client.features.timeout
import io.ktor.client.request.put import io.ktor.client.request.put
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import java.io.File import java.io.File
import java.util.* import java.util.*
object GitToken { object GitHub {
private fun getGitToken(): String { private fun getGithubToken(): String {
with(File(System.getProperty("user.dir")).parent + "/token.txt") { File(File(System.getProperty("user.dir")).parent, "/token.txt").let { local ->
println("reading token file in $this") if (local.exists()) {
return File(this).readText() return local.readText().trim()
}
}
File(File(System.getProperty("user.dir")), "/token.txt").let { local ->
if (local.exists()) {
return local.readText().trim()
}
}
val property = System.getProperty("github_token", "~")
if (property == null || property == "~") {
error(
"Cannot find github token, " +
"please specify by creating a file token.txt in project dir, " +
"or by providing JVM parameter 'github_token'"
)
} }
return property
} }
fun upload(file: File, url: String) = runBlocking { fun upload(file: File, url: String) = runBlocking {
...@@ -30,12 +46,7 @@ object GitToken { ...@@ -30,12 +46,7 @@ object GitToken {
requestTimeoutMillis = 600_000 requestTimeoutMillis = 600_000
socketTimeoutMillis = 600_000 socketTimeoutMillis = 600_000
} }
}.put<String>("""$url?access_token=${getGitToken()}""") { }.put<String>("""$url?access_token=${getGithubToken()}""") {
timeout {
connectTimeoutMillis = 600_000
requestTimeoutMillis = 600_000
socketTimeoutMillis = 600_000
}
val content = String(Base64.getEncoder().encode(file.readBytes())) val content = String(Base64.getEncoder().encode(file.readBytes()))
body = """ body = """
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment