|
| 1 | +--- |
| 2 | +name: Bump API Diff Baseline |
| 3 | + |
| 4 | +# After release.yml publishes to Maven Central, push a baseline bump and |
| 5 | +# regenerated docs/apidiffs onto release-please's open snapshot-bump PR branch |
| 6 | +# (release-please--branches--main). The user merges a single PR that bumps to |
| 7 | +# the next -SNAPSHOT *and* updates the api-diff baseline, so there is no window |
| 8 | +# where main has a stale baseline. |
| 9 | +# |
| 10 | +# If the snapshot PR branch no longer exists (already merged), this workflow |
| 11 | +# fails loudly — re-run via workflow_dispatch after recreating it, or bump |
| 12 | +# manually. |
| 13 | + |
| 14 | +on: |
| 15 | + workflow_dispatch: |
| 16 | + inputs: |
| 17 | + tag: |
| 18 | + description: "Released tag (e.g. v1.8.0)" |
| 19 | + required: true |
| 20 | + |
| 21 | +permissions: {} |
| 22 | + |
| 23 | +env: |
| 24 | + SNAPSHOT_BRANCH: release-please--branches--main |
| 25 | + |
| 26 | +jobs: |
| 27 | + bump: |
| 28 | + runs-on: ubuntu-24.04 |
| 29 | + permissions: |
| 30 | + contents: write # push to the snapshot PR branch |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6 |
| 33 | + with: |
| 34 | + ref: ${{ env.SNAPSHOT_BRANCH }} |
| 35 | + persist-credentials: true |
| 36 | + - uses: jdx/mise-action@dba19683ed58901619b14f395a24841710cb4925 # v4.1.0 |
| 37 | + with: |
| 38 | + version: v2026.5.18 |
| 39 | + sha256: cfac593469d028d7ae5fe36e37bd7c59118b5238e92d8a876209578464f24a84 |
| 40 | + - name: Cache local Maven repository |
| 41 | + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 |
| 42 | + with: |
| 43 | + path: ~/.m2/repository |
| 44 | + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} |
| 45 | + restore-keys: | |
| 46 | + ${{ runner.os }}-maven- |
| 47 | + - name: Compute versions and bump baseline |
| 48 | + id: bump |
| 49 | + env: |
| 50 | + TAG: ${{ inputs.tag }} |
| 51 | + run: | |
| 52 | + NEW="${TAG#v}" |
| 53 | + baseline() { |
| 54 | + grep -oP '(?<=<api\.diff\.baseline\.version>)[^<]+' "$1" |
| 55 | + } |
| 56 | + OLD=$(baseline pom.xml) |
| 57 | + if [[ -z "$OLD" ]]; then |
| 58 | + echo "::error::Could not read api.diff.baseline.version" |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | + if [[ "$OLD" == "$NEW" ]]; then |
| 62 | + echo "Baseline already $NEW; nothing to do" |
| 63 | + echo "skip=true" >>"$GITHUB_OUTPUT" |
| 64 | + exit 0 |
| 65 | + fi |
| 66 | + sed -i -E \ |
| 67 | + "s|(<api\.diff\.baseline\.version>)[^<]+(</api\.diff\.baseline\.version>)|\1${NEW}\2|" \ |
| 68 | + pom.xml |
| 69 | + if [[ -d docs/apidiffs/current_vs_latest ]]; then |
| 70 | + cp -r docs/apidiffs/current_vs_latest "docs/apidiffs/${NEW}_vs_${OLD}" |
| 71 | + fi |
| 72 | + echo "old=${OLD}" >>"$GITHUB_OUTPUT" |
| 73 | + echo "new=${NEW}" >>"$GITHUB_OUTPUT" |
| 74 | + - name: Regenerate docs/apidiffs |
| 75 | + if: steps.bump.outputs.skip != 'true' |
| 76 | + run: mise run api-diff |
| 77 | + - name: Push to snapshot PR branch |
| 78 | + if: steps.bump.outputs.skip != 'true' |
| 79 | + env: |
| 80 | + NEW: ${{ steps.bump.outputs.new }} |
| 81 | + run: | |
| 82 | + git config user.name "github-actions[bot]" |
| 83 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 84 | + git add pom.xml docs/apidiffs |
| 85 | + OUTSIDE=$(git status --porcelain -- ':(exclude)pom.xml' ':(exclude)docs/apidiffs') |
| 86 | + if [[ -n "$OUTSIDE" ]]; then |
| 87 | + echo "::error::Unexpected changes outside pom.xml/docs/apidiffs:" |
| 88 | + echo "$OUTSIDE" |
| 89 | + exit 1 |
| 90 | + fi |
| 91 | + git commit -m "chore: bump api-diff baseline to ${NEW}" |
| 92 | + # Note: GITHUB_TOKEN pushes don't trigger CI re-runs on the PR. |
| 93 | + # Close and reopen the snapshot PR to trigger CI after this commit. |
| 94 | + git push origin "HEAD:${SNAPSHOT_BRANCH}" |
0 commit comments