Skip to content

Commit

Permalink
Setup toolchains, compile project with Java 20 only, run test on vari…
Browse files Browse the repository at this point in the history
…ous Java versions (#2120)

* Replace testing on java 19 with testing on java 20

Closes #1888

* Unify `yml` files formating

* Do NOT compile the project with various Java version, instead test agains various java verstions

https://jakewharton.com/build-on-latest-java-test-through-lowest-java/

* Add `-add-opens` jvmArg to prevent ignored warnings

* Migrate away deprecated `java.net.URL` constructor

* Setup toolchain resolver

If someone doesn't have required java installed Gradle will attempt to install one

* Extract common build setup + fix memory settings

The build needs less than 0.5GB of a java heap memory. There is no value in reserving more than half of available RAM just for the Gradle demon. It's better to keep Gradle daemon small  and leave the memory available to other forked processes (i.e. tests)

* Disable VFS on CI

CI doesn't modify files, there is no value in putting extra effort in efficiently tracking changed files. From test runs VFS comes with noticable performance impact on Windows build

* Update comment with extra clarification

* Disable automatic build scans publishing on local builds

* Update kotlin dev version

* Fix `-PkotlinDev` not running tests agains configured kotlin version

* Fix `-PkotlinDev` artifacts version

* Run `-PkotlinDev` build as a separate workflow job in parallel

Co-authored-by: paul-dingemans <paul-dingemans@users.noreply.github.com>
  • Loading branch information
mateuszkwiecinski and paul-dingemans authored Jul 31, 2023
1 parent 3ccdf1f commit 760279e
Show file tree
Hide file tree
Showing 17 changed files with 206 additions and 82 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ max_line_length = unset

[gradle/verification-metadata.xml]
indent_size = 3

[*.yml]
ij_yaml_spaces_within_brackets = false
40 changes: 40 additions & 0 deletions .github/actions/setup-gradle-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Setup Gradle
description: Sets up the environment to run Gradle

inputs:
gradle-jvm-args:
description: "JVM args to pass to Gradle"
required: true
# Github-Hosted nodes have only 7GB of RAM available. Looking at build scans Gradle process requires slightly more than 0.5GB.
# Keeping this setting low, allows other, forked JVM processes (like tests) to use remaining memory.
# Increase this value, only if GC time visible in build scans will take more than a few seconds.
default: "-Xmx1g"
additional-java-versions:
description: "Java versions installed on the side of the default Java version required by the build"
required: false

runs:
using: composite

steps:
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: | # last version (set as default) should match all `jvmToolchain(xxx)` calls in the project
${{ inputs.additional-java-versions }}
20
# Please note these settings will override the ones set via `gradle.properties` committed to the repository - https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties
# List of optimizations:
# - `jvm-args` fine-tuned to the CI runner & tasks being invoked
# - disabled File System Watching to improve Windows build times. CI runs don't modify source files, hence they don't need to pay extra cost to efficiently track changed files.
- name: Optimize Gradle build properties for CI
run: |
mkdir -p ~/.gradle
printf "org.gradle.jvmargs=${{ inputs.gradle-jvm-args }}\n" >> ~/.gradle/gradle.properties
printf "org.gradle.vfs.watch=false\n" >> ~/.gradle/gradle.properties
shell: bash

- uses: gradle/gradle-build-action@v2
with:
gradle-home-cache-cleanup: true
2 changes: 1 addition & 1 deletion .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "Validate Gradle Wrapper"

on: [ push, pull_request ]
on: [push, pull_request]

jobs:
validation:
Expand Down
39 changes: 18 additions & 21 deletions .github/workflows/publish-release-build.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Publish release build

on :
push :
tags :
on:
push:
tags:
- '*.*.*'

jobs:
Expand All @@ -14,26 +14,23 @@ jobs:
- uses: actions/checkout@v3
with:
ref: 'master'
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 19
- uses: gradle/gradle-build-action@v2
with:
gradle-home-cache-cleanup: true


- uses: ./.github/actions/setup-gradle-build

- name: Build executable and publish to Maven
run: ./gradlew clean shadowJarExecutable publishMavenPublicationToMavenCentralRepository --no-daemon --no-parallel --no-configuration-cache
env:
SONATYPE_NEXUS_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
SONATYPE_NEXUS_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
ORG_GRADLE_PROJECT_signingKey : ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEY }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEY }}
ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEYID }}
ORG_GRADLE_PROJECT_signingKeyPassword : ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGPASSWORD }}
ORG_GRADLE_PROJECT_signingKeyPassword: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGPASSWORD }}

- name : Extract release notes
id : release_notes
- name: Extract release notes
id: release_notes
if: ${{ success() }}
uses : ffurrer2/extract-release-notes@v1
uses: ffurrer2/extract-release-notes@v1

- name: Get version
id: get_version
Expand All @@ -49,18 +46,18 @@ jobs:
cp ktlint ktlint-${{ env.version }}/bin
zip -rm ktlint-${{ env.version }}.zip ktlint-${{ env.version }}
- name : Create release
- name: Create release
id: github_release
if: ${{ success() }}
uses : softprops/action-gh-release@v1
with :
uses: softprops/action-gh-release@v1
with:
draft: false
prerelease: false
body : ${{ steps.release_notes.outputs.release_notes }}
body: ${{ steps.release_notes.outputs.release_notes }}
files: |
ktlint-cli/build/run/*
env :
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Bump Homebrew Formula
if: ${{ success() }}
Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/publish-snapshot-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish snapshot build

on:
push:
branches: [ master ]
branches: [master]
paths: ['**/*.kt', '**/*.kts', '**/*.properties', '**/*.toml']

env:
Expand All @@ -15,14 +15,11 @@ jobs:
if: github.repository == 'pinterest/ktlint'
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 19
- uses: gradle/gradle-build-action@v2
with:
gradle-home-cache-cleanup: true

- uses: ./.github/actions/setup-gradle-build

- name: Publish snapshot to Maven
run: ./gradlew clean publishMavenPublicationToMavenCentralRepository --no-daemon --no-parallel --no-configuration-cache

- name: Publish Kotlin-dev snapshot to Maven
run: ./gradlew -PkotlinDev clean publishMavenPublicationToMavenCentralRepository --no-daemon --no-parallel --no-configuration-cache
64 changes: 44 additions & 20 deletions .github/workflows/pull-request-with-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,31 @@ on:
- '**/*.toml'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

env:
ORG_GRADLE_PROJECT_signingKey : ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEY }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEY }}
ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEYID }}
ORG_GRADLE_PROJECT_signingKeyPassword : ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGPASSWORD }}
ORG_GRADLE_PROJECT_signingKeyPassword: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGPASSWORD }}
CLI_TEST_MAX_DURATION_IN_SECONDS: 10

# Note that "jobs.build.strategy" and "jobs.build.runs-on" should be kept in sync with "pull-request-wth-code"
# Note that all "jobs" (build, tests) including "jobs.*.runs-on" should be kept in sync with "pull-request-without-code"
jobs:
build:
strategy:
matrix:
os: [ ubuntu-latest, windows-latest ]
# When changing the list of JDK versions, the build configuration has to be changed by a repository admin. See
# https://github.com/pinterest/ktlint/pull/1787#issuecomment-1409074092
jdk: [ 8, 11, 17, 19 ]
exclude: # windows with JDK8 are *really* flaky
- os: windows-latest
jdk: 8
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
name: "[build] OS=${{ matrix.os }} Kotlin=stable"
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: ${{ matrix.jdk }}
- uses: gradle/gradle-build-action@v2
with:
gradle-home-cache-cleanup: true

- uses: ./.github/actions/setup-gradle-build

- name: Build with release Kotlin version
run: ./gradlew build ktlintCheck --no-configuration-cache
- name: Build with dev Kotlin version
run: ./gradlew -PkotlinDev build ktlintCheck --no-configuration-cache
run: ./gradlew ktlintCheck build

- name: Check `data class`es are not part of public API
run: |
Expand All @@ -70,3 +63,34 @@ jobs:
exit 1
fi
shell: bash

build-dev:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
name: "[build] OS=${{ matrix.os }}, Kotlin=dev"
steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/setup-gradle-build

- name: Build with assemble Kotlin version
run: ./gradlew -PkotlinDev ktlintCheck build

tests:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
jdk: [8, 11, 17] # list of Java versions to run tests against (excluding `java-compilation` version for which tests already have run during `build` job)
runs-on: ${{ matrix.os }}
name: "[tests] OS=${{ matrix.os }}, Java=${{ matrix.jdk }}"
steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/setup-gradle-build
with:
additional-java-versions: ${{ matrix.jdk }}

- run: ./gradlew testOnJdk${{ matrix.jdk }} -PtestJdkVersion=${{ matrix.jdk }}
30 changes: 22 additions & 8 deletions .github/workflows/pull-request-without-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,32 @@ on:
- '!**/*.toml'

# Add a dummy job that return true so that a PR not containing any code can be merged to master
# Note that "jobs.build.strategy" and "jobs.build.runs-on" should be kept in sync with "pull-request-wth-code"
# Note that all "jobs" (build, tests) including "jobs.*.runs-on" should be kept in sync with "pull-request-with-code"
jobs:
build:
strategy:
matrix:
os: [ ubuntu-latest, windows-latest ]
# When changing the list of JDK versions, the build configuration has to be changed by a repository admin. See
# https://github.com/pinterest/ktlint/pull/1787#issuecomment-1409074092
jdk: [ 8, 11, 17, 19 ]
exclude: # windows with JDK8 are *really* flaky
- os: windows-latest
jdk: 8
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
name: "[build] OS=${{ matrix.os }} Kotlin=stable"
steps:
- run: 'echo "No build required"'

build-dev:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
name: "[build] OS=${{ matrix.os }}, Kotlin=dev"
steps:
- run: 'echo "No build required"'

tests:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
jdk: [ 8, 11, 17 ]
runs-on: ${{ matrix.os }}
name: "[tests] OS=${{ matrix.os }}, Java=${{ matrix.jdk }}"
steps:
- run: 'echo "No build required"'
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
* Update dependency com.google.jimfs:jimfs to v1.3.0 ([#2112](https://github.com/pinterest/ktlint/pull/2112))
* As a part of public API stabilization, configure `binary-compatibility-validator` plugin for compile-time verification of binary compatibility with previous `ktlint` versions ([#2131](https://github.com/pinterest/ktlint/pull/2131))
* Update dependency org.junit.jupiter:junit-jupiter to v5.10.0 ([#2148](https://github.com/pinterest/ktlint/pull/2148))
* Build the project with Java 20, run test on Java 8, 11, 17 and 20 ([#1888](https://github.com/pinterest/ktlint/issues/1888))

## [0.50.0] - 2023-06-29

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<p align="center">
<a href="https://kotlinlang.slack.com/messages/CKS3XG0LS"><img src="https://img.shields.io/badge/slack-@kotlinlang/ktlint-yellow.svg?logo=slack" alt="Join the chat at https://kotlinlang.slack.com"/></a>
<a href="https://github.com/pinterest/ktlint/actions/workflows/gradle-snapshot-build.yml"><img src="https://github.com/pinterest/ktlint/actions/workflows/gradle-snapshot-build.yml/badge.svg" alt="Build status"></a>
<a href="https://github.com/pinterest/ktlint/actions/workflows/publish-snapshot-build.yml"><img src="https://github.com/pinterest/ktlint/actions/workflows/publish-snapshot-build.yml/badge.svg" alt="Build status"></a>
<a href="https://search.maven.org/artifact/com.pinterest/ktlint"><img src="https://img.shields.io/maven-central/v/com.pinterest/ktlint.svg" alt="Maven Central"></a>
<a href="https://jitpack.io/#pinterest/ktlint"><img src="https://jitpack.io/v/pinterest/ktlint.svg" alt="JitPack"></a>
<a href="https://formulae.brew.sh/formula/ktlint"><img src="https://img.shields.io/homebrew/v/ktlint.svg" alt="HomeBrew"></a>
Expand Down
23 changes: 21 additions & 2 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`kotlin-dsl`
}
Expand All @@ -6,14 +9,30 @@ repositories {
mavenCentral()
}

kotlin {
jvmToolchain(libs.versions.java.compilation.get().toInt())
}

// TODO: Remove setting `options.release` and `compilerOptions.jvmTarget` after upgrade to Kotlin Gradle Plugin 1.9
// build-logic is an internal project and given we know how the "actual" project is built - it's fine to target current java here as well.
// @see https://github.com/pinterest/ktlint/pull/2120#discussion_r1260229055 for more details
val buildLogicTargetJavaVersion = JavaVersion.VERSION_17
tasks.withType<JavaCompile>().configureEach {
options.release.set(buildLogicTargetJavaVersion.majorVersion.toInt())
}
tasks.withType<KotlinCompile>().configureEach {
// Convert Java version (e.g. "1.8" or "11") to Kotlin JvmTarget ("8" resp. "11")
compilerOptions.jvmTarget.set(JvmTarget.fromTarget(buildLogicTargetJavaVersion.toString()))
}

dependencies {
val kotlinPlugin =
if (providers.gradleProperty("kotlinDev").orNull.toBoolean()) {
if (hasProperty("kotlinDev")) {
// Pass '-PkotlinDev' to command line to enable kotlin-in-development version
logger.warn("Enabling kotlin dev version!")
libs.kotlin.plugin.dev
} else {
libs.kotlin.plugin
libs.kotlin.plugin.asProvider()
}
implementation(kotlinPlugin)
implementation(libs.dokka)
Expand Down
4 changes: 4 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ dependencyResolutionManagement {
}
}
}

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.6.0"
}
Loading

0 comments on commit 760279e

Please sign in to comment.