diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 9be205f..f6b0d11 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -14,4 +14,4 @@ updates: directory: "/" target-branch: "next" schedule: - interval: "daily" + interval: "daily" \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 498cf72..9b9ff70 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -# GitHub Actions Workflow created for testing and preparing the plugin release in following steps: +# GitHub Actions Workflow is created for testing and preparing the plugin release in the following steps: # - validate Gradle Wrapper, # - run 'test' and 'verifyPlugin' tasks, # - run Qodana inspections, @@ -33,21 +33,27 @@ jobs: changelog: ${{ steps.properties.outputs.changelog }} steps: + # Free GitHub Actions Environment Disk Space + - name: Maximize Build Space + run: | + sudo rm -rf /usr/share/dotnet + sudo rm -rf /usr/local/lib/android + sudo rm -rf /opt/ghc + # Check out current repository - name: Fetch Sources - uses: actions/checkout@v2.4.0 + uses: actions/checkout@v3 # Validate wrapper - name: Gradle Wrapper Validation - uses: gradle/wrapper-validation-action@v1.0.4 + uses: gradle/wrapper-validation-action@v1.0.5 # Setup Java 11 environment for the next steps - name: Setup Java - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: distribution: zulu java-version: 11 - cache: gradle # Set environment variables - name: Export Properties @@ -58,32 +64,38 @@ jobs: VERSION="$(echo "$PROPERTIES" | grep "^version:" | cut -f2- -d ' ')" NAME="$(echo "$PROPERTIES" | grep "^pluginName:" | cut -f2- -d ' ')" CHANGELOG="$(./gradlew getChangelog --unreleased --no-header --console=plain -q)" - CHANGELOG="${CHANGELOG//'%'/'%25'}" - CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" - CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" - echo "::set-output name=version::$VERSION" - echo "::set-output name=name::$NAME" - echo "::set-output name=changelog::$CHANGELOG" - echo "::set-output name=pluginVerifierHomeDir::~/.pluginVerifier" + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "name=$NAME" >> $GITHUB_OUTPUT + echo "pluginVerifierHomeDir=~/.pluginVerifier" >> $GITHUB_OUTPUT + + echo "changelog<> $GITHUB_OUTPUT + echo "$CHANGELOG" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT ./gradlew listProductsReleases # prepare list of IDEs for Plugin Verifier # Run tests - name: Run Tests - run: ./gradlew test + run: ./gradlew check # Collect Tests Result of failed tests - name: Collect Tests Result if: ${{ failure() }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: tests-result path: ${{ github.workspace }}/build/reports/tests + # Upload Kover report to CodeCov + - name: Upload Code Coverage Report + uses: codecov/codecov-action@v3 + with: + files: ${{ github.workspace }}/build/reports/kover/xml/report.xml + # Cache Plugin Verifier IDEs - name: Setup Plugin Verifier IDEs Cache - uses: actions/cache@v2.1.7 + uses: actions/cache@v3 with: path: ${{ steps.properties.outputs.pluginVerifierHomeDir }}/ides key: plugin-verifier-${{ hashFiles('build/listProductsReleases.txt') }} @@ -93,16 +105,16 @@ jobs: run: ./gradlew runPluginVerifier -Pplugin.verifier.home.dir=${{ steps.properties.outputs.pluginVerifierHomeDir }} # Collect Plugin Verifier Result -# - name: Collect Plugin Verifier Result -# if: ${{ always() }} -# uses: actions/upload-artifact@v2 -# with: -# name: pluginVerifier-result -# path: ${{ github.workspace }}/build/reports/pluginVerifier + - name: Collect Plugin Verifier Result + if: ${{ always() }} + uses: actions/upload-artifact@v3 + with: + name: pluginVerifier-result + path: ${{ github.workspace }}/build/reports/pluginVerifier # Run Qodana inspections # - name: Qodana - Code Inspection -# uses: JetBrains/qodana-action@v4.2.5 +# uses: JetBrains/qodana-action@v2022.3.0 # Prepare plugin archive content for creating artifact - name: Prepare Plugin Artifact @@ -113,11 +125,11 @@ jobs: FILENAME=`ls *.zip` unzip "$FILENAME" -d content - echo "::set-output name=filename::${FILENAME:0:-4}" + echo "filename=${FILENAME:0:-4}" >> $GITHUB_OUTPUT # Store already-built plugin as an artifact for downloading - name: Upload artifact - uses: actions/upload-artifact@v2.2.4 + uses: actions/upload-artifact@v3 with: name: ${{ steps.artifact.outputs.filename }} path: ./build/distributions/content/*/* @@ -129,13 +141,15 @@ jobs: if: github.event_name != 'pull_request' needs: build runs-on: ubuntu-latest + permissions: + contents: write steps: # Check out current repository - name: Fetch Sources - uses: actions/checkout@v2.4.0 + uses: actions/checkout@v3 - # Remove old release drafts by using the curl request for the available releases with draft flag + # Remove old release drafts by using the curl request for the available releases with a draft flag - name: Remove Old Release Drafts env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -144,7 +158,7 @@ jobs: --jq '.[] | select(.draft == true) | .id' \ | xargs -I '{}' gh api -X DELETE repos/{owner}/{repo}/releases/{} - # Create new release draft - which is not publicly visible and requires manual acceptance + # Create a new release draft which is not publicly visible and requires manual acceptance - name: Create Release Draft env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -155,4 +169,4 @@ jobs: --notes "$(cat << 'EOM' ${{ needs.build.outputs.changelog }} EOM - )" + )" \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0bcf2d5..24cac2d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,5 +1,6 @@ -# GitHub Actions Workflow created for handling the release process based on the draft release prepared -# with the Build workflow. Running the publishPlugin task requires the PUBLISH_TOKEN secret provided. +# 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: @@ -12,21 +13,23 @@ jobs: release: name: Publish Plugin runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write steps: # Check out current repository - name: Fetch Sources - uses: actions/checkout@v2.4.0 + uses: actions/checkout@v3 with: ref: ${{ github.event.release.tag_name }} # Setup Java 11 environment for the next steps - name: Setup Java - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: distribution: zulu java-version: 11 - cache: gradle # Set environment variables - name: Export Properties @@ -42,7 +45,7 @@ jobs: CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" - echo "::set-output name=changelog::$CHANGELOG" + echo "changelog=$CHANGELOG" >> $GITHUB_OUTPUT # Update Unreleased section with the current release note - name: Patch Changelog @@ -56,6 +59,9 @@ jobs: - 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 # Upload artifact as a release asset @@ -72,6 +78,7 @@ jobs: 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" @@ -79,9 +86,13 @@ jobs: 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" \ + || true gh pr create \ --title "Changelog update - \`$VERSION\`" \ --body "Current pull request contains patched \`CHANGELOG.md\` file for the \`$VERSION\` version." \ - --base main \ - --head $BRANCH + --label "$LABEL" \ + --head $BRANCH \ No newline at end of file diff --git a/.github/workflows/run-ui-tests.yml b/.github/workflows/run-ui-tests.yml index 3108cf1..3b9001f 100644 --- a/.github/workflows/run-ui-tests.yml +++ b/.github/workflows/run-ui-tests.yml @@ -33,15 +33,14 @@ jobs: # Check out current repository - name: Fetch Sources - uses: actions/checkout@v2.4.0 + uses: actions/checkout@v3 # Setup Java 11 environment for the next steps - name: Setup Java - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: distribution: zulu java-version: 11 - cache: gradle # Run IDEA prepared for UI testing - name: Run IDE @@ -49,7 +48,7 @@ jobs: # Wait for IDEA to be started - name: Health Check - uses: jtalk/url-health-check-action@v2 + uses: jtalk/url-health-check-action@v3 with: url: http://127.0.0.1:8082 max-attempts: 15 @@ -57,4 +56,4 @@ jobs: # Run tests - name: Tests - run: ./gradlew test + run: ./gradlew test \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 21df7b7..5bfd5a6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,5 @@ +import org.jetbrains.changelog.Changelog import org.jetbrains.changelog.markdownToHTML -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile fun properties(key: String) = project.findProperty(key).toString() @@ -7,13 +7,15 @@ plugins { // Java support id("java") // Kotlin support - id("org.jetbrains.kotlin.jvm") version "1.6.10" + id("org.jetbrains.kotlin.jvm") version "1.8.0" // Gradle IntelliJ Plugin - id("org.jetbrains.intellij") version "1.7.0" + id("org.jetbrains.intellij") version "1.12.0" // Gradle Changelog Plugin - id("org.jetbrains.changelog") version "1.3.1" + id("org.jetbrains.changelog") version "2.0.0" // Gradle Qodana Plugin id("org.jetbrains.qodana") version "0.1.13" + // Gradle Kover Plugin + id("org.jetbrains.kotlinx.kover") version "0.6.1" } group = properties("pluginGroup") @@ -21,16 +23,15 @@ version = properties("pluginVersion") // Configure project's dependencies repositories { - maven { - setUrl("https://maven.aliyun.com/repository/public") - } mavenCentral() } -dependencies { -// implementation("ws.vinta:pangu:1.1.0") + +// Set the JVM language level used to build the project. Use Java 11 for 2020.3+, and Java 17 for 2022.2+. +kotlin { + jvmToolchain(11) } -// Configure Gradle IntelliJ Plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin +// Configure Gradle IntelliJ Plugin - read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html intellij { pluginName.set(properties("pluginName")) version.set(properties("platformVersion")) @@ -42,30 +43,24 @@ intellij { // Configure Gradle Changelog Plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin changelog { - version.set(properties("pluginVersion")) groups.set(emptyList()) + repositoryUrl.set(properties("pluginRepositoryUrl")) } // Configure Gradle Qodana Plugin - read more: https://github.com/JetBrains/gradle-qodana-plugin qodana { - cachePath.set(projectDir.resolve(".qodana").canonicalPath) - reportPath.set(projectDir.resolve("build/reports/inspections").canonicalPath) + cachePath.set(file(".qodana").canonicalPath) + reportPath.set(file("build/reports/inspections").canonicalPath) saveReport.set(true) showReport.set(System.getenv("QODANA_SHOW_REPORT")?.toBoolean() ?: false) } -tasks { - // Set the JVM compatibility versions - properties("javaVersion").let { - withType { - sourceCompatibility = it - targetCompatibility = it - } - withType { - kotlinOptions.jvmTarget = it - } - } +// Configure Gradle Kover Plugin - read more: https://github.com/Kotlin/kotlinx-kover#configuration +kover.xmlReport { + onCheck.set(true) +} +tasks { wrapper { gradleVersion = properties("gradleVersion") } @@ -85,14 +80,18 @@ tasks { throw GradleException("Plugin description section not found in README.md:\n$start ... $end") } subList(indexOf(start) + 1, indexOf(end)) - }.joinToString("\n").run { markdownToHTML(this) } + }.joinToString("\n").let { markdownToHTML(it) } ) // Get the latest available change notes from the changelog file changeNotes.set(provider { - changelog.run { - getOrNull(properties("pluginVersion")) ?: getLatest() - }.toHTML() + with(changelog) { + renderItem( + getOrNull(properties("pluginVersion")) + ?: runCatching { getLatest() }.getOrElse { getUnreleased() }, + Changelog.OutputType.HTML, + ) + } }) } @@ -114,9 +113,9 @@ tasks { publishPlugin { dependsOn("patchChangelog") token.set(System.getenv("PUBLISH_TOKEN")) - // pluginVersion is based on the SemVer (https://semver.org) and supports pre-release labels, like 2.1.7-alpha.3 + // The pluginVersion is based on the SemVer (https://semver.org) and supports pre-release labels, like 2.1.7-alpha.3 // Specify pre-release label to publish the plugin in a custom Release Channel automatically. Read more: // https://plugins.jetbrains.com/docs/intellij/deployment.html#specifying-a-release-channel channels.set(listOf(properties("pluginVersion").split('-').getOrElse(1) { "default" }.split('.').first())) } -} +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index f85bf79..b31c78b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ pluginVersion = 1.1.3 # See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html # for insight into build numbers and IntelliJ Platform versions. -pluginSinceBuild = 193.5233.102 +pluginSinceBuild = 212.4746.92 pluginUntilBuild = 223.* # IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties @@ -24,9 +24,13 @@ platformPlugins = javaVersion = 11 # Gradle Releases -> https://github.com/gradle/gradle/releases -gradleVersion = 7.4 +gradleVersion = 7.6 # Opt-out flag for bundling Kotlin standard library. # See https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library for details. # suppress inspection "UnusedProperty" kotlin.stdlib.default.dependency = false + +# Enable Gradle Configuration Cache -> https://docs.gradle.org/current/userguide/configuration_cache.html +# suppress inspection "UnusedProperty" +org.gradle.unsafe.configuration-cache = true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41dfb87..ae04661 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/com/lilittlecat/plugin/listener/PanguFormatActionListener.java b/src/main/java/com/lilittlecat/plugin/listener/PanguFormatActionListener.java index 6d6af5b..e0cf201 100644 --- a/src/main/java/com/lilittlecat/plugin/listener/PanguFormatActionListener.java +++ b/src/main/java/com/lilittlecat/plugin/listener/PanguFormatActionListener.java @@ -4,7 +4,7 @@ import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.actionSystem.AnActionResult; import com.intellij.openapi.actionSystem.ex.AnActionListener; import com.lilittlecat.plugin.setting.PanguFormatSettingsState; import org.jetbrains.annotations.NotNull; @@ -18,7 +18,7 @@ public class PanguFormatActionListener implements AnActionListener { @Override - public void afterActionPerformed(@NotNull AnAction action, @NotNull DataContext dataContext, @NotNull AnActionEvent event) { + public void afterActionPerformed(@NotNull AnAction action, @NotNull AnActionEvent event, @NotNull AnActionResult result) { if (action.getClass().equals(ReformatCodeAction.class) && PanguFormatSettingsState.getInstance().isPanguFormatWhenReformatCode) { // pangu format in reformat code action ActionManager.getInstance().getAction("Pangu.Format.Editor").actionPerformed(event); diff --git a/src/main/java/com/lilittlecat/plugin/pangu/Pangu.java b/src/main/java/com/lilittlecat/plugin/pangu/Pangu.java index c670f14..57fa2ec 100644 --- a/src/main/java/com/lilittlecat/plugin/pangu/Pangu.java +++ b/src/main/java/com/lilittlecat/plugin/pangu/Pangu.java @@ -98,8 +98,9 @@ public String spacingText(String text) { Matcher qcMatcher = QUOTE_CJK.matcher(text); text = qcMatcher.replaceAll("$1 $2"); - Matcher fixQuoteMatcher = FIX_QUOTE.matcher(text); - text = fixQuoteMatcher.replaceAll("$1$3$5"); + // todo, ignore fix quote for now, consider the content between quotes is not meant to be modified +// Matcher fixQuoteMatcher = FIX_QUOTE.matcher(text); +// text = fixQuoteMatcher.replaceAll("$1$3$5"); // CJK and brackets String oldText = text; @@ -132,6 +133,9 @@ public String spacingText(String text) { Matcher acMatcher = ANSG_CJK.matcher(text); text = acMatcher.replaceAll("$1 $2"); + // replace the first `//some comment` of a line to `// some comment` todo add more comment patterns from different languages + text = text.replaceAll("(?<=^|\\s)//(\\S.*)", "// $1"); + return text; } @@ -172,7 +176,6 @@ public void spacingFile(File inputFile, File outputFile) throws IOException { } - /** * format text * @@ -188,7 +191,6 @@ public String formatText(String text) { } - /** * split text by line break * @@ -196,7 +198,8 @@ public String formatText(String text) { * @return list of text */ private List splitText(String text) { - return new ArrayList<>(Arrays.asList(text.split("\n"))); + // split text by line break, keep \n in the end of file + return Arrays.asList(text.split("(?<=\n)")); } /** @@ -210,9 +213,6 @@ private String joinText(List text) { final Iterator iterator = text.iterator(); while (iterator.hasNext()) { stringBuilder.append(iterator.next()); - if (iterator.hasNext()) { - stringBuilder.append("\n"); - } } return stringBuilder.toString(); }