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 29c2b7d
Browse filesBrowse the repository at this point in the historyBrowse files
The report needs the security-events: write permission, which the
default token does not have, so with it on by default every workflow
that uses the action would have to add a permissions block, and one
that did not would skip the upload on every run. The code-scanning
input now defaults to false; a workflow that wants the alert sets it
to true and grants the permission, as the README shows. The example
workflow loses the permissions block it no longer needs.
Test Action turns the report on in both jobs: with the permission in
the mode=changed job, where the upload has to go through, and without
it on the first run of the platform matrix, where it has to be
skipped without failing the check.
Copy file name to clipboardExpand all lines: README.md
+8-7Lines changed: 8 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +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
+
| `code-scanning` | no | `false` | Also report the version check to [code scanning](#code-scanning); needs the `security-events: write` permission |
26
26
27
27
## How `mode: changed` works
28
28
@@ -34,7 +34,7 @@ v2 is for open-java-format 2.98.0.2 and later, which has a single style. A workf
34
34
35
35
- If all files are formatted correctly → passes ✅
36
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
37
+
- If a newer open-java-format release is out → warns in the job log, and raises a [code scanning alert](#code-scanning) when that is turned on
38
38
39
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):
40
40
@@ -90,9 +90,9 @@ jobs:
90
90
91
91
## Code scanning
92
92
93
-
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.
93
+
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 can also be reported to code scanning: the action then 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
94
95
-
The upload needs the `security-events: write` permission, which a job gets like this:
95
+
This is off by default, because the upload needs the `security-events: write` permission, which the default token does not have. To turn it on, set `code-scanning: true` and give the job the permission:
96
96
97
97
```yaml
98
98
jobs:
@@ -101,18 +101,19 @@ jobs:
101
101
permissions:
102
102
contents: read
103
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
104
+
security-events: write # the code scanning upload
105
105
steps:
106
106
- uses: actions/checkout@v7
107
107
108
108
- uses: openjavaformat/open-java-format-action@v2
109
109
with:
110
110
version: '2.98.0.6'
111
+
code-scanning: true
111
112
```
112
113
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
+
The `permissions` block replaces the default permissions of the job, so it has to name everything else the job needs, such as `contents: read` for the checkout. If the permission is missing anyway, 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.
114
115
115
-
One report per job is enough. When the job runs on a matrix, enable it on one leg only:
116
+
One report per job is enough. When the job runs on a matrix, turn it on for one leg only:
Copy file name to clipboardExpand all lines: action.yml
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -16,9 +16,9 @@ inputs:
16
16
required: false
17
17
default: 'changed'
18
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.'
19
+
description: 'Also report the version check to code scanning: "true" raises an alert under Security → Code scanning while a newer open-java-format is out. Off by default, because the upload needs the security-events: write permission; without it the upload is skipped.'
0 commit comments