Skip to content

Commit

Permalink
feature: custom plugin repo
Browse files Browse the repository at this point in the history
  • Loading branch information
popovanton0 committed Jul 4, 2024
1 parent 3bab5af commit c7dba98
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 23 deletions.
File renamed without changes.
36 changes: 36 additions & 0 deletions .github/workflows/publish-ide-plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build IDE plugin and create a GitHub Release

on:
workflow_dispatch:

jobs:
publish-gradle-plugin:
runs-on: ubuntu-latest
steps:
- name: Checkout project sources
uses: actions/checkout@v3

- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Fetch plugin version
id: print_version
run: ./gradlew printVersion

- name: Build plugin
run: ./gradlew buildKelpIdePlugin

- name: Release plugin
uses: ncipollo/release-action@v1
with:
tag: v${{ steps.print_version.outputs.plugin-version }}
artifacts: "./build/github-release/**"
generateReleaseNotes: true
allowUpdates: true
draft: true
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[![Introductory Medium Article](https://img.shields.io/badge/medium-article-grey?labelColor=black&logo=medium&logoColor=white&link=https://proandroiddev.com/kelp-plugin-for-android-studio-4374127939aa)](https://proandroiddev.com/kelp-plugin-for-android-studio-4374127939aa)
![License](https://img.shields.io/github/license/ozontech/Kelp?color=blue)
[![Gradle Plugin Portal](https://img.shields.io/maven-metadata/v/https/plugins.gradle.org/m2/ru/ozon/kelp/ru.ozon.kelp.gradle.plugin/maven-metadata.xml.svg?colorB=007ec6&label=gradle%20plugin)](https://plugins.gradle.org/plugin/ru.ozon.kelp)
[![Gradle Plugin Portal](https://img.shields.io/gradle-plugin-portal/v/ru.ozon.kelp?color=green&label=Gradle%20Plugin%20Portal&logo=gradle)](https://plugins.gradle.org/plugin/ru.ozon.kelp)

Kelp is an Android Studio plugin that enhances support for **custom design systems** written using Jetpack Compose.

Expand Down
77 changes: 55 additions & 22 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import dev.bmac.gradle.intellij.UpdateXmlTask
import org.jetbrains.changelog.Changelog
import org.jetbrains.changelog.markdownToHTML
import org.jetbrains.intellij.platform.gradle.tasks.BuildPluginTask
import org.jetbrains.intellij.platform.gradle.tasks.CustomRunIdeTask

fun properties(key: String) = providers.gradleProperty(key)
Expand All @@ -13,6 +14,7 @@ plugins {
alias(libs.plugins.qodana)
alias(libs.plugins.kover)
alias(libs.plugins.serialization)
alias(libs.plugins.intellijPluginUploader)
}

group = properties("pluginGroup").get()
Expand Down Expand Up @@ -55,6 +57,29 @@ kotlin {
jvmToolchain(17)
}

val kelpPluginDescription = providers.fileContents(layout.projectDirectory.file("README.md")).asText.map {
val start = "-- Plugin description --"
val end = "-- Plugin description 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 kelpChangeNotes = properties("pluginVersion").map { pluginVersion ->
with(changelog) {
renderItem(
(getOrNull(pluginVersion) ?: getUnreleased())
.withHeader(false)
.withEmptySections(false),
Changelog.OutputType.HTML,
)
}
}

// Configure IntelliJ Platform Gradle Plugin - read more: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-extension.html
intellijPlatform {
buildSearchableOptions = false
Expand All @@ -63,30 +88,11 @@ intellijPlatform {
version = properties("pluginVersion")

// Extract the -- Plugin description -- section from README.md and provide for the plugin's manifest
description = providers.fileContents(layout.projectDirectory.file("README.md")).asText.map {
val start = "-- Plugin description --"
val end = "-- Plugin description 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)
}
}
description = kelpPluginDescription

val changelog = project.changelog // local variable for configuration cache compatibility
// Get the latest available change notes from the changelog file
changeNotes = properties("pluginVersion").map { pluginVersion ->
with(changelog) {
renderItem(
(getOrNull(pluginVersion) ?: getUnreleased())
.withHeader(false)
.withEmptySections(false),
Changelog.OutputType.HTML,
)
}
}
changeNotes = kelpChangeNotes.get()

ideaVersion {
sinceBuild = properties("pluginSinceBuild")
Expand Down Expand Up @@ -127,3 +133,30 @@ tasks {
systemProperty("jb.consents.confirmation.enabled", "false")
}
}

val toGitHubReleaseDir = project.layout.buildDirectory.dir("github-release")

val updateLocalPluginXmlTask = tasks.register<UpdateXmlTask>("updateLocalPluginXml") {
pluginName = properties("pluginName")
pluginId = properties("pluginGroup")
version = properties("pluginVersion")
pluginDescription = kelpPluginDescription
sinceBuild = properties("pluginSinceBuild")
changeNotes = kelpChangeNotes.get()

updateFile = toGitHubReleaseDir.map { it.file("updatePlugins.xml") }
downloadUrl = "${properties("pluginRepositoryUrl").get()}/releases/latest/download/${pluginName.get()}-${version.get()}.zip"
}

tasks.register<Copy>("buildKelpIdePlugin") {
dependsOn(updateLocalPluginXmlTask)
from(project.tasks.named<BuildPluginTask>("buildPlugin").flatMap { it.archiveFile })
into(toGitHubReleaseDir)
}

tasks.register("printVersion") {
inputs.property("version", project.version)
doLast {
exec { commandLine("echo \"plugin-version=${inputs.properties.values.first()}\" >> \$GITHUB_OUTPUT") }
}
}
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ intelliJPlatform = "2.0.0-beta7"
qodana = "2023.3.2"
kover = "0.7.6"
serialization = "1.6.3"
intellijPluginUploader = "1.3.5"

[libraries]
annotations = { group = "org.jetbrains", name = "annotations", version.ref = "annotations" }
Expand All @@ -21,3 +22,4 @@ kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" }
qodana = { id = "org.jetbrains.qodana", version.ref = "qodana" }
serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
intellijPluginUploader = { id = "dev.bmac.intellij.plugin-uploader", version.ref = "intellijPluginUploader" }

0 comments on commit c7dba98

Please sign in to comment.