You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 00ed0e4
Browse filesBrowse the repository at this point in the historyBrowse files
The action warns when a newer open-java-format release is out than the
version it runs, but a log warning is easy to miss. The check is now
also uploaded to code scanning as a SARIF file: one alert while the
version is behind, none once it is current, which closes the alert. It
shows under Security → Code scanning and in the "Code scanning results"
check of a pull request, placed on the line of the workflow that names
the version, so it points at what to change. Alerts are told apart by
a fingerprint of that line's text, so they survive the line moving.
The upload goes straight to the REST API rather than through
github/codeql-action/upload-sarif, which fails the job when the
security-events: write permission is missing. This way the upload is
best-effort like the check itself: without the permission, without
GitHub Code Security on a private repository, or with the read-only
token of a fork's pull request, it is skipped with a line in the log
and the log warning stays. The new code-scanning input turns it off.
Test Action grants the permission to the mode=changed job, so that
run exercises the upload, and withholds it from the platform matrix,
whose ten runs of the action would all report the same category and
must do without the upload anyway.
Copy file name to clipboardExpand all lines: README.md
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,7 @@ v2 is for open-java-format 2.98.0.2 and later, which has a single style. A workf
22
22
|-------|----------|---------|-------------|
23
23
| `version` | yes | `2.98.0.6` | Version of the open-java-format native binary, one of those on [Maven Central](https://repo1.maven.org/maven2/dev/openjavaformat/open-java-format-native/) |
24
24
| `mode` | no | `changed` | `changed` — only files from PR or push; `all` — every `.java` file in repo |
25
+
| `code-scanning` | no | `true` | Report the version check to [code scanning](#code-scanning) as well; `false` keeps it to the log warning |
25
26
26
27
## How `mode: changed` works
27
28
@@ -33,6 +34,7 @@ v2 is for open-java-format 2.98.0.2 and later, which has a single style. A workf
33
34
34
35
- If all files are formatted correctly → passes ✅
35
36
- If any file has formatting issues → lists unformatted files and fails ❌
37
+
- If a newer open-java-format release is out → warns in the job log, and raises a [code scanning alert](#code-scanning) when the job allows it
36
38
37
39
Files are checked in the open-java-format style, the formatter's only style. When the check fails, fix locally with a native binary or the runnable jar from the [open-java-format releases](https://github.com/openjavaformat/open-java-format/releases):
The action compares the `version` it runs with the latest [open-java-format release](https://github.com/openjavaformat/open-java-format/releases) and warns in the job log when a newer one is out. A log warning is easy to miss, so the check is also reported to code scanning: the action uploads a SARIF file with one alert while the version is behind, and with none once it is current, which closes the alert. The alert shows up under **Security → Code scanning** and in the **Code scanning results** check on pull requests, and points at the line of the workflow that names the version.
94
+
95
+
The upload needs the `security-events: write` permission, which a job gets like this:
96
+
97
+
```yaml
98
+
jobs:
99
+
format:
100
+
runs-on: ubuntu-latest
101
+
permissions:
102
+
contents: read
103
+
pull-requests: read # mode: changed reads the files of the pull request
104
+
security-events: write # the action reports its version check to code scanning
105
+
steps:
106
+
- uses: actions/checkout@v7
107
+
108
+
- uses: openjavaformat/open-java-format-action@v2
109
+
with:
110
+
version: '2.98.0.6'
111
+
```
112
+
113
+
Without the permission the upload is skipped with a line in the log, the check passes as before, and the log warning stays. Code scanning is free on public repositories; a private repository needs [GitHub Code Security](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-security-and-analysis-settings-for-your-repository) enabled. Pull requests from forks run with a read-only token and get the log warning only. To stop the upload altogether, set `code-scanning: false`.
114
+
115
+
One report per job is enough. When the job runs on a matrix, enable it on one leg only:
Copy file name to clipboardExpand all lines: action.yml
+143Lines changed: 143 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,10 @@ inputs:
15
15
description: 'Which files to check: "changed" for files from PR/push, "all" for every .java file'
16
16
required: false
17
17
default: 'changed'
18
+
code-scanning:
19
+
description: 'Report the version check to code scanning as well: "true" raises an alert under Security → Code scanning while a newer open-java-format is out, "false" keeps the check to the log warning. The upload needs the security-events: write permission and is skipped without it.'
A newer [open-java-format release](https://github.com/openjavaformat/open-java-format/releases) is out than the one this workflow checks formatting with. Releases fix formatting bugs, so code that passes with the pinned version may be formatted differently by the newer one.
159
+
160
+
To update:
161
+
162
+
- set the `version` input of `openjavaformat/open-java-format-action` to the new release;
163
+
- if the repository uses the pre-commit hook, set `FORMATTER_VERSION` at the top of it to the same release.
164
+
165
+
The alert closes on its own once the workflow runs with the latest release.
166
+
HELP_END
167
+
168
+
# One category per workflow and job, so that uploads from different jobs do not replace
169
+
# one another: open-java-format-action/ci.yml/format/
shortDescription: {text: "A newer open-java-format release is available"},
182
+
fullDescription: {text: "The workflow checks formatting with an open-java-format version older than the latest release. Releases fix formatting bugs, so code that passes with the pinned version may be formatted differently by the newer one."},
echo "Reported to code scanning: open-java-format $VERSION is the latest release."
208
+
else
209
+
echo "Reported to code scanning: an alert on $FILE:$LINE, open-java-format $LATEST is available."
210
+
fi
211
+
;;
212
+
403|404)
213
+
# No permission, no GitHub Code Security on a private repository, or the read-only
214
+
# token of a pull request from a fork. The log warning above stays.
215
+
echo "Code scanning did not accept the version check (HTTP $STATUS: $(jq -r '.message // empty' "$RESPONSE" 2>/dev/null)). To get it as a code scanning alert, give the job the 'security-events: write' permission; a private repository also needs GitHub Code Security. Set the code-scanning input to 'false' to stop these uploads."
216
+
;;
217
+
*)
218
+
echo "::warning::Could not report the version check to code scanning (HTTP $STATUS): $(cat "$RESPONSE" 2>/dev/null)"
0 commit comments