Skip to content

Commit

Permalink
Merge pull request #72 from NixOS/buildupdate
Browse files Browse the repository at this point in the history
Revise Build Configuration
  • Loading branch information
JojOatXGME committed Mar 16, 2024
2 parents df0a323 + 2abeb9d commit 37d0ad6
Show file tree
Hide file tree
Showing 15 changed files with 272 additions and 111 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/wrapper-validation-action@v2

check:

Expand All @@ -35,15 +35,15 @@ jobs:
steps:
# Setup environment
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.jdk }}
distribution: temurin
# Setup caches and collect metadata
- name: Setup cache for Gradle and dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
Expand All @@ -55,7 +55,7 @@ jobs:
- name: Collect metadata for upcoming steps and jobs
run: ./gradlew --stacktrace metadata listProductsReleases
- name: Setup cache for IntelliJ Plugin Verifier
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.pluginVerifier/ides
Expand All @@ -74,21 +74,21 @@ jobs:
# Upload artifacts
- name: Upload build reports
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: reports-jdk${{matrix.jdk}}
path: build/reports/
if-no-files-found: ignore
- name: Upload build result
if: ${{ matrix.primary }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: build-result
path: build/distributions/
if-no-files-found: error
- name: Upload metadata
if: ${{ matrix.primary }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: metadata
path: build/metadata/
Expand All @@ -104,7 +104,7 @@ jobs:
steps:
# Remove old release drafts
- name: Remove old release drafts
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
script: |
const owner = context.repo.owner;
Expand All @@ -116,12 +116,12 @@ jobs:
}
# Download build artifacts
- name: Download build result
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: build-result
path: build/distributions/
- name: Download metadata
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: metadata
path: build/metadata/
Expand All @@ -134,7 +134,7 @@ jobs:
echo "zipname=$(basename "$(cat build/metadata/zipfile.txt)")" >> "$GITHUB_OUTPUT"
# Fail job if the release tag already exists and points to a different commit
- name: Check release tag
uses: actions/github-script@v6
uses: actions/github-script@v7
env:
TAG_NAME: v${{ steps.metadata.outputs.version }}
with:
Expand Down Expand Up @@ -167,7 +167,7 @@ jobs:
}
# Create GitHub release draft
- name: Create GitHub release draft
uses: actions/github-script@v6
uses: actions/github-script@v7
env:
TAG_NAME: v${{ steps.metadata.outputs.version }}
ZIP_FILE: ${{ steps.metadata.outputs.zipfile }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
steps:
# Setup environment
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
Expand All @@ -42,7 +42,7 @@ jobs:
fi
# Setup cache
- name: Setup cache for Gradle and dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
Expand All @@ -53,7 +53,7 @@ jobs:
${{hashFiles('gradle.properties', '**/*.gradle.kts')}}"
# Update files
- name: Obtain release notes
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
script: |
await require('.github/scripts/get-release-notes.js')({
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/publish-to-jetbrains.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ jobs:
steps:
# Setup environment
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
# Setup cache
- name: Setup cache for Gradle and dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
Expand All @@ -38,7 +38,7 @@ jobs:
${{hashFiles('gradle.properties', '**/*.gradle.kts')}}"
# Build and publish
- name: Obtain release notes
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
script: |
await require('.github/scripts/get-release-notes.js')({
Expand All @@ -57,7 +57,7 @@ jobs:
# Upload artifacts
- name: Upload build reports
if: steps.gradle-build.outcome == 'success' || steps.gradle-build.outcome == 'failure'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: build-reports
path: build/reports/
Expand Down
119 changes: 42 additions & 77 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import org.jetbrains.changelog.Changelog
import org.jetbrains.changelog.markdownToHTML
import org.jetbrains.grammarkit.tasks.GenerateLexerTask
import org.jetbrains.grammarkit.tasks.GenerateParserTask
import org.jetbrains.intellij.tasks.RunPluginVerifierTask

plugins {
// Java support
id("java")
// gradle-intellij-plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
id("org.jetbrains.intellij") version "1.16.0"
// gradle-changelog-plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
id("org.jetbrains.changelog") version "2.2.0"
// grammarkit - read more: https://github.com/JetBrains/gradle-grammar-kit-plugin
id("org.jetbrains.grammarkit") version "2022.3.2"
alias(libs.plugins.jetbrains.intellij)
alias(libs.plugins.jetbrains.changelog)
alias(libs.plugins.jetbrains.grammarkit)
id("local.bump-version")
id("local.jbr-guidance")
}

// Import variables from gradle.properties file
Expand All @@ -38,9 +34,9 @@ repositories {
}

dependencies {
testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation("org.junit.jupiter:junit-jupiter")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine")
testImplementation(platform(libs.junit5.bom))
testImplementation(libs.junit5.jupiter)
testRuntimeOnly(libs.junit5.vintage.engine)
}

// Configure gradle-intellij-plugin plugin.
Expand Down Expand Up @@ -77,30 +73,6 @@ sourceSets {
}
}

val tasksUsingDownloadedJbr = mutableListOf<Task>()
// Check https://github.com/gradle/gradle/issues/20151 if an alternative for deprecated buildFinished became available.
gradle.buildFinished {
val regex = Regex("""\.gradle/.*/jbr/.*/java\b""")
for (task in tasksUsingDownloadedJbr) {
if (task.state.failure?.cause?.message?.contains(regex) == true) {
logger.error("""
|
|! Info for users on NixOS:
|!
|! The JetBrains Runtime (JBR) downloaded by Gradle is not compatible with NixOS.
|! You may run the ‘:jbr’ task to configure the runtime of <nixpkgs> instead.
|! Alternatively, you may run the following command within the project directory.
|!
|! nix-build '<nixpkgs>' -A jetbrains.jdk -o jbr
|!
|! This will create a symlink to the package jetbrains.jdk of nixpkgs at
|! ${'$'}projectDir/jbr, which is automatically detected by future builds.
""".trimMargin())
break
}
}
}

tasks {
withType<JavaCompile> {
options.encoding = "UTF-8"
Expand All @@ -109,59 +81,45 @@ tasks {
options.encoding = "UTF-8"
}

task<Exec>("jbr") {
description = "Create a symlink to package jetbrains.jdk"
group = "build setup"
commandLine("nix-build", "<nixpkgs>", "-A", "jetbrains.jdk", "-o", "jbr")
}

withType<org.jetbrains.intellij.tasks.RunIdeBase> {
project.file("jbr/bin/java")
.takeIf { it.exists() }
?.let { projectExecutable = it.toString() }
?: tasksUsingDownloadedJbr.add(this)
}

withType<Test> {
systemProperty("idea.test.execution.policy", "org.nixos.idea.NixTestExecutionPolicy")
systemProperty("plugin.testDataPath", rootProject.rootDir.resolve("src/test/testData").path)
}

task("metadata") {
outputs.upToDateWhen { false }
doLast {
val dir = project.layout.buildDirectory.dir("metadata").get().asFile
dir.mkdirs()
dir.resolve("version.txt").writeText(pluginVersion)
dir.resolve("zipfile.txt").writeText(buildPlugin.get().archiveFile.get().toString())
dir.resolve("latest_changelog.md").writeText(with(changelog) {
task<MetadataTask>("metadata") {
outputDir = layout.buildDirectory.dir("metadata")
file("version.txt", pluginVersion)
file("zipfile.txt") { buildPlugin.get().archiveFile.get().toString() }
file("latest_changelog.md") {
with(changelog) {
renderItem(
(getOrNull(pluginVersion) ?: getUnreleased())
.withHeader(false)
.withEmptySections(false),
Changelog.OutputType.MARKDOWN
)
})
}
}
}

val generateNixLexer by registering(GenerateLexerTask::class) {
generateLexer {
sourceFile = file("src/main/lang/Nix.flex")
targetDir = "src/gen/java/org/nixos/idea/lang"
targetClass = "_NixLexer"
targetOutputDir = file("src/gen/java/org/nixos/idea/lang")
purgeOldFiles = true
}

val generateNixParser by registering(GenerateParserTask::class) {
generateParser {
sourceFile = file("src/main/lang/Nix.bnf")
targetRoot = "src/gen/java"
targetRootOutputDir = file("src/gen/java")
pathToParser = "/org/nixos/idea/lang/NixParser"
pathToPsiRoot = "/org/nixos/idea/psi"
purgeOldFiles = true
// Task :generateLexer deletes files generated by this task when executed afterward.
mustRunAfter(generateLexer)
}

compileJava {
dependsOn(generateNixLexer, generateNixParser)
dependsOn(generateLexer, generateParser)
}

test {
Expand All @@ -174,15 +132,19 @@ tasks {
untilBuild = pluginUntilBuild

// Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
pluginDescription = projectDir.resolve("README.md").readText().lines().run {
val start = "<!-- Plugin description -->"
val end = "<!-- Plugin description 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) }
pluginDescription = providers.provider {
projectDir.resolve("README.md").readText().lines()
.run {
val start = "<!-- Plugin description -->"
val end = "<!-- Plugin description 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) }
}

// Get the latest available change notes from the changelog file
changeNotes = provider {
Expand All @@ -199,13 +161,16 @@ tasks {

runPluginVerifier {
failureLevel = RunPluginVerifierTask.FailureLevel.ALL
// Version 1.364 seems to be broken and always complains about supposedly missing 'plugin.xml':
// https://youtrack.jetbrains.com/issue/MP-6388
verifierVersion = "1.307"
}

publishPlugin {
token = System.getenv("JETBRAINS_TOKEN")
channels = listOf(pluginVersion.split('-').getOrElse(1) { "default" }.split('.').first())
token = providers.environmentVariable("JETBRAINS_TOKEN")
// Note: `listOf("foo").first()` does not what you think on Java 21 and Gradle 8.6. (The return type is TaskProvider<Task>)
// See https://github.com/gradle/gradle/issues/27699 and https://youtrack.jetbrains.com/issue/KT-65235.
channels = listOf(pluginVersion.split('-').getOrElse(1) { "default" }.split('.')[0])
}

}

apply(from = "gradle/bumpVersion.gradle.kts")
6 changes: 6 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ pluginUntilBuild = 233.*

platformType = IC
platformVersion = 2022.3.3

# Gradle Configuration
# -> https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configuration-cache=true
15 changes: 15 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Gradle Version Catalog
# -> https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format

[libraries]
junit5-bom = { module = "org.junit:junit-bom", version = "5.9.1" }
junit5-jupiter = { module = "org.junit.jupiter:junit-jupiter" }
junit5-vintage-engine = { module = "org.junit.vintage:junit-vintage-engine" }

[plugins]
# gradle-intellij-plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
jetbrains-intellij = { id = "org.jetbrains.intellij", version = "1.17.2" }
# gradle-changelog-plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
jetbrains-changelog = { id = "org.jetbrains.changelog", version = "2.2.0" }
# grammarkit - read more: https://github.com/JetBrains/gradle-grammar-kit-plugin
jetbrains-grammarkit = { id = "org.jetbrains.grammarkit", version = "2022.3.2.2" }

0 comments on commit 37d0ad6

Please sign in to comment.