Skip to content

Commit

Permalink
Merge pull request #166 from simple-robot/dev/main
Browse files Browse the repository at this point in the history
Release: v4.0.0-beta6
  • Loading branch information
ForteScarlet authored Aug 12, 2024
2 parents 4e8a500 + a9d7613 commit a52a73a
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 242 deletions.
7 changes: 7 additions & 0 deletions .changelog/v4.0.0-beta6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
> 对应核心版本: [**v4.5.0**](https://github.com/simple-robot/simpler-robot/releases/tag/v4.5.0)
> [!warning]
> 目前版本尚处于 **`beta`** 阶段,代表仍然可能存在部分已知问题或未知问题,
> 以及尚未完善的内容和落后于官方更新的内容。
我们欢迎并期望着您的 [反馈](https://github.com/simple-robot/simbot-component-kook/issues)[协助](https://github.com/simple-robot/simbot-component-kook/pulls),感谢您的贡献与支持!
27 changes: 2 additions & 25 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ jobs:

# Create gitHub release
- name: Create Github Release
uses: softprops/action-gh-release@v0.1.15
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.PUSH_TOKEN }}
body_path: .changelog/${{ github.ref_name }}.md
body: ''
generate_release_notes: true
prerelease: ${{ contains(github.ref_name, 'preview') || contains(github.ref_name, 'alpha') || contains(github.ref_name, 'dev') }}

Expand Down Expand Up @@ -137,27 +138,3 @@ jobs:
# deploy to sub dir
destination_dir: components/kook

# deploy-website:
# name: Deploy Website
# runs-on: ubuntu-latest
# needs: run-test-and-publish
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-node@v3
# with:
# node-version: 16.x
# cache: npm
# cache-dependency-path: ./website/package-lock.json
#
# - run: |
# npm ci
# npm run build
# working-directory: ./website
#
# # https://github.com/marketplace/actions/github-pages-action
# - name: Push to doc repository
# uses: peaceiris/actions-gh-pages@v3
# with:
# personal_token: ${{ secrets.PUSH_TOKEN }}
# publish_branch: gh-pages
# publish_dir: ./website/build
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# v4.0.0-beta6

> Release & Pull Notes: [v4.0.0-beta6](https://github.com/simple-robot/simpler-robot/releases/tag/v4.0.0-beta6)
- optimize(internal): 简单优化内部的KSP ([`bd15b6a`](https://github.com/simple-robot/simpler-robot/commit/bd15b6a))
- fix(api): 修复 CreateAssetApi 使用的错误请求头 ([`f0a0fe0`](https://github.com/simple-robot/simpler-robot/commit/f0a0fe0))

# v4.0.0-beta5

> Release & Pull Notes: [v4.0.0-beta5](https://github.com/simple-robot/simpler-robot/releases/tag/v4.0.0-beta5)
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/P.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ object P : ProjectDetail() {
override val homepage: String
get() = HOMEPAGE

const val VERSION = "4.0.0-beta5"
const val NEXT_VERSION = "4.0.0-beta6"
const val VERSION = "4.0.0-beta6"
const val NEXT_VERSION = "4.0.0-beta7"

override val snapshotVersion = "$NEXT_VERSION-SNAPSHOT"
override val version = if (isSnapshot()) snapshotVersion else VERSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

package kook.internal.processors.apireader

import com.google.devtools.ksp.KspExperimental
import com.google.devtools.ksp.getKotlinClassByName
import com.google.devtools.ksp.getClassDeclarationByName
import com.google.devtools.ksp.isAbstract
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.processing.SymbolProcessor
Expand All @@ -42,29 +41,11 @@ abstract class ReaderProcessor(private val environment: SymbolProcessorEnvironme
abstract val optionName: String
abstract val targetClassName: String

@OptIn(KspExperimental::class)
override fun process(resolver: Resolver): List<KSAnnotated> {
val targetFilePath: String? = environment.options[optionName]

val targetFile = File(targetFilePath ?: run {
val msg = "target output file option ['$optionName'] is null!"
environment.logger.warn(msg)
return emptyList()
})

environment.logger.info("target output file: ${targetFile.absolutePath}")
val targetClass = resolver.getKotlinClassByName(targetClassName)
environment.logger.info("apiClass: $targetClassName")
targetClass ?: return emptyList()

val targetClasses = resolver.getAllFiles().flatMap { it.declarations }
.filterIsInstance<KSClassDeclaration>()
.filter {
targetClass.asStarProjectedType().isAssignableFrom(it.asStarProjectedType())
}
.filter { !it.isAbstract() }
.toList()
private var targetFile: File? = null
private val targetClasses = mutableListOf<KSClassDeclaration>()

override fun finish() {
val targetFile = targetFile ?: return
if (!targetFile.exists()) {
targetFile.parentFile.mkdirs()
} else {
Expand All @@ -80,7 +61,32 @@ abstract class ReaderProcessor(private val environment: SymbolProcessorEnvironme
).use { writer ->
writer.writeDeflistTo(targetClasses)
}
}

override fun process(resolver: Resolver): List<KSAnnotated> {
val targetFilePath: String? = environment.options[optionName]

val targetFile = File(targetFilePath ?: run {
val msg = "target output file option ['$optionName'] is null!"
environment.logger.warn(msg)
return emptyList()
})

this.targetFile = targetFile

environment.logger.info("target output file: ${targetFile.absolutePath}")
val targetClass = resolver.getClassDeclarationByName(targetClassName)
environment.logger.info("apiClass: $targetClassName found $targetClass", targetClass)
targetClass ?: return emptyList()

// find all
resolver.getAllFiles().flatMap { it.declarations }
.filterIsInstance<KSClassDeclaration>()
.filter {
targetClass.asStarProjectedType().isAssignableFrom(it.asStarProjectedType())
}
.filter { !it.isAbstract() }
.toCollection(targetClasses)

return emptyList()
}
Expand All @@ -91,7 +97,7 @@ abstract class ReaderProcessor(private val environment: SymbolProcessorEnvironme
*
* @author ForteScarlet
*/
class ApiReaderProcessor(private val environment: SymbolProcessorEnvironment) : ReaderProcessor(environment) {
class ApiReaderProcessor(environment: SymbolProcessorEnvironment) : ReaderProcessor(environment) {
override val optionName: String = API_READ_TARGET_FILE_OPTION_KEY
override val targetClassName: String = KOOK_API_CLASS_NAME
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

package kook.internal.processors.apireader

import com.google.devtools.ksp.KspExperimental
import com.google.devtools.ksp.getKotlinClassByName
import com.google.devtools.ksp.getClassDeclarationByName
import com.google.devtools.ksp.getVisibility
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.processing.SymbolProcessor
Expand Down Expand Up @@ -50,7 +49,29 @@ class EventReaderProcessor(private val environment: SymbolProcessorEnvironment)
private val targetClassName = environment.options[EVENT_READ_TARGET_CLASS_OPTION_KEY]
?: KOOK_EVENT_CLASS_NAME

@OptIn(KspExperimental::class)
private var targetFile: File? = null
private val targetClasses = mutableListOf<KSClassDeclaration>()

override fun finish() {
val targetFile = targetFile ?: return

if (!targetFile.exists()) {
targetFile.parentFile.mkdirs()
} else {
targetFile.delete()
}

targetFile.toPath().bufferedWriter(
options = arrayOf(
StandardOpenOption.WRITE,
StandardOpenOption.TRUNCATE_EXISTING,
StandardOpenOption.CREATE
)
).use { writer ->
writer.writeDeflistTo(targetClasses)
}
}

override fun process(resolver: Resolver): List<KSAnnotated> {
val targetFilePath: String? = environment.options[EVENT_READ_TARGET_FILE_OPTION_KEY]

Expand All @@ -59,37 +80,22 @@ class EventReaderProcessor(private val environment: SymbolProcessorEnvironment)
environment.logger.warn(msg)
return emptyList()
})
this.targetFile = targetFile

environment.logger.info("Target class name: $targetClassName")
environment.logger.info("Target output file: ${targetFile.absolutePath}")
val targetClass = resolver.getKotlinClassByName(targetClassName)
environment.logger.info("apiClass: $targetClass")
val targetClass = resolver.getClassDeclarationByName(targetClassName)
environment.logger.info("apiClass: $targetClass found at $targetClass", targetClass)
targetClass ?: return emptyList()

val targetClasses = resolver.getAllFiles().flatMap { it.declarations }
resolver.getAllFiles().flatMap { it.declarations }
.filterIsInstance<KSClassDeclaration>()
.filter {
targetClass.asStarProjectedType().isAssignableFrom(it.asStarProjectedType())
}
// .filter { !it.isAbstract() }
.filter { it.getVisibility() in EXPECT_VISIBILITY }
.toList()

if (!targetFile.exists()) {
targetFile.parentFile.mkdirs()
} else {
targetFile.delete()
}

targetFile.toPath().bufferedWriter(
options = arrayOf(
StandardOpenOption.WRITE,
StandardOpenOption.TRUNCATE_EXISTING,
StandardOpenOption.CREATE
)
).use { writer ->
writer.writeDeflistTo(targetClasses)
}
.toCollection(targetClasses)

return emptyList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class CreateAssetApi private constructor(
private const val DEFAULT_FILENAME = "unknown-file"
private const val ASSET_API_FORM_PROPERTY_NAME = "file"
private val HEADERS = Headers.build {
append(HttpHeaders.ContentType, "form-data")
append(HttpHeaders.ContentType, ContentType.MultiPart.FormData)
}

/**
Expand Down
Loading

0 comments on commit a52a73a

Please sign in to comment.