-
Notifications
You must be signed in to change notification settings - Fork 0
80 lines (70 loc) · 2.33 KB
/
api-diff.yml
File metadata and controls
80 lines (70 loc) · 2.33 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
name: API diff
on:
pull_request:
paths:
- "specs/omada_api.json"
- "specs/snapshots/**"
- "scripts/diff-api.ts"
- ".github/workflows/api-diff.yml"
permissions:
contents: read
pull-requests: write
jobs:
diff:
name: OpenAPI operation diff
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Setup Node 22
uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Compute operation diff
run: pnpm spec:diff --output /tmp/api-diff.md
- name: Fail on breaking operation changes
# Non-additive changes (removed operations, moved method/path) break
# downstream SDK callers at compile time. Additions are reported in
# the PR comment but do not fail the workflow.
run: pnpm spec:diff --fail-on-breaking
- name: Upload diff as artefact
uses: actions/upload-artifact@v4
with:
name: api-diff
path: /tmp/api-diff.md
- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
const fs = require("node:fs");
const body = fs.readFileSync("/tmp/api-diff.md", "utf8");
const marker = "<!-- api-diff-comment -->";
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.data.find((c) => c.body && c.body.includes(marker));
const payload = `${marker}\n${body}`;
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: payload,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: payload,
});
}