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