Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoii committed Aug 31, 2022
2 parents 414c77f + e10fae6 commit 33e906d
Show file tree
Hide file tree
Showing 7 changed files with 2,989 additions and 73 deletions.
24 changes: 24 additions & 0 deletions .github/actions/modify-package-json/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: 'Modify package json'
description: 'Modify package json'
inputs:
defaultChannel:
description: 'The Default Channel'
required: false
channel:
description: 'The channel will be edited'
required: false
version:
description: 'Version'
required: true
srcPath:
description: 'package.json path'
required: true
destPath:
description: 'Output path'
required: true
outputs:
outputPath:
description: 'Output absolute path'
runs:
using: 'node16'
main: 'index.js'
2,851 changes: 2,851 additions & 0 deletions .github/actions/modify-package-json/index.js

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions .github/actions/modify-package-json/index.src.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const core = require('@actions/core');
const path = require('path');
const fs = require('fs');

try {
const defaultChannel = core.getInput('defaultChannel');
let channel = core.getInput('channel');
const version = core.getInput('version');
const srcPath = core.getInput('srcPath');
const destPath = core.getInput('destPath');

const workdir = process.env.GITHUB_WORKSPACE;
const src = path.resolve(workdir, srcPath);
const content = fs.readFileSync(src, 'utf8').toString();

console.log(`read content: ${content}`);

const packageJson = JSON.parse(content);

if (defaultChannel) {
packageJson.defaultChannel = defaultChannel;
}

if (!channel) {
channel = packageJson.defaultChannel;
}

packageJson.channels[channel].push(version);

const dest = path.resolve(workdir, destPath);
const newContent = JSON.stringify(packageJson, null, 2)
fs.writeFileSync(dest, newContent);

console.log(`write content to ${dest}`);
console.log(`new content: ${newContent}`)

core.setOutput("outputPath", dest);

} catch (e) {
core.setFailed(e.message);
}
70 changes: 62 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v1
Expand All @@ -27,15 +27,69 @@ jobs:
PUBLICATION_CREDENTIALS: ${{ secrets.PUBLICATION_CREDENTIALS }}

- name: Build with Gradle
run: ./gradlew build
run: ./gradlew buildPlugin

- run: ./gradlew mirai-api-http:publish --info --scan
- name: Publish to Maven Central
run: ./gradlew mirai-api-http:publish --info --scan
env:
PUBLICATION_CREDENTIALS: ${{ secrets.PUBLICATION_CREDENTIALS }}

# - name: Gradle closeRepository
# run: >
# ./gradlew mirai-api-http:closeRepository --info --stacktrace --scan
# env:
# PUBLICATION_CREDENTIALS: ${{ secrets.PUBLICATION_CREDENTIALS }}
- name: Get Tag
id: tag
uses: dawidd6/action-get-tag@v1

- name: Generate Line Temp File
run: "cat CHANGELOG.md | grep -n '## \\\\' | cut -d: -f1 | head -n 2 >> line.tmp"

- name: Generate Release Log
run: "cat CHANGELOG.md | head -n $((`tail -n 1 line.tmp`-1)) | tail -n +`head -n 1 line.tmp` >> release.log"

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: mirai-api-http-${{ steps.tag.outputs.tag }}
body_path: release.log
draft: false
prerelease: false

- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./mirai-api-http/build/mirai/mirai-api-http-${{ steps.tag.outputs.tag }}.mirai2.jar
asset_name: mirai-api-http-${{ steps.tag.outputs.tag }}.mirai2.jar
asset_content_type: application/zip

- name: Clone Mirai-Repo
uses: actions/checkout@v3
with:
repository: project-mirai/mirai-repo-mirror
token: ${{ secrets.MAMOEBOT_TOKEN }}
path: ./github/mirai-repo-mirror

- name: Modify package.json
uses: ./.github/actions/modify-package-json
with:
defaultChannel: stable-v2
version: ${{ steps.tag.outputs.tag }}
srcPath: .github/mirai-repo-mirror/net/mamoe/mirai-api-http/package.json
destPath: .github/package.json

- name: Move package.json
run: |
cp .github/package.json .github/mirai-repo-mirror/net/mamoe/mirai-api-http/package.json
- name: Create PR for Mirai-Repo
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.MAMOEBOT_TOKEN }}
commit-message: 'update: mirai-api-http ${{ steps.tag.outputs.tag }}'
title: 'update: mirai-api-http ${{ steps.tag.outputs.tag }}'
branch: create-pull-request/mah-update-version
delete-branch: true
62 changes: 0 additions & 62 deletions .github/workflows/release.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class WebhookAdapter : MahAdapter("webhook") {
private suspend fun hook(destination: String, data: String, bot: Bot) {
kotlin.runCatching {
val resp = client.post(destination, data, bot.id)
resp.jsonParseOrNull<WebhookPacket>()?.let {
resp?.jsonParseOrNull<WebhookPacket>()?.let {
execute(bot, it)
}
}.onFailure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package net.mamoe.mirai.api.http.adapter.webhook.client
import io.ktor.client.*
import io.ktor.client.engine.okhttp.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.http.content.*
import net.mamoe.mirai.api.http.util.smartTakeFrom
Expand All @@ -30,12 +31,19 @@ class WebhookHttpClient(private val headers: Map<String, String>) {
/**
* POST请求 (String)
*/
suspend fun post(path: String, content: String, botId: Long? = null): String {
return client.request {
suspend fun post(path: String, content: String, botId: Long? = null): String? {
return client.request<HttpResponse> {
url { smartTakeFrom(path) }
botHeader(botId.toString())
method = HttpMethod.Post
body = TextContent(content, ContentType.Application.Json.withCharset(StandardCharsets.UTF_8))
}.let {
val contentLength = it.contentLength()
if (it.status != HttpStatusCode.OK || contentLength == null || contentLength == 0L) {
return null
}

it.readText()
}
}
}

0 comments on commit 33e906d

Please sign in to comment.