diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..502ef6a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,103 @@ +# GitHub Actions Workflow created for handling the release process based on the draft release prepared with the Build workflow. +# Running the publishPlugin task requires all following secrets to be provided: PUBLISH_TOKEN, PRIVATE_KEY, PRIVATE_KEY_PASSWORD, CERTIFICATE_CHAIN. +# See https://plugins.jetbrains.com/docs/intellij/plugin-signing.html for more information. + +name: Release +on: + release: + types: [prereleased, released] + +jobs: + + # 准备插件并将其发布到 JetBrains Marketplace 存储库 + release: + name: Publish Plugin + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + + # 查看当前存储库 + - name: Fetch Sources + uses: actions/checkout@v4 + with: + ref: ${{ github.event.release.tag_name }} + + # 为后续步骤设置 Java 环境 + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: zulu + java-version: 17 + + # 设置 Gradle + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + gradle-home-cache-cleanup: true + + # 设置环境变量 + - name: Export Properties + id: properties + shell: bash + run: | + CHANGELOG="$(cat << 'EOM' | sed -e 's/^[[:space:]]*$//g' -e '/./,$!d' + ${{ github.event.release.body }} + EOM + )" + + echo "changelog<> $GITHUB_OUTPUT + echo "$CHANGELOG" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + # 使用当前发行说明更新未发布部分 + - name: Patch Changelog + if: ${{ steps.properties.outputs.changelog != '' }} + env: + CHANGELOG: ${{ steps.properties.outputs.changelog }} + run: | + ./gradlew patchChangelog --release-note="$CHANGELOG" + + # 将插件发布到 JetBrains Marketplace + - name: Publish Plugin + env: + PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }} + CERTIFICATE_CHAIN: ${{ secrets.CERTIFICATE_CHAIN }} + PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }} + PRIVATE_KEY_PASSWORD: ${{ secrets.PRIVATE_KEY_PASSWORD }} + run: ./gradlew publishPlugin -Dorg.gradle.project.intellijPublishToken=${{ secrets.PUBLISH_TOKEN }} + + # 上传工件作为发布资产 + - name: Upload Release Asset + env: + GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }} + run: gh release upload ${{ github.event.release.tag_name }} ./build/distributions/* + + # 创建拉取请求 + - name: Create Pull Request + if: ${{ steps.properties.outputs.changelog != '' }} + env: + GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }} + run: | + VERSION="${{ github.event.release.tag_name }}" + BRANCH="changelog-update-$VERSION" + LABEL="release changelog" + + git config user.email "action@github.com" + git config user.name "GitHub Action" + + git checkout -b $BRANCH + git commit -am "Changelog update - $VERSION" + git push --set-upstream origin $BRANCH + + gh label create "$LABEL" \ + --description "Pull requests with release changelog update" \ + --force \ + || true + + gh pr create \ + --title "Changelog update - \`$VERSION\`" \ + --body "Current pull request contains patched \`CHANGELOG.md\` file for the \`$VERSION\` version." \ + --label "$LABEL" \ + --head $BRANCH \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..453dd19 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,23 @@ +# IntelliJ Platform Plugin Template Changelog + +## [Unreleased] +### Added + +### Changed + +### Deprecated + +### Removed + +### Fixed + +### Security + +## [1.1.2] +**Full Changelog**: https://github.com/mdddj/SalvoRsTool/compare/1.1.1.7...1.1.2 + +## [1.1.2] - 2024-04-19 +- upload test + +## [1.1.1] - 2024-04-19 +- bug fix \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 83d1eae..b190e81 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,27 +1,26 @@ plugins { id("org.jetbrains.kotlin.jvm") version "1.9.22" id("org.jetbrains.intellij") version "1.17.2" + id("org.jetbrains.changelog") version "1.3.1" } group = "shop.itbug" -version = "1.0-SNAPSHOT" +version = "1.1.2" repositories { mavenCentral() } -// Configure Gradle IntelliJ Plugin -// Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html +// intellij { version.set("LATEST-EAP-SNAPSHOT") - type.set("RR") // Target IDE Platform + type.set("RR") plugins.set(listOf("com.jetbrains.rust")) } -val pushToken: String? = System.getenv("idea_push_token") +val pushToken: String? = System.getenv("PUBLISH_TOKEN") tasks { - // Set the JVM compatibility versions withType { sourceCompatibility = "17" targetCompatibility = "17" @@ -33,16 +32,28 @@ tasks { patchPluginXml { sinceBuild.set("232") untilBuild.set("242.*") + changeNotes.set(""" +
+

1.1.0

+

+ Optimize the presentation of underlined database table names, which will be changed to camel case naming method +

+
+ """.trimIndent()) } signPlugin { - certificateChainFile.set(file("chain.crt")) - privateKeyFile.set(file("private.key")) +// certificateChainFile.set(file("chain.crt")) +// privateKeyFile.set(file("private.key")) + certificateChain.set(System.getenv("CERTIFICATE_CHAIN")) + privateKey.set(System.getenv("PRIVATE_KEY")) password.set(System.getenv("PRIVATE_KEY_PASSWORD")) } publishPlugin { - token.set(pushToken) + if(pushToken != null) { + token.set(pushToken) + } } runIde { diff --git a/src/main/kotlin/shop/itbug/salvorstool/dialog/GenerateDtoDialog.kt b/src/main/kotlin/shop/itbug/salvorstool/dialog/GenerateDtoDialog.kt index 8fad0cb..b71a0d9 100644 --- a/src/main/kotlin/shop/itbug/salvorstool/dialog/GenerateDtoDialog.kt +++ b/src/main/kotlin/shop/itbug/salvorstool/dialog/GenerateDtoDialog.kt @@ -25,6 +25,7 @@ import shop.itbug.salvorstool.i18n.MyI18n import shop.itbug.salvorstool.tool.MyRsPsiFactory import shop.itbug.salvorstool.tool.Tools import shop.itbug.salvorstool.tool.myManager +import shop.itbug.salvorstool.tool.underlineToCamel import shop.itbug.salvorstool.widget.RsEditor import java.awt.Dimension import java.util.* @@ -48,10 +49,11 @@ enum class GenerateDtoDialogResultEnum { ///获取struct名称,例如: "user"表名字,生成对象的名称:"UserAddRequest" fun GenerateDtoDialogResultEnum.getStructName(sqlTableName: String): String { + return when (this) { - GenerateDtoDialogResultEnum.AddRequest -> sqlTableName + "AddRequest" - GenerateDtoDialogResultEnum.UpdateRequest -> sqlTableName + "UpdateRequest" - GenerateDtoDialogResultEnum.Response -> sqlTableName + "Response" + GenerateDtoDialogResultEnum.AddRequest -> sqlTableName.underlineToCamel + "AddRequest" + GenerateDtoDialogResultEnum.UpdateRequest -> sqlTableName.underlineToCamel + "UpdateRequest" + GenerateDtoDialogResultEnum.Response -> sqlTableName.underlineToCamel + "Response" }.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() } } diff --git a/src/main/kotlin/shop/itbug/salvorstool/tool/ExtendedFuntions.kt b/src/main/kotlin/shop/itbug/salvorstool/tool/ExtendedFuntions.kt index 15c4f2d..67f09c5 100644 --- a/src/main/kotlin/shop/itbug/salvorstool/tool/ExtendedFuntions.kt +++ b/src/main/kotlin/shop/itbug/salvorstool/tool/ExtendedFuntions.kt @@ -1,9 +1,12 @@ package shop.itbug.salvorstool.tool +import com.google.common.base.CaseFormat import com.intellij.psi.PsiElement import org.rust.lang.core.psi.RsNamedFieldDecl import org.rust.lang.core.psi.RsOuterAttr import org.rust.lang.core.psi.impl.RsStructItemImpl +import java.util.* + val PsiElement.myManager get() = MyRsPsiElementManager(this) val RsStructItemImpl.myManager get() = MyRsStructManager(this) val RsNamedFieldDecl.myManager get() = MyFieldPsiElementManager(this) @@ -12,5 +15,11 @@ fun String.capitalizeFirstLetter(): String { if (isEmpty()) { return this } - return substring(0, 1).toUpperCase() + substring(1) + return substring(0, 1).uppercase(Locale.getDefault()) + substring(1) +} +/// +val String.underlineToCamel: String get() = underlineToCamel(this) +///将驼峰变成下划线 +fun underlineToCamel(underlineString: String): String { + return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, underlineString) } \ No newline at end of file diff --git a/src/main/kotlin/shop/itbug/salvorstool/tool/MyRsPsiElementManager.kt b/src/main/kotlin/shop/itbug/salvorstool/tool/MyRsPsiElementManager.kt index 18adcb0..279c932 100644 --- a/src/main/kotlin/shop/itbug/salvorstool/tool/MyRsPsiElementManager.kt +++ b/src/main/kotlin/shop/itbug/salvorstool/tool/MyRsPsiElementManager.kt @@ -15,7 +15,7 @@ class MyRsPsiElementManager(context: PsiElement) { } /// struct操作管理 -class MyRsStructManager(val psiElement: RsStructItemImpl) { +class MyRsStructManager(private val psiElement: RsStructItemImpl) { ///属性列表 @@ -40,7 +40,7 @@ class MyRsStructManager(val psiElement: RsStructItemImpl) { } - +/// ///属性处理 diff --git a/src/main/kotlin/shop/itbug/salvorstool/tool/MyRsPsiFactory.kt b/src/main/kotlin/shop/itbug/salvorstool/tool/MyRsPsiFactory.kt index a6c2c8c..669ae4d 100644 --- a/src/main/kotlin/shop/itbug/salvorstool/tool/MyRsPsiFactory.kt +++ b/src/main/kotlin/shop/itbug/salvorstool/tool/MyRsPsiFactory.kt @@ -92,7 +92,7 @@ pub async fn add_$tabName(req: $structName) -> AppResult<$responseName> { let model = $tabName::ActiveModel { $sb }; - let result = ${tabName.capitalizeFirstLetter()}::insert(model).exec(db).await?; + let result = ${tabName.underlineToCamel.capitalizeFirstLetter()}::insert(model).exec(db).await?; Ok($responseName { ${primaryField.myManager.name}: result.last_insert_id, $fsb @@ -138,9 +138,9 @@ pub async fn update_$tabName(req: $structName) -> AppResult<$responseName> { .get() .ok_or(anyhow::anyhow!("Database connection failed."))?; - let find = ${tabName.capitalizeFirstLetter()}::find_by_id(req.${primaryField.myManager.name}).one(db).await?; + let find = ${tabName.underlineToCamel.capitalizeFirstLetter()}::find_by_id(req.${primaryField.myManager.name}).one(db).await?; if find.is_none() { - return Err(anyhow::anyhow!("${tabName.capitalizeFirstLetter()} does not exist.").into()); + return Err(anyhow::anyhow!("${tabName.underlineToCamel.capitalizeFirstLetter()} does not exist.").into()); } let mut model: $tabName::ActiveModel = find.unwrap().into(); @@ -169,7 +169,7 @@ $fsb let db = DB .get() .ok_or(anyhow::anyhow!("Database connection failed."))?; - ${tabName.capitalizeFirstLetter()}::delete_by_id(${primaryField.myManager.name}).exec(db).await?; + ${tabName.underlineToCamel.capitalizeFirstLetter()}::delete_by_id(${primaryField.myManager.name}).exec(db).await?; Ok(()) } """.trimIndent() @@ -195,7 +195,7 @@ pub async fn ${tabName+"_find_all"}() -> AppResult> { let db = DB .get() .ok_or(anyhow::anyhow!("Database connection failed."))?; - let $tabName = ${tabName.capitalizeFirstLetter()}::find().all(db).await?; + let $tabName = ${tabName.underlineToCamel.capitalizeFirstLetter()}::find().all(db).await?; let res = $tabName .into_iter() .map(|r| $typeStructName { diff --git a/src/main/kotlin/shop/itbug/salvorstool/tool/Tools.kt b/src/main/kotlin/shop/itbug/salvorstool/tool/Tools.kt index fcce035..3b73d23 100644 --- a/src/main/kotlin/shop/itbug/salvorstool/tool/Tools.kt +++ b/src/main/kotlin/shop/itbug/salvorstool/tool/Tools.kt @@ -82,7 +82,7 @@ object Tools { }; use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter, Set, NotSet}; use crate::dtos::$tabName::*; - use crate::entities::prelude::${tabName.capitalizeFirstLetter()}; + use crate::entities::prelude::${tabName.underlineToCamel.capitalizeFirstLetter()}; """.trimIndent() }