Commit c3f01f90 authored by Him188's avatar Him188 Committed by GitHub

Configure Shadow publish (#160)

* Test shadow

* Add print stacktrace

* Add more ways to find githubToken

* Error when failed to upload

* Try github token

* Use mamoe token

* Use header

* Rubbish actions

* Fix `GroupImpl.getGroupByUin`

* Triage shadow task on release
parent 748b1f74
...@@ -27,9 +27,9 @@ jobs: ...@@ -27,9 +27,9 @@ jobs:
- name: Gradle build - name: Gradle build
run: ./gradlew build run: ./gradlew build
- name: Gradle :mirai-core:githubUpload - name: Gradle :mirai-core:githubUpload
run: ./gradlew :mirai-core:githubUpload -Dgithub_token=${{ secrets.MAMOE_TOKEN }} run: ./gradlew :mirai-core:githubUpload -Dgithub_token=${{ secrets.MAMOE_TOKEN }} -Pgithub_token=${{ secrets.MAMOE_TOKEN }}
- name: Gradle :mirai-core-qqandroid:githubUpload - name: Gradle :mirai-core-qqandroid:githubUpload
run: ./gradlew :mirai-core-qqandroid:githubUpload -Dgithub_token=${{ secrets.MAMOE_TOKEN }} run: ./gradlew :mirai-core-qqandroid:githubUpload -Dgithub_token=${{ secrets.MAMOE_TOKEN }} -Pgithub_token=${{ secrets.MAMOE_TOKEN }}
# - name: Upload artifact # - name: Upload artifact
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
开发版本. 频繁更新, 不保证高稳定性 开发版本. 频繁更新, 不保证高稳定性
## `0.30.1` ~
- 修复一些事件解析失败
## `0.30.0` 2020/3/24 ## `0.30.0` 2020/3/24
此版本为二进制不兼容更新, 全部使用者都需要重新编译. 此版本为二进制不兼容更新, 全部使用者都需要重新编译.
......
...@@ -91,10 +91,13 @@ subprojects { ...@@ -91,10 +91,13 @@ subprojects {
runCatching { runCatching {
upload.GitHub.upload( upload.GitHub.upload(
file, file,
"https://api.github.com/repositories/249670490/contents/shadow/${project.name}/$filename" "https://api.github.com/repos/mamoe/mirai-repo/contents/shadow/${project.name}/$filename",
project
) )
}.exceptionOrNull()?.let { }.exceptionOrNull()?.let {
System.err.println("Upload failed") System.err.println("Upload failed")
it.printStackTrace() // force show stacktrace
throw it
} }
} }
} }
......
...@@ -7,12 +7,24 @@ import io.ktor.client.engine.cio.CIO ...@@ -7,12 +7,24 @@ import io.ktor.client.engine.cio.CIO
import io.ktor.client.features.HttpTimeout import io.ktor.client.features.HttpTimeout
import io.ktor.client.request.put import io.ktor.client.request.put
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.gradle.api.Project
import org.gradle.kotlin.dsl.provideDelegate
import java.io.File import java.io.File
import java.util.* import java.util.*
object GitHub { object GitHub {
private fun getGithubToken(): String { private fun getGithubToken(project: Project): String {
kotlin.runCatching {
@Suppress("UNUSED_VARIABLE", "LocalVariableName")
val github_token: String by project
return github_token
}
System.getProperty("github_token", null)?.let {
return it.trim()
}
File(File(System.getProperty("user.dir")).parent, "/token.txt").let { local -> File(File(System.getProperty("user.dir")).parent, "/token.txt").let { local ->
if (local.exists()) { if (local.exists()) {
return local.readText().trim() return local.readText().trim()
...@@ -25,35 +37,36 @@ object GitHub { ...@@ -25,35 +37,36 @@ object GitHub {
} }
} }
val property = System.getProperty("github_token", "~")
if (property == null || property == "~") {
error( error(
"Cannot find github token, " + "Cannot find github token, " +
"please specify by creating a file token.txt in project dir, " + "please specify by creating a file token.txt in project dir, " +
"or by providing JVM parameter 'github_token'" "or by providing JVM parameter 'github_token'"
) )
} }
return property
}
fun upload(file: File, url: String) = runBlocking { fun upload(file: File, url: String, project: Project) = runBlocking {
val token = getGithubToken(project)
println("token.length=${token.length}")
HttpClient(CIO) { HttpClient(CIO) {
engine { engine {
requestTimeout = 600_000 requestTimeout = 600_000
} }
install(HttpTimeout) { install(HttpTimeout) {
connectTimeoutMillis = 600_000
requestTimeoutMillis = 600_000
socketTimeoutMillis = 600_000 socketTimeoutMillis = 600_000
requestTimeoutMillis = 600_000
connectTimeoutMillis = 600_000
} }
}.put<String>("""$url?access_token=${getGithubToken()}""") { }.put<String>("$url?access_token=$token") {
//header("token", token)
val content = String(Base64.getEncoder().encode(file.readBytes())) val content = String(Base64.getEncoder().encode(file.readBytes()))
body = """ body = """
{ {
"message": "automatic upload", "message": "automatically upload on release",
"content": "$content" "content": "$content"
} }
""".trimIndent() """.trimIndent()
}.let {
println("Upload response: $it")
} }
} }
} }
\ No newline at end of file
...@@ -14,8 +14,10 @@ import io.ktor.client.request.* ...@@ -14,8 +14,10 @@ import io.ktor.client.request.*
import io.ktor.client.request.forms.MultiPartFormDataContent import io.ktor.client.request.forms.MultiPartFormDataContent
import io.ktor.client.request.forms.formData import io.ktor.client.request.forms.formData
import io.ktor.client.statement.HttpResponse import io.ktor.client.statement.HttpResponse
import kotlinx.coroutines.* import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.async
import kotlinx.coroutines.io.ByteReadChannel import kotlinx.coroutines.io.ByteReadChannel
import kotlinx.coroutines.withContext
import kotlinx.serialization.UnstableDefault import kotlinx.serialization.UnstableDefault
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration import kotlinx.serialization.json.JsonConfiguration
...@@ -30,6 +32,7 @@ import net.mamoe.mirai.event.events.MessageRecallEvent ...@@ -30,6 +32,7 @@ import net.mamoe.mirai.event.events.MessageRecallEvent
import net.mamoe.mirai.message.data.* import net.mamoe.mirai.message.data.*
import net.mamoe.mirai.qqandroid.contact.MemberInfoImpl import net.mamoe.mirai.qqandroid.contact.MemberInfoImpl
import net.mamoe.mirai.qqandroid.contact.QQImpl import net.mamoe.mirai.qqandroid.contact.QQImpl
import net.mamoe.mirai.qqandroid.contact.checkIsGroupImpl
import net.mamoe.mirai.qqandroid.message.OnlineFriendImageImpl import net.mamoe.mirai.qqandroid.message.OnlineFriendImageImpl
import net.mamoe.mirai.qqandroid.message.OnlineGroupImageImpl import net.mamoe.mirai.qqandroid.message.OnlineGroupImageImpl
import net.mamoe.mirai.qqandroid.network.QQAndroidBotNetworkHandler import net.mamoe.mirai.qqandroid.network.QQAndroidBotNetworkHandler
...@@ -99,11 +102,11 @@ internal abstract class QQAndroidBotBase constructor( ...@@ -99,11 +102,11 @@ internal abstract class QQAndroidBotBase constructor(
// internally visible only // internally visible only
fun getGroupByUin(uin: Long): Group { fun getGroupByUin(uin: Long): Group {
return groups.delegate.getOrNull(uin) ?: throw NoSuchElementException("Can not found group with ID=${uin}") return getGroupByUinOrNull(uin) ?: throw NoSuchElementException("Group $uin not found")
} }
fun getGroupByUinOrNull(uin: Long): Group? { fun getGroupByUinOrNull(uin: Long): Group? {
return groups.delegate.getOrNull(uin) return groups.asSequence().firstOrNull { it.checkIsGroupImpl(); it.uin == uin }
} }
@OptIn(LowLevelAPI::class) @OptIn(LowLevelAPI::class)
......
...@@ -47,6 +47,14 @@ internal fun GroupImpl.Companion.checkIsInstance(instance: Group) { ...@@ -47,6 +47,14 @@ internal fun GroupImpl.Companion.checkIsInstance(instance: Group) {
check(instance is GroupImpl) { "group is not an instanceof GroupImpl!! DO NOT interlace two or more protocol implementations!!" } check(instance is GroupImpl) { "group is not an instanceof GroupImpl!! DO NOT interlace two or more protocol implementations!!" }
} }
@OptIn(ExperimentalContracts::class)
internal fun Group.checkIsGroupImpl() {
contract {
returns() implies (this@checkIsGroupImpl is GroupImpl)
}
GroupImpl.checkIsInstance(this)
}
@Suppress("PropertyName") @Suppress("PropertyName")
internal class GroupImpl( internal class GroupImpl(
bot: QQAndroidBot, override val coroutineContext: CoroutineContext, bot: QQAndroidBot, override val coroutineContext: CoroutineContext,
...@@ -133,7 +141,7 @@ internal class GroupImpl( ...@@ -133,7 +141,7 @@ internal class GroupImpl(
} }
} }
override val settings: GroupSettings = object : GroupSettings{ override val settings: GroupSettings = object : GroupSettings {
override var entranceAnnouncement: String override var entranceAnnouncement: String
get() = _announcement get() = _announcement
......
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