|
| 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 | +# Mirrors generate-protobuf.yml: a read-only `generate` job produces a patch |
| 10 | +# artifact and a privileged `publish` job pushes it back. |
| 11 | + |
| 12 | +on: |
| 13 | + push: |
| 14 | + branches: |
| 15 | + - "renovate/api-diff-baseline" |
| 16 | + |
| 17 | +permissions: {} |
| 18 | + |
| 19 | +jobs: |
| 20 | + generate: |
| 21 | + runs-on: ubuntu-24.04 |
| 22 | + permissions: |
| 23 | + contents: read # checkout + read-only `git fetch origin main` for the verify step |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 26 | + with: |
| 27 | + ref: ${{ github.ref }} |
| 28 | + persist-credentials: false |
| 29 | + - uses: jdx/mise-action@1648a7812b9aeae629881980618f079932869151 # v4.0.1 |
| 30 | + with: |
| 31 | + version: v2026.5.18 |
| 32 | + sha256: cfac593469d028d7ae5fe36e37bd7c59118b5238e92d8a876209578464f24a84 |
| 33 | + - name: Cache local Maven repository |
| 34 | + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 |
| 35 | + with: |
| 36 | + path: ~/.m2/repository |
| 37 | + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} |
| 38 | + restore-keys: | |
| 39 | + ${{ runner.os }}-maven- |
| 40 | + - name: Verify the baseline version was updated |
| 41 | + run: | |
| 42 | + git fetch origin main |
| 43 | + if ! git diff origin/main -- pom.xml | grep -q 'api.diff.baseline.version'; then |
| 44 | + echo "::error::api.diff.baseline.version not updated in pom.xml" |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | + - name: Regenerate docs/apidiffs |
| 48 | + run: mise run api-diff |
| 49 | + - name: Validate and export docs/apidiffs as a patch |
| 50 | + run: | |
| 51 | + UNEXPECTED=$(git diff --name-only | grep -v '^docs/apidiffs/' || true) |
| 52 | + if [[ -n "$UNEXPECTED" ]]; then |
| 53 | + echo "::error::Unexpected files changed:" |
| 54 | + echo "$UNEXPECTED" |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | + git diff > /tmp/api-diff-baseline.patch |
| 58 | + - name: Upload generated patch |
| 59 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 60 | + with: |
| 61 | + name: api-diff-baseline-patch |
| 62 | + path: /tmp/api-diff-baseline.patch |
| 63 | + retention-days: 5 |
| 64 | + |
| 65 | + publish: |
| 66 | + runs-on: ubuntu-24.04 |
| 67 | + needs: generate |
| 68 | + permissions: |
| 69 | + contents: write # push regenerated docs/apidiffs back to the renovate branch |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 72 | + with: |
| 73 | + ref: ${{ github.ref }} |
| 74 | + # zizmor: ignore[artipacked] -- needs credentials to push |
| 75 | + persist-credentials: true |
| 76 | + - name: Download generated patch |
| 77 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 78 | + with: |
| 79 | + name: api-diff-baseline-patch |
| 80 | + path: /tmp/patch |
| 81 | + - name: Commit and push regenerated docs/apidiffs |
| 82 | + run: | |
| 83 | + PATCH=/tmp/patch/api-diff-baseline.patch |
| 84 | + if [[ ! -s "$PATCH" ]]; then |
| 85 | + echo "No regenerated changes to commit" |
| 86 | + exit 0 |
| 87 | + fi |
| 88 | + git apply "$PATCH" |
| 89 | + # Note: GITHUB_TOKEN pushes don't trigger CI re-runs. |
| 90 | + # Close and reopen the PR to trigger CI after this commit. |
| 91 | + git config user.name "github-actions[bot]" |
| 92 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 93 | + git add docs/apidiffs |
| 94 | + git commit -m "chore: regenerate docs/apidiffs" |
| 95 | + git push |
0 commit comments