From 56fb59b891fdcae8742132af17bc227d41c1b33b Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Tue, 30 Apr 2024 23:09:08 +0300 Subject: [PATCH] try publishing EAPs with CI --- .github/workflows/check.yml | 7 ++- .github/workflows/publish-eap.yml | 82 +++++++++++++++++++++++++++++++ build.gradle.kts | 40 ++++++++++++++- 3 files changed, 124 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/publish-eap.yml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 281ebdfd8..3c1cf13ef 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -1,4 +1,4 @@ -name: check +name: Check on: push: @@ -10,10 +10,9 @@ jobs: tests: strategy: matrix: - os: [ ubuntu-latest ] - gradle-properties-version: [ 232, 233 ] + gradle-properties-version: [ 232, 233, 241 ] - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest env: ORG_GRADLE_PROJECT_shortPlatformVersion: ${{ matrix.gradle-properties-version }} diff --git a/.github/workflows/publish-eap.yml b/.github/workflows/publish-eap.yml new file mode 100644 index 000000000..cdeda3c28 --- /dev/null +++ b/.github/workflows/publish-eap.yml @@ -0,0 +1,82 @@ +name: Publish EAP + +on: + # only works on 'master' branch as it is a default branch + workflow_run: + workflows: [ Check ] + types: + - completed + branches: + - master + +jobs: + check-for-tests-success: + runs-on: ubuntu-latest + permissions: + actions: write + + steps: + - name: Early exit if tests wasn't successful + if: ${{ github.event.workflow_run.conclusion != 'success' }} + run: | + gh run cancel ${{ github.run_id }} + gh run watch ${{ github.run_id }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + + publish-eap-channel: + needs: [ check-for-tests-success ] + strategy: + matrix: + gradle-properties-version: [ 232, 233, 241 ] + + runs-on: ubuntu-latest + env: + ORG_GRADLE_PROJECT_shortPlatformVersion: ${{ matrix.gradle-properties-version }} + JB_PUB_TOKEN: ${{ secrets.JB_PUB_TOKEN }} + JB_PUB_CHANNEL: eap + + steps: + - uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'corretto' + java-version: 17 + + - name: Setup Gradle and dependencies + uses: gradle/actions/setup-gradle@v3.1.0 + with: + gradle-version: wrapper + cache-read-only: false + arguments: ":resolveDependencies -Pkotlin.incremental=false --no-daemon" + gradle-home-cache-excludes: | + caches/modules-2/files-2.1/com.jetbrains.intellij.pycharm + caches/modules-2/files-2.1/com.jetbrains.intellij.idea + caches/modules-2/files-2.1/com.jetbrains.intellij.clion + + - name: Build + uses: gradle/gradle-build-action@v2.7.0 + with: + gradle-version: wrapper + arguments: "assemble testClasses -Pkotlin.incremental=false --no-daemon --stacktrace" + gradle-home-cache-excludes: | + caches/modules-2/files-2.1/com.jetbrains.intellij.pycharm + caches/modules-2/files-2.1/com.jetbrains.intellij.idea + caches/modules-2/files-2.1/com.jetbrains.intellij.clion + + - name: Publish to EAP channel + uses: gradle/gradle-build-action@v2.7.0 + with: + gradle-version: wrapper + arguments: ":plugin:publishPlugin -Pkotlin.incremental=false --no-daemon --stacktrace" + gradle-home-cache-excludes: | + caches/modules-2/files-2.1/com.jetbrains.intellij.pycharm + caches/modules-2/files-2.1/com.jetbrains.intellij.idea + caches/modules-2/files-2.1/com.jetbrains.intellij.clion + + + + diff --git a/build.gradle.kts b/build.gradle.kts index ea1927b99..75380b89f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,9 +1,11 @@ import org.jetbrains.intellij.tasks.PrepareSandboxTask import org.jetbrains.intellij.tasks.RunPluginVerifierTask import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import java.io.ByteArrayOutputStream import java.util.* val publishingToken = System.getenv("JB_PUB_TOKEN") ?: null +val publishingChannel = System.getenv("JB_PUB_CHANNEL") ?: "default" // set by default in Github Actions val isCI = System.getenv("CI") != null @@ -11,9 +13,44 @@ fun prop(name: String): String = extra.properties[name] as? String ?: error("Property `$name` is not defined in gradle.properties for environment `$shortPlatformVersion`") +fun gitHash(): String { + val byteOut = ByteArrayOutputStream() + project.exec { + commandLine = "git rev-parse --short HEAD".split(" ") +// commandLine = "git rev-parse --abbrev-ref HEAD".split(" ") + standardOutput = byteOut + } + return String(byteOut.toByteArray()).trim().also { + if (it == "HEAD") + logger.warn("Unable to determine current branch: Project is checked out with detached head!") + } +} + +fun gitTimestamp(): String { + val byteOut = ByteArrayOutputStream() + project.exec { + commandLine = "git show --no-patch --format=%at HEAD".split(" ") +// commandLine = "git rev-parse --abbrev-ref HEAD".split(" ") + standardOutput = byteOut + } + return String(byteOut.toByteArray()).trim().also { + if (it == "HEAD") + logger.warn("Unable to determine current branch: Project is checked out with detached head!") + } +} + val shortPlatformVersion = prop("shortPlatformVersion") val codeVersion = "1.36.0" -val pluginVersion = "$codeVersion.$shortPlatformVersion" + +var pluginVersion = "$codeVersion.$shortPlatformVersion" +if (publishingChannel != "default") { + // timestamp of the commit with this eaps addition + val start = 1714498465 + val commitTimestamp = gitTimestamp().toInt() - start + val commitHash = gitHash() + pluginVersion = "$pluginVersion-$publishingChannel.$commitTimestamp-$commitHash" +} + val pluginGroup = "org.move" val javaVersion = JavaVersion.VERSION_17 val pluginJarName = "intellij-move-$pluginVersion" @@ -225,6 +262,7 @@ project(":plugin") { publishPlugin { token.set(publishingToken) + channels.set(listOf(publishingChannel)) } runIde { enabled = true }