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
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ updates:
target-branch: "main"
cooldown:
default-days: 7
ignore:
# follow-releases.yml moves both of the formatter's lines that the tests use, each to the latest
# release of its own line. Dependabot knows one version only and would move the 17 line to 21.x.
- dependency-name: "dev.openjavaformat:open-java-format"
37 changes: 32 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,37 @@ concurrency:
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
build:
name: build
test:
name: test (JDK ${{ matrix.jdk }}, open-java-format ${{ matrix.open-java-format }}.x)
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# The formatter's 17 line on JDK 17, its 21 line on JDK 21 and later. pom.xml holds each line's
# version, and the open-java-format-<line> profile picks it.
include:
- jdk: '17'
open-java-format: '17'
- jdk: '21'
open-java-format: '21'
- jdk: '25'
open-java-format: '21'
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Install JDK 21
- name: Install JDK ${{ matrix.jdk }}
uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0
with:
distribution: temurin
java-version: '21'
java-version: ${{ matrix.jdk }}
cache: maven

- name: Build
run: mvn --no-transfer-progress -B verify
env:
LINE: ${{ matrix.open-java-format }}
run: mvn --no-transfer-progress -B -P "open-java-format-$LINE" verify

- name: Publish Test Report
uses: mikepenz/action-junit-report@a16be3a69023e9bd7e748ede768b3282ea7b30ce # v6.7.1
Expand All @@ -39,3 +53,16 @@ jobs:
report_paths: 'target/surefire-reports/TEST-*.xml,target/invoker-reports/TEST-*.xml'
annotate_only: true
job_summary: true

# The check the ruleset requires, and so what auto-merge waits for: every leg of the matrix, since a
# new 21.x that breaks the plugin on JDK 21 must not merge on the strength of JDK 17 alone.
build:
name: build
needs: test
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
steps:
- name: Check that every leg passed
env:
RESULT: ${{ needs.test.result }}
run: test "$RESULT" = success
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ jobs:
with:
persist-credentials: false

- 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'

- name: Initialize CodeQL
uses: github/codeql-action/init@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea # v4.39.4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dependency-submission.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:
with:
persist-credentials: false

- 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'

- name: Submit Dependency Snapshot
uses: advanced-security/maven-dependency-submission-action@a64327a7329c9939cf675e458452febe1894a70c # v6.0.1
Expand Down
90 changes: 68 additions & 22 deletions .github/workflows/follow-releases.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
name: Follow releases

# The README's examples name the latest release of open-java-format and of the plugin itself. Once
# an hour this compares each with the latest GitHub release of openjavaformat/<artifact>. When a new
# release is out, the README is changed on the branch follow-releases/<artifact>, and a pull request
# The README's examples name the latest release of open-java-format and of the plugin itself, and
# pom.xml the version of each formatter line the tests use: the 17 line and the 21 line. Once an hour
# this compares each with the highest published GitHub release of openjavaformat/<artifact> in that
# line, not with the one GitHub marks Latest: a 17.x release is never marked so. When a new release
# is out, the files are changed on the branch follow-releases/<artifact>[-<line>], and a pull request
# for it is opened, approved and set to merge once build passes, the way Dependabot's are: main
# takes no direct pushes.
# takes no direct pushes. A new 21.x moves the README and the tests together, so the README names it
# only once the plugin passed its tests with it.
#
# BOT_PAT pushes the branch, opens the pull request and turns on auto-merge: a push or a pull request
# made with the workflow's own token starts no workflow runs, so build would never run on the pull
Expand All @@ -20,15 +23,29 @@ permissions: {}

jobs:
bump:
name: Bump ${{ matrix.artifact }}
name: Bump ${{ matrix.artifact }}${{ matrix.line && format(' {0}.x', matrix.line) || '' }}
runs-on: ubuntu-latest
permissions:
contents: read # check out the README
contents: read # check out the README and pom.xml
pull-requests: write # approve the pull request
strategy:
fail-fast: false
matrix:
artifact: [open-java-format, fmt-maven-plugin]
include:
# line: the first number of the releases to follow, or '' for all of them.
# readme: whether the README's examples name it. property: the pom.xml property, if any.
- artifact: open-java-format
line: '21'
readme: true
property: open-java-format-21.version
- artifact: open-java-format
line: '17'
readme: false
property: open-java-format-17.version
- artifact: fmt-maven-plugin
line: ''
readme: true
property: ''
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand All @@ -38,42 +55,71 @@ jobs:
shell: bash
env:
ARTIFACT: ${{ matrix.artifact }}
LINE: ${{ matrix.line }}
README: ${{ matrix.readme }}
PROPERTY: ${{ matrix.property }}
GH_TOKEN: ${{ github.token }}
BOT_PAT: ${{ secrets.BOT_PAT }}
run: |
# Every example names the version on the line after <artifactId>$ARTIFACT</artifactId>.
current=$(sed -n "/<artifactId>$ARTIFACT<\/artifactId>/{n;s/.*<version>\(.*\)<\/version>.*/\1/p;q}" README.md)
release=$(gh release view --repo "openjavaformat/$ARTIFACT" --json tagName,publishedAt)
latest=$(jq -r .tagName <<< "$release")
published=$(jq -r '.publishedAt[:10]' <<< "$release")
# The latest release is the one published last, and a fix for an older line can come out
# after a newer line started: only a higher version number is a bump.
# The highest published release of the line. Not the latest by date: a fix for an older line
# can come out after a newer line started.
releases=$(gh release list --repo "openjavaformat/$ARTIFACT" --exclude-drafts --exclude-pre-releases \
--limit 100 --json tagName,publishedAt)
latest=$(jq -r --arg prefix "${LINE:+$LINE.}" '.[].tagName | select(startswith($prefix))' <<< "$releases" |
sort -V | tail -n 1)
if [ -z "$latest" ]; then
echo "openjavaformat/$ARTIFACT has no ${LINE:+$LINE.x }release yet."
exit 0
fi
published=$(jq -r --arg tag "$latest" '.[] | select(.tagName == $tag) | .publishedAt[:10]' <<< "$releases")

if [ -n "$PROPERTY" ]; then
current=$(sed -n "s/.*<$PROPERTY>\(.*\)<\/$PROPERTY>.*/\1/p" pom.xml)
else
# Every example names the version on the line after <artifactId>$ARTIFACT</artifactId>.
current=$(sed -n "/<artifactId>$ARTIFACT<\/artifactId>/{n;s/.*<version>\(.*\)<\/version>.*/\1/p;q}" README.md)
fi
# Only a higher version number is a bump.
newer=$(printf '%s\n' "$current" "$latest" | sort -V | tail -n 1)
if [ "$latest" = "$current" ] || [ "$newer" != "$latest" ]; then
echo "Already on $current; the latest release is $latest."
exit 0
fi

sed -i "/<artifactId>$ARTIFACT<\/artifactId>/{n;s/<version>.*<\/version>/<version>$latest<\/version>/}" README.md
if [ "$README" = true ]; then
sed -i "/<artifactId>$ARTIFACT<\/artifactId>/{n;s/<version>.*<\/version>/<version>$latest<\/version>/}" README.md
fi
if [ -n "$PROPERTY" ]; then
sed -i "s/<$PROPERTY>.*<\/$PROPERTY>/<$PROPERTY>$latest<\/$PROPERTY>/" pom.xml
fi

# The branch lives as long as its pull request is open, and on after the pull request is
# closed unmerged. Either way, a branch with this README needs nothing more.
branch=follow-releases/$ARTIFACT
# closed unmerged. Either way, a branch with these files needs nothing more.
branch=follow-releases/$ARTIFACT${LINE:+-$LINE}
if git fetch --quiet --depth 1 origin "refs/heads/$branch" 2> /dev/null &&
git diff --quiet FETCH_HEAD -- README.md; then
git diff --quiet FETCH_HEAD -- README.md pom.xml; then
echo "$branch names $latest already."
exit 0
fi
git diff

if [ -n "$PROPERTY" ]; then
title="Test with $ARTIFACT $latest"
what="The tests on the $LINE line use $ARTIFACT $latest"
if [ "$README" = true ]; then
what="$what, and the README's examples name it"
fi
else
title="Show $ARTIFACT $latest in the README"
what="The examples name $ARTIFACT $latest"
fi
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git commit --all --quiet --file - <<COMMIT
Show $ARTIFACT $latest in the README
$title

The examples name $ARTIFACT $latest, which
openjavaformat/$ARTIFACT released on $published. Made by the
"$GITHUB_WORKFLOW" workflow:
$what. openjavaformat/$ARTIFACT released it on $published.
Made by the "$GITHUB_WORKFLOW" workflow:
$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
COMMIT
gh auth setup-git
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ jobs:
fetch-depth: 0
persist-credentials: false

- 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'

- name: Take the version from the tag
env:
Expand Down Expand Up @@ -94,11 +94,11 @@ jobs:
fetch-depth: 0
persist-credentials: false

- 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'

# The central job has already refused anything but a clean X.Y.Z.N.
- name: Take the version from the tag
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ You can pass parameters via standard `-D` syntax.

### Requirements

Maven has to run on JDK 21 or newer: open-java-format is compiled for Java 21, and the plugin formats in a JVM started from the same JDK.
Maven has to run on JDK 17 or newer, and the `open-java-format` version you name decides the rest, since the plugin formats in a JVM started from the same JDK: 21.x needs JDK 21 or newer, and the 17 line, 17.x, runs on JDK 17 and newer.

### Building

`mvn verify` on JDK 21 runs the unit tests and the integration tests, the projects in `src/test/resources`.
`mvn verify` runs the unit tests and the integration tests, the projects in `src/test/resources`, with the formatter's 17 line, which runs on JDK 17 and newer. `-P open-java-format-21` runs them with the 21 line instead, on JDK 21 or newer. CI runs the 17 line on JDK 17 and the 21 line on JDK 21 and 25, and [follow-releases.yml](.github/workflows/follow-releases.yml) moves each line in `pom.xml` to its latest release.

### Releasing

Expand Down
2 changes: 1 addition & 1 deletion mise.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Development tooling for fmt-maven-plugin.
#
[tools]
java = "temurin-21"
java = "temurin-17"

# ---- GitHub Actions secrets ----
# Read from 1Password at apply time; nothing secret is stored in the repo. Requires gh
Expand Down
40 changes: 36 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,24 @@
</scm>

<properties>
<!-- open-java-format is compiled for Java 21, so the plugin cannot run on anything older. -->
<java.version>21</java.version>
<!--
The plugin runs on JDK 17 and later. The formatter a build names decides the JDK it needs:
open-java-format 17.x runs on JDK 17 and later, 21.x on JDK 21 and later.
-->
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.outputTimestamp>1758111025</project.build.outputTimestamp>
<maven.version>3.10.2</maven.version>
<!-- The version the plugin is compiled and tested against. Builds that use the plugin name their own. -->
<open-java-format.version>21.0.2</open-java-format.version>
<!--
The formatter the plugin is tested with, one version per line: the 17 line on JDK 17 and later,
the 21 line on JDK 21 and later. The open-java-format-17 and open-java-format-21 profiles pick one,
and CI runs both; follow-releases.yml moves each to the latest release of its line. Without a
profile the plugin is compiled and tested against the 17 line, which runs on every JDK the plugin
does. Builds that use the plugin name their own version.
-->
<open-java-format-17.version>17.1.0</open-java-format-17.version>
<open-java-format-21.version>21.1.2</open-java-format-21.version>
<open-java-format.version>${open-java-format-17.version}</open-java-format.version>
<!-- What JReleaser does: deploy to Maven Central, unless the github-release profile below is active. -->
<jreleaser.central.deploy>ALWAYS</jreleaser.central.deploy>
<jreleaser.github.release>false</jreleaser.github.release>
Expand Down Expand Up @@ -183,6 +194,11 @@
<version>3.16.0</version>
<configuration>
<goalPrefix>fmt</goalPrefix>
<!--
Maven 4 does not load the plugin on a JDK older than this. "auto" takes the version from the
classes of open-java-format too, so with a 21.x there it would be 21.
-->
<requiredJavaVersion>${java.version}</requiredJavaVersion>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
Expand Down Expand Up @@ -323,6 +339,22 @@
</build>

<profiles>
<!--
Profiles rather than -Dopen-java-format.version: the integration tests take the version from the
POM's properties, and a -D does not reach them.
-->
<profile>
<id>open-java-format-17</id>
<properties>
<open-java-format.version>${open-java-format-17.version}</open-java-format.version>
</properties>
</profile>
<profile>
<id>open-java-format-21</id>
<properties>
<open-java-format.version>${open-java-format-21.version}</open-java-format.version>
</properties>
</profile>
<!--
The draft GitHub release, for the job in release.yml that runs once the plugin is on Maven
Central: `mvn -P github-release jreleaser:release` releases the jar in target/ and deploys nothing.
Expand Down