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:
- name: Gradle build
run: ./gradlew build
- 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
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
......
......@@ -2,6 +2,9 @@
开发版本. 频繁更新, 不保证高稳定性
## `0.30.1` ~
- 修复一些事件解析失败
## `0.30.0` 2020/3/24
此版本为二进制不兼容更新, 全部使用者都需要重新编译.
......
......@@ -91,10 +91,13 @@ subprojects {
runCatching {
upload.GitHub.upload(
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 {
System.err.println("Upload failed")
it.printStackTrace() // force show stacktrace
throw it
}
}
}
......
......@@ -7,12 +7,24 @@ import io.ktor.client.engine.cio.CIO
import io.ktor.client.features.HttpTimeout
import io.ktor.client.request.put
import kotlinx.coroutines.runBlocking
import org.gradle.api.Project
import org.gradle.kotlin.dsl.provideDelegate
import java.io.File
import java.util.*
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 ->
if (local.exists()) {
return local.readText().trim()
......@@ -25,35 +37,36 @@ object GitHub {
}
}
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
error(
"Cannot find github token, " +
"please specify by creating a file token.txt in project dir, " +
"or by providing JVM parameter 'github_token'"
)
}
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) {
engine {
requestTimeout = 600_000
}
install(HttpTimeout) {
connectTimeoutMillis = 600_000
requestTimeoutMillis = 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()))
body = """
{
"message": "automatic upload",
"message": "automatically upload on release",
"content": "$content"
}
""".trimIndent()
}.let {
println("Upload response: $it")
}
}
}
\ No newline at end of file
......@@ -14,8 +14,10 @@ import io.ktor.client.request.*
import io.ktor.client.request.forms.MultiPartFormDataContent
import io.ktor.client.request.forms.formData
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.withContext
import kotlinx.serialization.UnstableDefault
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration
......@@ -30,6 +32,7 @@ import net.mamoe.mirai.event.events.MessageRecallEvent
import net.mamoe.mirai.message.data.*
import net.mamoe.mirai.qqandroid.contact.MemberInfoImpl
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.OnlineGroupImageImpl
import net.mamoe.mirai.qqandroid.network.QQAndroidBotNetworkHandler
......@@ -99,11 +102,11 @@ internal abstract class QQAndroidBotBase constructor(
// internally visible only
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? {
return groups.delegate.getOrNull(uin)
return groups.asSequence().firstOrNull { it.checkIsGroupImpl(); it.uin == uin }
}
@OptIn(LowLevelAPI::class)
......
......@@ -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!!" }
}
@OptIn(ExperimentalContracts::class)
internal fun Group.checkIsGroupImpl() {
contract {
returns() implies (this@checkIsGroupImpl is GroupImpl)
}
GroupImpl.checkIsInstance(this)
}
@Suppress("PropertyName")
internal class GroupImpl(
bot: QQAndroidBot, override val coroutineContext: CoroutineContext,
......@@ -133,7 +141,7 @@ internal class GroupImpl(
}
}
override val settings: GroupSettings = object : GroupSettings{
override val settings: GroupSettings = object : GroupSettings {
override var entranceAnnouncement: String
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