Skip to content

Commit 87d6884

Browse files
committed
Warn only about a higher version
The check compared the pinned version with the latest release for equality, so any other version counted as newer. GitHub's latest release is the one published last, and a fix for an older line can come out after a newer line started: with open-java-format numbered 21.x now, a 2.98.0.7 would have told every repository on 21 to update, and the hourly bump would have moved this repository back to it. Now the warning and the code scanning alert come only when the latest release sorts after the pinned one by version number, and the hourly bump only goes upward. The `latest` step hands the decision on as its `newer` output, so the two steps cannot disagree.
1 parent 47d9951 commit 87d6884

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎.github/workflows/follow-releases.yml‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ jobs:
3535
release=$(gh release view --repo openjavaformat/open-java-format --json tagName,publishedAt)
3636
latest=$(jq -r .tagName <<< "$release")
3737
published=$(jq -r '.publishedAt[:10]' <<< "$release")
38-
if [ "$latest" = "$current" ]; then
39-
echo "Already on $current."
38+
# The latest release is the one published last, and a fix for an older line can come out
39+
# after a newer line started: only a higher version number is a bump.
40+
newer=$(printf '%s\n' "$current" "$latest" | sort -V | tail -n 1)
41+
if [ "$latest" = "$current" ] || [ "$newer" != "$latest" ]; then
42+
echo "Already on $current; the latest release is $latest."
4043
exit 0
4144
fi
4245

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ jobs:
127127

128128
## Code scanning
129129

130-
The action compares the version in `.open-java-format-version` 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 `.open-java-format-version`.
130+
The action compares the version in `.open-java-format-version` 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. Newer is a higher version number: a repository on a release ahead of the latest one gets no warning. 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 `.open-java-format-version`.
131131

132132
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, as in the [second recommended setup](#with-the-version-check-in-code-scanning-too). 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.
133133

‎action.yml‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,17 @@ runs:
9090
https://api.github.com/repos/openjavaformat/open-java-format/releases/latest 2>/dev/null \
9191
| jq -r '.tag_name // empty' 2>/dev/null || true)
9292
93+
# Newer is a higher version number, not merely a different one: the latest release is the
94+
# one published last, and a fix for an older line can come out after a newer line started.
9395
echo "version=$LATEST" >> "$GITHUB_OUTPUT"
96+
NEWER=false
9497
if [ -z "$LATEST" ]; then
9598
echo "Could not check the latest open-java-format version — skipping this check."
96-
elif [ "$LATEST" != "$VERSION" ]; then
99+
elif [ "$LATEST" != "$VERSION" ] && [ "$(printf '%s\n' "$VERSION" "$LATEST" | sort -V | tail -n 1)" = "$LATEST" ]; then
100+
NEWER=true
97101
echo "::warning file=.open-java-format-version,line=1::A newer open-java-format version is available: $LATEST (.open-java-format-version has $VERSION)"
98102
fi
103+
echo "newer=$NEWER" >> "$GITHUB_OUTPUT"
99104
100105
- name: Report the version check to code scanning
101106
if: inputs.code-scanning == 'true' && steps.latest.outputs.version != ''
@@ -104,6 +109,7 @@ runs:
104109
GH_TOKEN: ${{ github.token }}
105110
VERSION: ${{ steps.version.outputs.version }}
106111
LATEST: ${{ steps.latest.outputs.version }}
112+
NEWER: ${{ steps.latest.outputs.newer }}
107113
run: |
108114
# A log warning is easy to miss, so the check is also handed to code scanning: a SARIF
109115
# file with one alert while a newer release is out, and with none once the version is
@@ -121,7 +127,7 @@ runs:
121127
WORKFLOW="${WORKFLOW%@*}"
122128
123129
RESULTS='[]'
124-
if [ "$LATEST" != "$VERSION" ]; then
130+
if [ "$NEWER" = true ]; then
125131
FILE=".open-java-format-version"
126132
LINE=1
127133
# Code scanning tells alerts apart by this fingerprint, made from the line's text.

0 commit comments

Comments
 (0)