Skip to content

Indent a block comment that trails { like the statements after it #391

Indent a block comment that trails { like the statements after it

Indent a block comment that trails { like the statements after it #391

Workflow file for this run

name: CI
on:
push:
branches:
- '*.X.X' # a release line is named after the Java version it is built for: 21.X.X
pull_request:
permissions:
contents: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
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
# warnings of a step, so the annotations are the first ten warnings the parallel build prints.
- name: Install JDK 21
uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1
with:
distribution: temurin
java-version: '21'
problem-matcher: true
# Gradle's downloads come from the Actions cache rather than the network: the wrapper's distribution
# (services.gradle.org timed out and failed DNS on macos-15-intel, twice in a month) and the
# dependencies (Maven Central reset the connection on three runners and failed DNS on a fourth, all
# on 2026-10-19). Only builds of the default branch write the cache; pull requests read it. Two
# things stay out: the local build cache, left out on purpose for now, and the IDE the IntelliJ
# plugin's tests start, whose 852 MB zip and the 2.1 GB it unpacks to under transforms would take
# longer to restore than to download and fill much of the repository's 10 GB. Leaving paths out is a
# feature of the default, proprietary cache provider, bundled in the action and free for public
# repositories; the open-source one has none.
- name: Cache Gradle's downloads
uses: gradle/actions/setup-gradle@3f5f9adaf7d9fecd50b5935e54106014257a94e6 # v6.4.0
with:
gradle-home-cache-excludes: |
caches/build-cache-1
caches/modules-2/files-2.1/com.jetbrains.intellij.idea
caches/*/transforms
- name: Build
run: ./gradlew test
- name: Publish Test Report
uses: mikepenz/action-junit-report@6ef3fdcfcd5f0b5d14df3e659ef19b8c6820f93d # v6.6.1
if: ${{ !cancelled() }}
with:
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@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1
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@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1
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@3f5f9adaf7d9fecd50b5935e54106014257a94e6 # v6.4.0
with:
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"
- name: Publish Test Report
uses: mikepenz/action-junit-report@6ef3fdcfcd5f0b5d14df3e659ef19b8c6820f93d # v6.6.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.platform }})
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:
include:
- platform: linux-x86-64
runner: ubuntu-latest
- platform: linux-aarch64
runner: ubuntu-24.04-arm
- platform: macos-aarch64
runner: macos-15
- platform: macos-x86-64
runner: macos-15-intel
- platform: windows-x86-64
runner: 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@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1
with:
distribution: temurin
java-version: '21'
problem-matcher: false
- name: Install GraalVM 25 for the image
uses: graalvm/setup-graalvm@27b360dbb857524eaf0b4c4cef364d38e5b4f173 # v1.6.7
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@3f5f9adaf7d9fecd50b5935e54106014257a94e6 # v6.4.0
with:
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
- name: Test the plugins against the image
run: ./gradlew -PnativeImage=true :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@6ef3fdcfcd5f0b5d14df3e659ef19b8c6820f93d # v6.6.1
if: ${{ !cancelled() }}
with:
report_paths: '**/build/test-results/test/*.xml'
annotate_only: true
job_summary: true