diff --git a/.github/workflows/follow-releases.yml b/.github/workflows/follow-releases.yml index 37117d3..3849683 100644 --- a/.github/workflows/follow-releases.yml +++ b/.github/workflows/follow-releases.yml @@ -1,11 +1,17 @@ name: Follow open-java-format releases -# The pages install the formatter version that zensical.toml names as ojf_version. Once an hour this -# compares it with the latest release of openjavaformat/open-java-format. When a new release is out, -# that line is changed, the result is pushed to main, and Documentation is run on it to deploy the -# site. That run has to be explicit: a push made with the workflow's own token starts no -# push-triggered workflow. Nothing but that line changes: the pages name earlier versions as -# history, on Migrate for instance, and those stay as written. +# The pages install the formatter versions that zensical.toml names. Once an hour this compares +# them with the releases of openjavaformat/open-java-format: +# +# - ojf_version with the latest release; +# - ojf_17_version with the newest release of the 17 line, which is never the latest release, and +# ojf_17_native_version with the newest 21 release of the same minor version, whose native binary +# the 17 line's Gradle plugin runs. +# +# When a new release is out, those lines are changed, the result is pushed to main, and Documentation +# is run on it to deploy the site. That run has to be explicit: a push made with the workflow's own +# token starts no push-triggered workflow. Nothing but those lines changes: the pages name earlier +# versions as history, on Migrate for instance, and those stay as written. on: schedule: @@ -31,29 +37,47 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: | - current=$(sed -n 's/^ojf_version = "\(.*\)"$/\1/p' zensical.toml) - release=$(gh release view --repo openjavaformat/open-java-format --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. - 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." + # The newest published release whose tag starts with $1, drafts and prereleases left out. + newest() { + gh release list --repo openjavaformat/open-java-format --limit 1000 \ + --json tagName,isDraft,isPrerelease \ + --jq '.[] | select((.isDraft or .isPrerelease) | not) | .tagName' \ + | grep -E "^${1//./\\.}" | sort -V | tail -n 1 || true + } + bumped=() + # Sets the line `$1 = "..."` of zensical.toml to the version $2, when $2 is higher. A fix for an + # older line can come out after a newer line started: only a higher version number is a bump. + bump() { + local key=$1 version=$2 current higher + current=$(sed -n "s/^$key = \"\(.*\)\"$/\1/p" zensical.toml) + higher=$(printf '%s\n' "$current" "$version" | sort -V | tail -n 1) + if [ -z "$version" ] || [ "$version" = "$current" ] || [ "$higher" != "$version" ]; then + echo "$key stays $current; the release found is ${version:-none}." + return + fi + # The dots are escaped so that sed takes them literally. + sed -i "s/^$key = \"${current//./\\.}\"$/$key = \"$version\"/" zensical.toml + bumped+=("$key $current -> $version") + } + + bump ojf_version "$(gh release view --repo openjavaformat/open-java-format --json tagName --jq .tagName)" + bump ojf_17_version "$(newest 17.)" + minor=$(sed -n 's/^ojf_17_version = "17\.\([0-9]*\)\..*"$/\1/p' zensical.toml) + bump ojf_17_native_version "$(newest "21.${minor}.")" + + if [ "${#bumped[@]}" -eq 0 ]; then exit 0 fi - - # The dots are escaped so that sed takes them literally. - sed -i "s/^ojf_version = \"${current//./\\.}\"$/ojf_version = \"$latest\"/" zensical.toml git diff git config user.name 'github-actions[bot]' git config user.email '41898282+github-actions[bot]@users.noreply.github.com' git commit --all --quiet --file - < com.diffplug.spotless diff --git a/zensical.toml b/zensical.toml index ee8b2c4..948e325 100644 --- a/zensical.toml +++ b/zensical.toml @@ -119,6 +119,11 @@ toggle.name = "Switch to system preference" # extra.version: the theme reads that one as the switch for a version selector. [project.extra] ojf_version = "21.1.2" +# The 17 line, for builds on JDK 17 to 20, and the 21 release of the same minor version, whose native binary its +# Gradle plugin runs. follow-releases.yml moves these two with each release as well: a 17.x is never the latest +# release, so it looks for the newest of each line. +ojf_17_version = "17.1.0" +ojf_17_native_version = "21.1.2" # The Maven plugin is released from its own repository, openjavaformat/fmt-maven-plugin, with version # numbers of its own. follow-maven-plugin-releases.yml bumps it on each release of the plugin. maven_plugin_version = "2.27.0.2"