diff --git a/.github/dependabot.yml b/.github/dependabot.yml index d4ff3fc..5bd993b 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -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" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2282041..0cd650d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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- 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 @@ -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 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index c2ebf01..5770b84 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -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 diff --git a/.github/workflows/dependency-submission.yml b/.github/workflows/dependency-submission.yml index 4d63533..3e87a0a 100644 --- a/.github/workflows/dependency-submission.yml +++ b/.github/workflows/dependency-submission.yml @@ -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 diff --git a/.github/workflows/follow-releases.yml b/.github/workflows/follow-releases.yml index e509320..60773f6 100644 --- a/.github/workflows/follow-releases.yml +++ b/.github/workflows/follow-releases.yml @@ -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/. When a new -# release is out, the README is changed on the branch follow-releases/, 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/ 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/[-], 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 @@ -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: @@ -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 $ARTIFACT. - current=$(sed -n "/$ARTIFACT<\/artifactId>/{n;s/.*\(.*\)<\/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 $ARTIFACT. + current=$(sed -n "/$ARTIFACT<\/artifactId>/{n;s/.*\(.*\)<\/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 "/$ARTIFACT<\/artifactId>/{n;s/.*<\/version>/$latest<\/version>/}" README.md + if [ "$README" = true ]; then + sed -i "/$ARTIFACT<\/artifactId>/{n;s/.*<\/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 - < - - 21 + + 17 UTF-8 1758111025 3.10.2 - - 21.0.2 + + 17.1.0 + 21.1.2 + ${open-java-format-17.version} ALWAYS false @@ -183,6 +194,11 @@ 3.16.0 fmt + + ${java.version} true @@ -323,6 +339,22 @@ + + + open-java-format-17 + + ${open-java-format-17.version} + + + + open-java-format-21 + + ${open-java-format-21.version} + +