Skip to content

Commit 39b3711

Browse files
committed
Follow open-java-format releases from CI
Until now every open-java-format release meant changing ojf_version in zensical.toml by hand and pushing. The "Follow open-java-format releases" workflow now does that once an hour: when the latest GitHub release differs from ojf_version, it changes that line, pushes the bump to main and runs Documentation on it to deploy the site. Documentation gains workflow_dispatch for that run, because a push made with the workflow's own token starts no push-triggered workflow, and it deploys on any run that is not a pull request. The GitHub Action page's table now writes the action's default as {{ ojf_version }}: the action follows the releases the same way since openjavaformat/open-java-format-action@6e1a02b, so the two no longer drift apart.
1 parent a1e5ba8 commit 39b3711

3 files changed

Lines changed: 63 additions & 3 deletions

File tree

‎.github/workflows/docs.yml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
branches:
88
- main
99
pull_request:
10+
workflow_dispatch: # Follow open-java-format releases runs this on the bump it pushes
1011

1112
permissions:
1213
contents: read
@@ -34,15 +35,16 @@ jobs:
3435
- name: Build the site
3536
run: zensical build --clean --strict
3637

38+
# A pull request is only built. A push and the dispatched run above deploy.
3739
- name: Upload the Pages artifact
38-
if: github.event_name == 'push'
40+
if: github.event_name != 'pull_request'
3941
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
4042
with:
4143
path: site
4244

4345
deploy:
4446
name: deploy
45-
if: github.event_name == 'push'
47+
if: github.event_name != 'pull_request'
4648
needs: build
4749
runs-on: ubuntu-latest
4850
permissions:
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Follow open-java-format releases
2+
3+
# The pages install the formatter version that zensical.toml names as ojf_version. Once an hour this
4+
# compares it with the latest release of openjavaformat/open-java-format. When a new release is out,
5+
# that line is changed, the result is pushed to main, and Documentation is run on it to deploy the
6+
# site. That run has to be explicit: a push made with the workflow's own token starts no
7+
# push-triggered workflow. Nothing but that line changes: the pages name earlier versions as
8+
# history, on Migrate for instance, and those stay as written.
9+
10+
on:
11+
schedule:
12+
- cron: '17 * * * *' # not on the hour, when GitHub's schedule queue is longest
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/^ojf_version = "\(.*\)"$/\1/p' zensical.toml)
35+
release=$(gh release view --repo openjavaformat/open-java-format --json tagName,publishedAt)
36+
latest=$(jq -r .tagName <<< "$release")
37+
published=$(jq -r '.publishedAt[:10]' <<< "$release")
38+
if [ "$latest" = "$current" ]; then
39+
echo "Already on $current."
40+
exit 0
41+
fi
42+
43+
# The dots are escaped so that sed takes them literally.
44+
sed -i "s/^ojf_version = \"${current//./\\.}\"$/ojf_version = \"$latest\"/" zensical.toml
45+
git diff
46+
47+
git config user.name 'github-actions[bot]'
48+
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
49+
git commit --all --quiet --file - <<COMMIT
50+
Install open-java-format $latest
51+
52+
The pages install $latest, which openjavaformat/open-java-format
53+
released on $published. Made by the "$GITHUB_WORKFLOW" workflow:
54+
$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
55+
COMMIT
56+
gh auth setup-git
57+
git push origin HEAD:main
58+
gh workflow run docs.yml --ref main

‎docs/get-started/github-actions.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ the files that are not formatted and fails the job if there are any.
2929
3030
| Input | Default | Meaning |
3131
| --- | --- | --- |
32-
| `version` | `2.98.0.5` | The formatter version to download |
32+
| `version` | `{{ ojf_version }}` | The formatter version to download |
3333
| `mode` | `changed` | `changed` checks the files of the pull request or push, `all` checks every `.java` file |
3434

3535
A workflow that still pins 2.98.0.1 stays on `@v1`: that version needs the `--ojf` flag, which `@v2`

0 commit comments

Comments
 (0)