Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
298 changes: 4 additions & 294 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ jobs:
with:
persist-credentials: false

# setup-java's problem matcher turns javac's warnings, Error Prone's among them, into annotations on
# the diff. This is the one job that keeps it: every other job compiles the same sources, and with
# the matcher on there too each warning showed once per job. GitHub keeps only the first ten
# The 17 line builds and tests on JDK 17 alone; 21.x is the line for JDK 21 and later. setup-java's
# problem matcher turns javac's warnings into annotations on the diff. GitHub keeps only the first ten
# warnings of a step, so the annotations are the first ten warnings the parallel build prints.
- name: Install JDK 21
- name: Install JDK 17
uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0
with:
distribution: temurin
java-version: '21'
java-version: '17'
problem-matcher: true

# Gradle's downloads come from the Actions cache rather than the network: the wrapper's distribution
Expand Down Expand Up @@ -68,292 +67,3 @@ jobs:
report_paths: '**/build/test-results/test/*.xml'
annotate_only: true
job_summary: true

# The tests of `build` on the newer JDKs, in parallel with everything else: nothing waits for these
# jobs and nothing they build is kept. The code is still compiled for Java 21 by JDK 21, as in the
# release; -PjavaRuntime moves only the test JVMs, and with them the javac whose internals the
# formatter parses with. The IntelliJ plugin's tests stay on the runtime of the IDE they start.
# JDK 21 itself is `build`, the check the default branch requires.
jdk:
name: build (JDK ${{ matrix.jdk }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# `gradle` is what the Gradle plugins' tests build their projects with: the oldest release that runs on
# the leg's JDK (https://docs.gradle.org/current/userguide/compatibility.html#java_runtime), or 9.3.1,
# the oldest the plugins support, where that is older. Each leg thus tests the far end of what it can.
# 28-ea has none that runs on it yet.
include:
- jdk: 25
gradle: 9.3.1
gradle_args: ''
gradle_args_reason: ''
- jdk: 26
gradle: 9.4.0
gradle_args: ''
gradle_args_reason: ''
- jdk: 27
gradle: 9.8.0
gradle_args: ''
gradle_args_reason: ''
# Value classes (JEP 401) are a preview feature of JDK 28, so until it is released the `value` modifier
# tests (#131) run on its early-access builds and are skipped everywhere else. The version is spelled
# as setup-java spells it; Gradle gets the number alone.
- jdk: 28-ea
gradle: ''
gradle_args: -x :gradle-open-java-format:test
gradle_args_reason: >-
No Gradle release runs on Java 28 yet: 9.8.2, the newest, fails to compile a build script there with
"Unsupported class file major version 72". The Gradle plugins' tests build their projects with Gradle
on the test JVM, so they are left out until a release runs on it.
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

# No problem matcher in this job: `build` annotates the warnings.
- name: Install JDK ${{ matrix.jdk }} for the tests
id: test-jdk
uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0
with:
distribution: temurin
java-version: ${{ matrix.jdk }}
problem-matcher: false

# Installed last, so that it is the JAVA_HOME Gradle runs and compiles on.
- name: Install JDK 21
uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0
with:
distribution: temurin
java-version: '21'
problem-matcher: false

# The same cache as in `build`.
- name: Cache Gradle's downloads
uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1
with:
gradle-home-cache-includes: |
caches
notifications
test-kit/caches/modules-2
gradle-home-cache-excludes: |
caches/build-cache-1
caches/modules-2/files-2.1/com.jetbrains.intellij.idea
caches/*/transforms

- name: Explain the extra Gradle arguments
if: ${{ matrix.gradle_args != '' }}
env:
GRADLE_ARGS: ${{ matrix.gradle_args }}
REASON: ${{ matrix.gradle_args_reason }}
run: echo "::notice title=JDK ${{ matrix.jdk }} runs with $GRADLE_ARGS::$REASON"

# Gradle does not look into the runner's tool cache, so it is told where the test JDK is. The path is
# a step's output, so it reaches the shell as a variable rather than being pasted into the script.
# -PjavaRuntime takes a number, so an early-access leg loses its -ea suffix here.
- name: Build
env:
TEST_JDK: ${{ steps.test-jdk.outputs.path }}
JDK: ${{ matrix.jdk }}
TESTKIT_GRADLE: ${{ matrix.gradle }}
run: >-
./gradlew test -PjavaRuntime="${JDK%-ea}" -PtestkitGradleVersion="$TESTKIT_GRADLE" ${{ matrix.gradle_args }}
-Porg.gradle.java.installations.paths="$TEST_JDK" -PtestkitDir="$GRADLE_USER_HOME/test-kit"

- name: Publish Test Report
uses: mikepenz/action-junit-report@a16be3a69023e9bd7e748ede768b3282ea7b30ce # v6.7.1
if: ${{ !cancelled() }}
with:
report_paths: '**/build/test-results/test/*.xml'
annotate_only: true
job_summary: true

# One explicit job per target, so every binary we ship is traceable to a named run.
native:
name: native (${{ matrix.runner }})
needs: build
runs-on: ${{ matrix.runner }}
timeout-minutes: 90
# bash on Windows too, so that every step reads the same on every runner.
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
# Linux on the previous Ubuntu LTS, not the newest: a binary built against a newer glibc may need that
# glibc to start, and the older one keeps the binaries running on older systems. GitHub retires an
# image once two newer ones are out. release.yml builds on the same images. Elsewhere the newest
# images; Intel macOS has no free -latest label, so its image is named.
runner:
- ubuntu-24.04
- ubuntu-24.04-arm
# macOS on Apple silicon is built for a release only, in release.yml.
# - macos-latest
- macos-26-intel
- windows-latest

steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

# The jars compile with a Java 21 toolchain, which gradle.properties looks up in JDK21_HOME. On
# Linux and macOS Gradle also finds the runner's own JDK 21 by its location, on Windows it does not.
# Installed before GraalVM, so that Gradle itself still runs on GraalVM. No problem matcher: `build`
# annotates the warnings.
- name: Install JDK 21 for the jars
id: jdk21
uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0
with:
distribution: temurin
java-version: '21'
problem-matcher: false

- name: Install GraalVM 25 for the image
uses: graalvm/setup-graalvm@60e76998d25690099182b796e99b8804da582d90 # v1.6.10
with:
java-version: '25'
distribution: 'graalvm-community'
github-token: ${{ secrets.GITHUB_TOKEN }}

# The same cache as in `build`.
- name: Cache Gradle's downloads
uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1
with:
gradle-home-cache-includes: |
caches
notifications
test-kit/caches/modules-2
gradle-home-cache-excludes: |
caches/build-cache-1
caches/modules-2/files-2.1/com.jetbrains.intellij.idea
caches/*/transforms

- name: Compile the native image
run: ./gradlew -PnativeImage=true :open-java-format-native:nativeCompile
env:
JDK21_HOME: ${{ steps.jdk21.outputs.path }}

# The binary itself on a file that needs formatting, a formatted one, one that does not parse and
# one in Java 25 syntax.
- name: Smoke-test the binary
run: |
binary="$PWD/$(ls open-java-format-native/build/native/nativeCompile/open-java-format-* | grep -v '\.txt$')"
mkdir smoke-test && cd smoke-test
"$binary" --version
printf 'class A{int x;}\n' > A.java
"$binary" --replace A.java
printf 'class A {\n int x;\n}\n' | diff - A.java
"$binary" --dry-run --set-exit-if-changed A.java
printf 'class B {\n' > B.java
set +e; "$binary" B.java; status=$?; set -e
test "$status" -eq 2
# Java 25 syntax: a compact source file with a module import and an unnamed pattern.
printf 'import module java.base;\nrecord Box(int a,int b){}\nvoid main(){Object o=new Box(1,2);if(o instanceof Box(_,_)){IO.println(List.of(1));}}\n' > C.java
"$binary" --replace C.java
printf 'import module java.base;\n\nrecord Box(int a, int b) {}\n\nvoid main() {\n Object o = new Box(1, 2);\n if (o instanceof Box(_, _)) {\n IO.println(List.of(1));\n }\n}\n' | diff - C.java

# Packaged as release.yml packages it for the GitHub release and the apt repository, under the version
# the binary prints.
- name: Find the binary and its version
id: binary
if: runner.os == 'Linux'
run: |
binary="$(ls open-java-format-native/build/native/nativeCompile/open-java-format-* | grep -v '\.txt$')"
echo "path=$binary" >> "$GITHUB_OUTPUT"
echo "version=$("$binary" --version 2>&1 | sed -n 's/^open-java-format: Version //p')" >> "$GITHUB_OUTPUT"

- name: Package and install the binary as a .deb
if: runner.os == 'Linux'
uses: $/.github/actions/deb-package
with:
binary: ${{ steps.binary.outputs.path }}
version: ${{ steps.binary.outputs.version }}
out-dir: ${{ runner.temp }}/deb-package

- name: Test the plugins against the image
run: >-
./gradlew -PnativeImage=true -PtestkitDir="$GRADLE_USER_HOME/test-kit"
:open-java-format-jdk-bootstrap:test :gradle-open-java-format:test
env:
JDK21_HOME: ${{ steps.jdk21.outputs.path }}

- name: Publish Test Report
uses: mikepenz/action-junit-report@a16be3a69023e9bd7e748ede768b3282ea7b30ce # v6.7.1
if: ${{ !cancelled() }}
with:
report_paths: '**/build/test-results/test/*.xml'
annotate_only: true
job_summary: true

# The WebAssembly module, built and tested as the release's `wasm` job does, so that a change that breaks it shows
# in its pull request rather than in a release. The module itself is not kept.
wasm:
name: wasm
needs: build
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

# The jars compile with Java 21 through JDK21_HOME, as in `native`. Installed before GraalVM, so that Gradle
# still runs on GraalVM. No problem matcher: `build` annotates the warnings.
- name: Install JDK 21 for the jars
id: jdk21
uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0
with:
distribution: temurin
java-version: '21'
problem-matcher: false

# The same release as in release.yml: Web Image is experimental, and its options and output change between
# releases.
- name: Install Oracle GraalVM 25 for the module
uses: graalvm/setup-graalvm@60e76998d25690099182b796e99b8804da582d90 # v1.6.10
with:
java-version: '25.0.4'
distribution: 'graalvm'
github-token: ${{ secrets.GITHUB_TOKEN }}

# Web Image runs wasm-opt from the PATH, and needs Binaryen 119 or later; Ubuntu's package is older.
- name: Install Binaryen
env:
BINARYEN_VERSION: version_133
BINARYEN_SHA256: 2dc9c7813f5375db93d96ead4b78222fcc3e2677bbb832297af4797782a37489
run: |
archive="binaryen-${BINARYEN_VERSION}-x86_64-linux.tar.gz"
curl --fail --silent --show-error --location --output "${RUNNER_TEMP}/${archive}" \
"https://github.com/WebAssembly/binaryen/releases/download/${BINARYEN_VERSION}/${archive}"
echo "${BINARYEN_SHA256} ${RUNNER_TEMP}/${archive}" | sha256sum --check
tar -xzf "${RUNNER_TEMP}/${archive}" -C "${RUNNER_TEMP}"
echo "${RUNNER_TEMP}/binaryen-${BINARYEN_VERSION}/bin" >> "$GITHUB_PATH"

# Node 24 has the WebAssembly GC and exception handling the module needs.
- name: Install Node.js 24 for the tests
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '24'
package-manager-cache: false

# The same cache as in `build`.
- name: Cache Gradle's downloads
uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1
with:
gradle-home-cache-includes: |
caches
notifications
test-kit/caches/modules-2
gradle-home-cache-excludes: |
caches/build-cache-1
caches/modules-2/files-2.1/com.jetbrains.intellij.idea
caches/*/transforms

# wasmTest: the smoke test, then every Java 21 and Java 25 test case's input against the runnable jar.
- name: Build and test the module
run: ./gradlew -Pwasm=true :open-java-format-wasm:wasmTest
env:
JDK21_HOME: ${{ steps.jdk21.outputs.path }}
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ jobs:
persist-credentials: false

# No problem matcher: the javac warnings are annotated by CI's `build` job.
- name: Set up JDK 21
- name: Set up JDK 17
uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0
with:
distribution: temurin
java-version: '21'
java-version: '17'
problem-matcher: false

- name: Initialize CodeQL
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependency-submission.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0
with:
distribution: temurin
java-version: '21'
java-version: '17'

- name: Submit Dependency Snapshot
uses: gradle/actions/dependency-submission@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1
Expand Down
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ buildscript {

dependencies {
classpath 'com.gradle.publish:plugin-publish-plugin:2.2.1'
// The released open-java-format formats this repository, not the one being built here.
classpath 'dev.openjavaformat:gradle-open-java-format:21.0.2'
// The released open-java-format formats this repository, not the one being built here. The 21 line's
// plugin does not load on Gradle with JDK 17, so the 17 line applies none until 17.1.0 is out; until then,
// changes made on the branch are formatted with the 21 line's -all.jar.
// classpath 'dev.openjavaformat:gradle-open-java-format:21.0.2'
classpath 'me.champeau.jmh:jmh-gradle-plugin:0.7.4'
}
}
Expand Down Expand Up @@ -47,7 +49,7 @@ def javacInternalExports = [
]

allprojects {
apply plugin: 'dev.openjavaformat.java-format'
// apply plugin: 'dev.openjavaformat.java-format'

// The fork's Maven group (README, "Coordinates"). The Java packages stay com.palantir.javaformat.
group = 'dev.openjavaformat'
Expand Down Expand Up @@ -84,7 +86,6 @@ allprojects {
subprojects {
apply plugin: 'java-library'
apply plugin: 'open-java-format.java-conventions'
apply plugin: 'open-java-format.error-prone-conventions'

// Bans Guava's immutable collections, but not in the SPI: FormatterService.getFormatReplacements keeps
// returning ImmutableList, so that code compiled against an older SPI still links.
Expand Down
2 changes: 0 additions & 2 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ repositories {
}

dependencies {
implementation 'net.ltgt.gradle:gradle-errorprone-plugin:5.2.0'
implementation 'net.ltgt.gradle:gradle-nullaway-plugin:3.3.0'
implementation 'de.thetaphi:forbiddenapis:3.11'
implementation 'org.jreleaser:org.jreleaser.gradle.plugin:1.26.0'
}
Loading
Loading