From 1b2660f7a5aeba785a39be7f2bc93f07da47674b Mon Sep 17 00:00:00 2001 From: Jan Skrasek Date: Sat, 14 Dec 2024 23:21:52 +0100 Subject: [PATCH] update plugin setup --- .github/workflows/build.yml | 200 +++++++++++++++---------- .github/workflows/release.yml | 6 +- .gitignore | 1 + build.gradle.kts | 125 +++++++++++----- gradle.properties | 6 +- src/main/resources/META-INF/plugin.xml | 2 - 6 files changed, 218 insertions(+), 122 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7a2a169..efecdac 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,46 +1,45 @@ name: Build - on: - # Trigger the workflow on pushes to only the 'main' branch (this avoids duplicate checks being run e.g. for dependabot pull requests) + # Trigger the workflow on pushes to only the 'main' branch (this avoids duplicate checks being run e.g., for dependabot pull requests) push: - branches: [main] + branches: [ main ] # Trigger the workflow on any pull request pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + jobs: - # Run Gradle Wrapper Validation Action to verify the wrapper's checksum - gradleValidation: - name: Gradle Wrapper + # Prepare environment and build the plugin + build: + name: Build runs-on: ubuntu-latest + outputs: + version: ${{ steps.properties.outputs.version }} + changelog: ${{ steps.properties.outputs.changelog }} + pluginVerifierHomeDir: ${{ steps.properties.outputs.pluginVerifierHomeDir }} steps: - # Check out current repository + # Check out the current repository - name: Fetch Sources uses: actions/checkout@v4 # Validate wrapper - name: Gradle Wrapper Validation - uses: gradle/wrapper-validation-action@v3 + uses: gradle/actions/wrapper-validation@v3 - # Run verifyPlugin and test Gradle tasks - test: - name: Test - needs: gradleValidation - runs-on: ubuntu-latest - steps: - - # Check out current repository - - name: Fetch Sources - uses: actions/checkout@v4 - - # Setup Java environment for the next steps + # Set up Java environment for the next steps - name: Setup Java uses: actions/setup-java@v4 with: distribution: zulu java-version: 17 - cache: gradle + + # Setup Gradle + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 # Set environment variables - name: Export Properties @@ -48,94 +47,142 @@ jobs: shell: bash run: | PROPERTIES="$(./gradlew properties --console=plain -q)" - IDE_VERSIONS="$(echo "$PROPERTIES" | grep "^pluginVerifierIdeVersions:" | base64)" + VERSION="$(echo "$PROPERTIES" | grep "^version:" | cut -f2- -d ' ')" + CHANGELOG="$(./gradlew getChangelog --unreleased --no-header --console=plain -q)" - echo "::set-output name=ideVersions::$IDE_VERSIONS" - echo "::set-output name=pluginVerifierHomeDir::~/.pluginVerifier" + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "pluginVerifierHomeDir=~/.pluginVerifier" >> $GITHUB_OUTPUT + + echo "changelog<> $GITHUB_OUTPUT + echo "$CHANGELOG" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT - # Cache Plugin Verifier IDEs - - name: Setup Plugin Verifier IDEs Cache - uses: actions/cache@v4 + # Build plugin + - name: Build plugin + run: ./gradlew buildPlugin + + # Prepare plugin archive content for creating artifact + - name: Prepare Plugin Artifact + id: artifact + shell: bash + run: | + cd ${{ github.workspace }}/build/distributions + FILENAME=`ls *.zip` + unzip "$FILENAME" -d content + + echo "filename=${FILENAME:0:-4}" >> $GITHUB_OUTPUT + + # Store already-built plugin as an artifact for downloading + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ steps.artifact.outputs.filename }} + path: ./build/distributions/content/*/* + + # Run tests and upload a code coverage report + test: + name: Test + needs: [ build ] + runs-on: ubuntu-latest + steps: + + # Check out the current repository + - name: Fetch Sources + uses: actions/checkout@v4 + + # Set up Java environment for the next steps + - name: Setup Java + uses: actions/setup-java@v4 with: - path: ${{ steps.properties.outputs.pluginVerifierHomeDir }}/ides - key: ${{ runner.os }}-plugin-verifier-${{ steps.properties.outputs.ideVersions }} + distribution: zulu + java-version: 17 + + # Setup Gradle + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 # Run tests - name: Run Tests - run: ./gradlew test + run: ./gradlew check - # Run verifyPlugin Gradle task - - name: Verify Plugin - run: ./gradlew verifyPlugin + # Collect Tests Result of failed tests + - name: Collect Tests Result + if: ${{ failure() }} + uses: actions/upload-artifact@v4 + with: + name: tests-result + path: ${{ github.workspace }}/build/reports/tests - # Run IntelliJ Plugin Verifier action using GitHub Action - - name: Run Plugin Verifier - run: ./gradlew runPluginVerifier -Pplugin.verifier.home.dir=${{ steps.properties.outputs.pluginVerifierHomeDir }} + # Upload the Kover report to CodeCov + - name: Upload Code Coverage Report + uses: codecov/codecov-action@v4 + with: + files: ${{ github.workspace }}/build/reports/kover/report.xml - # Build plugin with buildPlugin Gradle task and provide the artifact for the next workflow jobs - # Requires test job to be passed - build: - name: Build - needs: test + # Run plugin structure verification along with IntelliJ Plugin Verifier + verify: + name: Verify plugin + needs: [ build ] runs-on: ubuntu-latest - outputs: - version: ${{ steps.properties.outputs.version }} - changelog: ${{ steps.properties.outputs.changelog }} steps: - # Check out current repository + # Free GitHub Actions Environment Disk Space + - name: Maximize Build Space + uses: jlumbroso/free-disk-space@main + with: + tool-cache: false + large-packages: false + + # Check out the current repository - name: Fetch Sources uses: actions/checkout@v4 - # Setup Java environment for the next steps + # Set up Java environment for the next steps - name: Setup Java uses: actions/setup-java@v4 with: distribution: zulu java-version: 17 - # Set environment variables - - name: Export Properties - id: properties - shell: bash - run: | - PROPERTIES="$(./gradlew properties --console=plain -q)" - 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'}" + # Setup Gradle + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 - echo "::set-output name=version::$VERSION" - echo "::set-output name=name::$NAME" - echo "::set-output name=changelog::$CHANGELOG" + # Cache Plugin Verifier IDEs + - name: Setup Plugin Verifier IDEs Cache + uses: actions/cache@v4 + with: + path: ${{ needs.build.outputs.pluginVerifierHomeDir }}/ides + key: plugin-verifier-${{ hashFiles('build/listProductsReleases.txt') }} - # Build artifact using buildPlugin Gradle task - - name: Build Plugin - run: ./gradlew buildPlugin + # Run Verify Plugin task and IntelliJ Plugin Verifier tool + - name: Run Plugin Verification tasks + run: ./gradlew verifyPlugin -Dplugin.verifier.home.dir=${{ needs.build.outputs.pluginVerifierHomeDir }} - # Store built plugin as an artifact for downloading - - name: Upload artifacts + # Collect Plugin Verifier Result + - name: Collect Plugin Verifier Result + if: ${{ always() }} uses: actions/upload-artifact@v4 with: - name: "${{ steps.properties.outputs.name }} - ${{ steps.properties.outputs.version }}" - path: ./build/distributions/* + name: pluginVerifier-result + path: ${{ github.workspace }}/build/reports/pluginVerifier # Prepare a draft release for GitHub Releases page for the manual verification # If accepted and published, release workflow would be triggered releaseDraft: - name: Release Draft + name: Release draft if: github.event_name != 'pull_request' - needs: build + needs: [ build, test, verify ] runs-on: ubuntu-latest + permissions: + contents: write steps: - # Check out current repository + # Check out the current repository - name: Fetch Sources uses: actions/checkout@v4 - # 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,12 +191,15 @@ 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 }} run: | - gh release create v${{ needs.build.outputs.version }} \ + gh release create "v${{ needs.build.outputs.version }}" \ --draft \ --title "v${{ needs.build.outputs.version }}" \ - --notes "${{ needs.build.outputs.changelog }}" + --notes "$(cat << 'EOM' + ${{ needs.build.outputs.changelog }} + EOM + )" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6fe8ac1..1c6d300 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,12 +18,12 @@ jobs: with: ref: ${{ github.event.release.tag_name }} - # Setup Java 11 environment for the next steps + # Setup Java environment for the next steps - name: Setup Java uses: actions/setup-java@v4 with: distribution: zulu - java-version: 11 + java-version: 17 cache: gradle # Update Unreleased section with the current release note @@ -37,7 +37,7 @@ jobs: - name: Publish Plugin env: PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }} - run: ./gradlew publishPlugin + run: ./gradlew :publishPlugin # Upload artifact as a release asset - name: Upload Release Asset diff --git a/.gitignore b/.gitignore index 64f02f7..bf130d2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /out /build /.gradle +/.intellijPlatform diff --git a/build.gradle.kts b/build.gradle.kts index ddba389..8d7039c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ fun properties(key: String) = project.findProperty(key).toString() plugins { id("org.jetbrains.kotlin.jvm") version "2.1.0" - id("org.jetbrains.intellij") version "1.17.4" + id("org.jetbrains.intellij.platform") version "2.2.1" id("org.jetbrains.changelog") version "2.2.1" } @@ -15,6 +15,9 @@ version = properties("pluginVersion") repositories { mavenCentral() + intellijPlatform { + defaultRepositories() + } } kotlin { @@ -22,15 +25,71 @@ kotlin { } dependencies { - implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + intellijPlatform { + phpstorm("2023.3") + bundledPlugins(listOf("com.jetbrains.php")) + + pluginVerifier() + zipSigner() + } } -intellij { - type.set("PS") - version.set("PS-2023.3") - plugins.set(listOf("com.jetbrains.php")) - pluginName.set(properties("pluginName")) - updateSinceUntilBuild.set(false) +intellijPlatform { + pluginConfiguration { + version = providers.gradleProperty("pluginVersion") + + description = providers.fileContents(layout.projectDirectory.file("readme.md")).asText.map { + val start = "" + val end = "" + + with(it.lines()) { + if (!containsAll(listOf(start, end))) { + throw GradleException("Plugin description section not found in readme.md:\n$start ... $end") + } + subList(indexOf(start) + 1, indexOf(end)).joinToString("\n").let(::markdownToHTML) + } + } + + val changelog = project.changelog // local variable for configuration cache compatibility + // Get the latest available change notes from the changelog file + changeNotes = providers.gradleProperty("pluginVersion").map { pluginVersion -> + with(changelog) { + renderItem( + (getOrNull(pluginVersion) ?: getUnreleased()) + .withHeader(false) + .withEmptySections(false), + Changelog.OutputType.HTML, + ) + } + } + + ideaVersion { + sinceBuild = "233" + untilBuild = "*.*.*" + } + } + + publishing { + token = providers.environmentVariable("PUBLISH_TOKEN") + // 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 = providers.gradleProperty("pluginVersion") + .map { + listOf( + it.substringAfter('-', "") + .substringBefore('.') + .ifEmpty { "default" } + ) + } + } + + pluginVerification { + freeArgs.add("-mute TemplateWordInPluginId") + ides { + recommended() + } + } } changelog { @@ -43,38 +102,28 @@ tasks { buildSearchableOptions { enabled = false } - - - patchPluginXml { - version.set(properties("pluginVersion")) - - pluginDescription.set( - File(projectDir, "readme.md").readText().lines().run { - val start = "" - val end = "" - - if (!containsAll(listOf(start, end))) { - throw GradleException("Plugin description section not found in README.md:\n$start ... $end") - } - subList(indexOf(start) + 1, indexOf(end)) - }.joinToString("\n").run { markdownToHTML(this) } - ) - - changeNotes.set(provider { changelog.renderItem(changelog.getLatest(), Changelog.OutputType.HTML) }) + publishPlugin { + dependsOn(patchChangelog) } +} - runPluginVerifier { - ideVersions.set( - properties("pluginVerifierIdeVersions").split(',').map(String::trim).filter(String::isNotEmpty) - ) - } +intellijPlatformTesting { + runIde { + register("runIdeForUiTests") { + task { + jvmArgumentProviders += CommandLineArgumentProvider { + listOf( + "-Drobot-server.port=8082", + "-Dide.mac.message.dialogs.as.sheets=false", + "-Djb.privacy.policy.text=", + "-Djb.consents.confirmation.enabled=false", + ) + } + } - 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 - // 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())) + plugins { + robotServerPlugin() + } + } } } diff --git a/gradle.properties b/gradle.properties index d888e08..2565cbc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,5 @@ pluginGroup = org.nextras.orm.intellij pluginName = Nextras Orm Plugin -pluginVersion = 0.9.1 +pluginVersion = 2.0.0 -# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl -# See https://jb.gg/intellij-platform-builds-list for available build versions. -pluginVerifierIdeVersions = PS-2022.3 +kotlin.stdlib.default.dependency = false diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index bbfc20a..a49b0a0 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -6,8 +6,6 @@ com.intellij.modules.platform com.jetbrains.php - -