|
| 1 | +--- |
| 2 | +name: Generate API Diff Baseline |
| 3 | + |
| 4 | +# When Renovate bumps <api.diff.baseline.version> (on the renovate/api-diff-baseline |
| 5 | +# branch), regenerate docs/apidiffs against the new baseline and push the result |
| 6 | +# back onto the PR. Renovate only proposes versions already published to Maven |
| 7 | +# Central, so japicmp can always resolve the new baseline. |
| 8 | +# |
| 9 | +# Before regenerating, the previous current_vs_latest is archived as |
| 10 | +# docs/apidiffs/<new>_vs_<old>/ to keep a per-release history (like |
| 11 | +# opentelemetry-java). This is an approximation of a release-vs-release diff: |
| 12 | +# the archived files compare the dev snapshot (which has just become <new>) |
| 13 | +# against <old>, so any commits merged between the release and this bump are |
| 14 | +# included too. |
| 15 | +# |
| 16 | +# Mirrors generate-protobuf.yml: a read-only `generate` job produces a patch |
| 17 | +# artifact and a privileged `publish` job pushes it back. |
| 18 | + |
| 19 | +on: |
| 20 | + push: |
| 21 | + branches: |
| 22 | + - "renovate/api-diff-baseline" |
| 23 | + |
| 24 | +permissions: {} |
| 25 | + |
| 26 | +jobs: |
| 27 | + generate: |
| 28 | + runs-on: ubuntu-24.04 |
| 29 | + permissions: |
| 30 | + contents: read # checkout + read-only `git fetch origin main` for the verify step |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 33 | + with: |
| 34 | + ref: ${{ github.ref }} |
| 35 | + persist-credentials: false |
| 36 | + - uses: jdx/mise-action@1648a7812b9aeae629881980618f079932869151 # v4.0.1 |
| 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: Archive the previous current_vs_latest |
| 48 | + run: | |
| 49 | + git fetch origin main |
| 50 | + baseline() { |
| 51 | + grep -oP '(?<=<api\.diff\.baseline\.version>)[^<]+' "$1" |
| 52 | + } |
| 53 | + OLD=$(git show origin/main:pom.xml | baseline /dev/stdin) |
| 54 | + NEW=$(baseline pom.xml) |
| 55 | + if [[ -z "$OLD" || -z "$NEW" ]]; then |
| 56 | + echo "::error::Could not read api.diff.baseline.version" |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | + if [[ "$OLD" == "$NEW" ]]; then |
| 60 | + echo "::error::api.diff.baseline.version unchanged ($NEW); nothing to bump" |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | + if [[ -d docs/apidiffs/current_vs_latest ]]; then |
| 64 | + cp -r docs/apidiffs/current_vs_latest "docs/apidiffs/${NEW}_vs_${OLD}" |
| 65 | + echo "Archived current_vs_latest as ${NEW}_vs_${OLD}" |
| 66 | + fi |
| 67 | + - name: Regenerate docs/apidiffs |
| 68 | + run: mise run api-diff |
| 69 | + - name: Validate and export docs/apidiffs as a patch |
| 70 | + run: | |
| 71 | + # Stage first so newly added files (the archived dir) are captured. |
| 72 | + git add docs/apidiffs |
| 73 | + OUTSIDE=$(git status --porcelain -- ':(exclude)docs/apidiffs') |
| 74 | + if [[ -n "$OUTSIDE" ]]; then |
| 75 | + echo "::error::Unexpected changes outside docs/apidiffs:" |
| 76 | + echo "$OUTSIDE" |
| 77 | + exit 1 |
| 78 | + fi |
| 79 | + git diff --cached -- docs/apidiffs > /tmp/api-diff-baseline.patch |
| 80 | + - name: Upload generated patch |
| 81 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 82 | + with: |
| 83 | + name: api-diff-baseline-patch |
| 84 | + path: /tmp/api-diff-baseline.patch |
| 85 | + retention-days: 5 |
| 86 | + |
| 87 | + publish: |
| 88 | + runs-on: ubuntu-24.04 |
| 89 | + needs: generate |
| 90 | + permissions: |
| 91 | + contents: write # push regenerated docs/apidiffs back to the renovate branch |
| 92 | + steps: |
| 93 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 94 | + with: |
| 95 | + ref: ${{ github.ref }} |
| 96 | + # zizmor: ignore[artipacked] -- needs credentials to push |
| 97 | + persist-credentials: true |
| 98 | + - name: Download generated patch |
| 99 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 100 | + with: |
| 101 | + name: api-diff-baseline-patch |
| 102 | + path: /tmp/patch |
| 103 | + - name: Commit and push regenerated docs/apidiffs |
| 104 | + run: | |
| 105 | + PATCH=/tmp/patch/api-diff-baseline.patch |
| 106 | + if [[ ! -s "$PATCH" ]]; then |
| 107 | + echo "No regenerated changes to commit" |
| 108 | + exit 0 |
| 109 | + fi |
| 110 | + git apply "$PATCH" |
| 111 | + # Note: GITHUB_TOKEN pushes don't trigger CI re-runs. |
| 112 | + # Close and reopen the PR to trigger CI after this commit. |
| 113 | + git config user.name "github-actions[bot]" |
| 114 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 115 | + git add docs/apidiffs |
| 116 | + git commit -m "chore: regenerate docs/apidiffs" |
| 117 | + git push |
0 commit comments