Skip to content

Commit 720cc9b

Browse files
committed
Follow fmt-maven-plugin releases from CI
Every release of the Maven plugin meant changing maven_plugin_version in zensical.toml by hand. The "Follow fmt-maven-plugin releases" workflow now does that once an hour, the way "Follow open-java-format releases" does for ojf_version: when the latest GitHub release of openjavaformat/fmt-maven-plugin is a higher version, it changes that line, pushes the bump to main and runs Documentation on it to deploy the site. It is a copy of that workflow rather than a second job in it, and it runs at minute 47 instead of 17, so that the two never push to main at once.
1 parent f2643c2 commit 720cc9b

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Follow fmt-maven-plugin releases
2+
3+
# The pages add the Maven plugin with the version that zensical.toml names as maven_plugin_version.
4+
# Once an hour this compares it with the latest release of openjavaformat/fmt-maven-plugin. When a
5+
# new release is out, that line is changed, the result is pushed to main, and Documentation is run
6+
# on it to deploy the site. That run has to be explicit: a push made with the workflow's own token
7+
# starts no push-triggered workflow. follow-releases.yml does the same for ojf_version half an hour
8+
# apart, so that the two never push to main at once.
9+
10+
on:
11+
schedule:
12+
- cron: '47 * * * *' # half an hour after follow-releases.yml, and not on the hour
13+
workflow_dispatch:
14+
15+
permissions: {}
16+
17+
jobs:
18+
bump:
19+
name: Bump to the latest release
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: write # push to main
23+
actions: write # run Documentation
24+
steps:
25+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
26+
with:
27+
persist-credentials: false
28+
29+
- name: Bump when a new release is out
30+
shell: bash
31+
env:
32+
GH_TOKEN: ${{ github.token }}
33+
run: |
34+
current=$(sed -n 's/^maven_plugin_version = "\(.*\)"$/\1/p' zensical.toml)
35+
release=$(gh release view --repo openjavaformat/fmt-maven-plugin --json tagName,publishedAt)
36+
latest=$(jq -r .tagName <<< "$release")
37+
published=$(jq -r '.publishedAt[:10]' <<< "$release")
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."
43+
exit 0
44+
fi
45+
46+
# The dots are escaped so that sed takes them literally.
47+
sed -i "s/^maven_plugin_version = \"${current//./\\.}\"$/maven_plugin_version = \"$latest\"/" zensical.toml
48+
git diff
49+
50+
git config user.name 'github-actions[bot]'
51+
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
52+
git commit --all --quiet --file - <<COMMIT
53+
Install fmt-maven-plugin $latest
54+
55+
The pages install fmt-maven-plugin $latest, which
56+
openjavaformat/fmt-maven-plugin released on $published. Made by the
57+
"$GITHUB_WORKFLOW" workflow:
58+
$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
59+
COMMIT
60+
gh auth setup-git
61+
git push origin HEAD:main
62+
gh workflow run docs.yml --ref main

‎zensical.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ toggle.name = "Switch to system preference"
109109
[project.extra]
110110
ojf_version = "2.98.0.6"
111111
# The Maven plugin is released from its own repository, openjavaformat/fmt-maven-plugin, with version
112-
# numbers of its own. Bump it on each release of the plugin.
112+
# numbers of its own. follow-maven-plugin-releases.yml bumps it on each release of the plugin.
113113
maven_plugin_version = "2.27.0.1"
114114

115115
# Renders every page as a Jinja template, for {{ ojf_version }}. A misspelt variable or a stray {{

0 commit comments

Comments
 (0)