|
| 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 |
0 commit comments