Skip to content

Commit d7aa84f

Browse files
authored
ci: add API diff workflow (#9600)
Co-authored-by: knqyf263 <[email protected]>
1 parent 05375d1 commit d7aa84f

File tree

4 files changed

+133
-4
lines changed

4 files changed

+133
-4
lines changed

.github/workflows/apidiff.yaml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: API Diff Check
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
paths:
7+
- 'pkg/**/*.go'
8+
- 'rpc/**/*.go'
9+
10+
permissions:
11+
contents: read
12+
pull-requests: write
13+
issues: write
14+
15+
jobs:
16+
apidiff:
17+
runs-on: ubuntu-24.04
18+
name: API Diff Check
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
22+
23+
- name: Set up Go
24+
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
25+
with:
26+
go-version-file: go.mod
27+
cache: false
28+
29+
# Ensure the base commit exists locally when checkout uses depth=1 (default).
30+
- name: Fetch base commit
31+
run: |
32+
BASE_REF="${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}"
33+
if [ -n "$BASE_REF" ]; then
34+
git fetch --depth=1 origin "$BASE_REF"
35+
fi
36+
37+
# NOTE: go-apidiff is not managed in go.mod because installing it via `go get -tool`
38+
# would cause `mage tool:install` to attempt building it on Windows, which currently
39+
# fails due to platform-specific issues.
40+
- name: Run go-apidiff
41+
id: apidiff
42+
continue-on-error: true
43+
uses: joelanford/go-apidiff@60c4206be8f84348ebda2a3e0c3ac9cb54b8f685 # v0.8.3
44+
with:
45+
version: v0.8.3
46+
47+
- name: Add apidiff label
48+
if: ${{ steps.apidiff.outputs.semver-type == 'major' }}
49+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
50+
with:
51+
script: |
52+
const label = 'apidiff';
53+
await github.rest.issues.addLabels({
54+
owner: context.repo.owner,
55+
repo: context.repo.repo,
56+
issue_number: context.issue.number,
57+
labels: [label],
58+
});
59+
60+
- name: Comment API diff
61+
if: ${{ steps.apidiff.outputs.semver-type == 'major' }}
62+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
63+
env:
64+
APIDIFF_OUTPUT: ${{ steps.apidiff.outputs.output }}
65+
SEMVER_TYPE: ${{ steps.apidiff.outputs.semver-type }}
66+
with:
67+
script: |
68+
const header = '## 📊 API Changes Detected';
69+
const diff = process.env.APIDIFF_OUTPUT.trim();
70+
const semver = process.env.SEMVER_TYPE || 'unknown';
71+
const body = [
72+
header,
73+
'',
74+
`Semver impact: \`${semver}\``,
75+
'',
76+
'```',
77+
diff,
78+
'```',
79+
].join('\n');
80+
81+
const { data: comments } = await github.rest.issues.listComments({
82+
owner: context.repo.owner,
83+
repo: context.repo.repo,
84+
issue_number: context.issue.number,
85+
});
86+
87+
const existing = comments.find(comment =>
88+
comment.user.type === 'Bot' &&
89+
comment.body.startsWith(header),
90+
);
91+
92+
if (existing) {
93+
await github.rest.issues.updateComment({
94+
owner: context.repo.owner,
95+
repo: context.repo.repo,
96+
comment_id: existing.id,
97+
body,
98+
});
99+
} else {
100+
await github.rest.issues.createComment({
101+
owner: context.repo.owner,
102+
repo: context.repo.repo,
103+
issue_number: context.issue.number,
104+
body,
105+
});
106+
}
107+
108+
# Attempt to request the premium reviewers; needs org-scoped token because GITHUB_TOKEN lacks read:org.
109+
- name: Request trivy-premium review
110+
if: ${{ steps.apidiff.outputs.semver-type == 'major' }}
111+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
112+
with:
113+
github-token: ${{ secrets.ORG_REPO_TOKEN }}
114+
script: |
115+
try {
116+
await github.rest.pulls.requestReviewers({
117+
owner: context.repo.owner,
118+
repo: context.repo.repo,
119+
pull_number: context.issue.number,
120+
team_reviewers: ['trivy-premium'],
121+
});
122+
console.log('Requested review from aquasecurity/trivy-premium team');
123+
} catch (error) {
124+
core.error(`Failed to request trivy-premium reviewers: ${error.message}`);
125+
throw error;
126+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ require (
153153
cloud.google.com/go/storage v1.55.0 // indirect
154154
connectrpc.com/connect v1.18.1 // indirect
155155
connectrpc.com/otelconnect v0.7.2 // indirect
156-
dario.cat/mergo v1.0.1 // indirect
156+
dario.cat/mergo v1.0.2 // indirect
157157
github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2 // indirect
158158
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c // indirect
159159
github.com/AzureAD/microsoft-authentication-library-for-go v1.5.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ cuelabs.dev/go/oci/ociregistry v0.0.0-20240314152124-224736b49f2e h1:GwCVItFUPxw
5555
cuelabs.dev/go/oci/ociregistry v0.0.0-20240314152124-224736b49f2e/go.mod h1:ApHceQLLwcOkCEXM1+DyCXTHEJhNGDpJ2kmV6axsx24=
5656
cuelang.org/go v0.8.1 h1:VFYsxIFSPY5KgSaH1jQ2GxHOrbu6Ga3kEI70yCZwnOg=
5757
cuelang.org/go v0.8.1/go.mod h1:CoDbYolfMms4BhWUlhD+t5ORnihR7wvjcfgyO9lL5FI=
58-
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
59-
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
58+
dario.cat/mergo v1.0.2 h1:85+piFYR1tMbRrLcDwR18y4UKJ3aH1Tbzi24VRW1TK8=
59+
dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA=
6060
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
6161
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
6262
github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 h1:He8afgbRMd7mFxO99hRNu+6tazq8nFF9lIwo9JFroBk=

misc/triage/labels.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,7 @@ labels:
143143
# automation
144144
- name: autoready
145145
color: 1d76db
146-
description: Automatically mark PR as ready for review when all checks pass
146+
description: Automatically mark PR as ready for review when all checks pass
147+
- name: apidiff
148+
color: ededed
149+
description: Indicates Go API changes relevant to library consumers (CLI compatibility may be unaffected)

0 commit comments

Comments
 (0)