forked from mamoe/mirai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cui cloud publishing & GitHub republishing (mamoe#177)
* Add CuiCloud tasks * Add CuiCloud workflow * Fix shadowJar * Fix `reply` function prohibition in MessageSelectBuilder * Fix doc * Update CI * Update CI * Test CI * Fix file * Increase jvm memory limitation * Add comments * Remove unnecessary experimental api use * Increase upload task timeout * Fix sha * Increase timeout * Fix github * Trigger publishing on release
- Loading branch information
Showing
8 changed files
with
303 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# This is a basic workflow to help you get started with Actions | ||
|
||
name: CuiCloud 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:cuiCloudUpload | ||
run: ./gradlew :mirai-core:cuiCloudUpload -Dcui_cloud_key=${{ secrets.CUI_CLOUD_KEY }} -Pcui_cloud_key=${{ secrets.CUI_CLOUD_KEY }} -Dcui_cloud_url=${{ secrets.CUI_CLOUD_URL }} -Pcui_cloud_url=${{ secrets.CUI_CLOUD_URL }} | ||
- name: Gradle :mirai-core-qqandroid:cuiCloudUpload | ||
run: ./gradlew :mirai-core-qqandroid:cuiCloudUpload -Dcui_cloud_key=${{ secrets.CUI_CLOUD_KEY }} -Pcui_cloud_key=${{ secrets.CUI_CLOUD_KEY }} -Dcui_cloud_url=${{ secrets.CUI_CLOUD_URL }} -Pcui_cloud_url=${{ secrets.CUI_CLOUD_URL }} | ||
|
||
|
||
# - name: Upload artifact | ||
# uses: actions/[email protected] | ||
# 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/[email protected] | ||
# with: | ||
# # Artifact name | ||
# name: mirai-core-qqandroid-all | ||
# # Directory containing files to upload | ||
# path: "mirai-core-qqandroid/build/libs/mirai-core-qqandroid-*-all.jar" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* 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 | ||
*/ | ||
|
||
package upload | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.runBlocking | ||
import kotlinx.coroutines.withContext | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.provideDelegate | ||
import org.jsoup.Connection | ||
import org.jsoup.Jsoup | ||
import java.io.File | ||
import java.util.* | ||
|
||
object CuiCloud { | ||
private fun getUrl(project: Project): String { | ||
kotlin.runCatching { | ||
@Suppress("UNUSED_VARIABLE", "LocalVariableName") | ||
val cui_cloud_url: String by project | ||
return cui_cloud_url | ||
} | ||
|
||
System.getProperty("cui_cloud_url", null)?.let { | ||
return it.trim() | ||
} | ||
error("cannot find url for CuiCloud") | ||
} | ||
|
||
private fun getKey(project: Project): String { | ||
kotlin.runCatching { | ||
@Suppress("UNUSED_VARIABLE", "LocalVariableName") | ||
val cui_cloud_key: String by project | ||
return cui_cloud_key | ||
} | ||
|
||
System.getProperty("cui_cloud_key", null)?.let { | ||
return it.trim() | ||
} | ||
error("cannot find key for CuiCloud") | ||
} | ||
|
||
fun upload(file: File, project: Project) { | ||
val cuiCloudUrl = getUrl(project) | ||
val key = getKey(project) | ||
|
||
runBlocking { | ||
uploadToCuiCloud( | ||
cuiCloudUrl, | ||
key, | ||
"/mirai/${project.name}/${file.nameWithoutExtension}.mp4", | ||
file.readBytes() | ||
) | ||
} | ||
} | ||
|
||
private suspend fun uploadToCuiCloud( | ||
cuiCloudUrl: String, | ||
cuiToken: String, | ||
filePath: String, | ||
content: ByteArray | ||
) { | ||
val response = withContext(Dispatchers.IO) { | ||
Jsoup.connect(cuiCloudUrl).method(Connection.Method.POST) | ||
.data("base64", Base64.getEncoder().encodeToString(content)) | ||
.data("filePath", filePath) | ||
.data("key", cuiToken) | ||
.timeout(Int.MAX_VALUE) | ||
.execute() | ||
} | ||
if (response.statusCode() != 200) { | ||
println(response.body()) | ||
error("Cui Cloud Does Not Return 200") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.