Repository navigation
91 lines (82 loc) · 3.35 KB
/
Copy pathapi-diff.yml
File metadata and controls
91 lines (82 loc) · 3.35 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
# 外部アプリ向け API 面 (openapi.json / bindings.ts) を変更する PR に
# その diff を sticky コメントで貼り、レビューで API の変化を見えるようにする。
# スナップショットはコミット済みなのでビルド不要、git diff を貼るだけ。
name: API Diff
on:
pull_request:
paths:
- 'src-tauri/openapi.json'
- 'src/bindings.ts'
permissions:
contents: read
pull-requests: write
jobs:
report:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
- name: Generate diff
env:
BASE_REF: ${{ github.base_ref }}
run: |
git fetch --no-tags --depth=1 origin "$BASE_REF"
git diff "origin/$BASE_REF" HEAD -- src-tauri/openapi.json src/bindings.ts > /tmp/api.diff
git diff --stat "origin/$BASE_REF" HEAD -- src-tauri/openapi.json src/bindings.ts > /tmp/api.stat
- name: Report
uses: actions/github-script@v9
with:
script: |
const fs = require('fs')
const marker = '<!-- notedeck-api-diff -->'
const stat = fs.readFileSync('/tmp/api.stat', 'utf8').trim()
let diff = fs.readFileSync('/tmp/api.diff', 'utf8')
// PR コメントは 64KB 上限。超えたら切り詰めて Files changed へ誘導する
const limit = 60000
const truncated = diff.length > limit
if (truncated) diff = `${diff.slice(0, limit)}\n... (truncated)`
const body = [
marker,
'## API surface diff',
'',
'外部アプリ向け API 面 (`src-tauri/openapi.json` / `src/bindings.ts`) が変更されています。',
'互換性への影響 (#709) をレビューしてください。',
'',
'```',
stat || '(no diff)',
'```',
'',
'<details><summary>Full diff</summary>',
'',
'````diff',
diff,
'````',
'',
'</details>',
truncated ? '\n> [!NOTE]\n> サイズ上限のため省略あり。全文は Files changed を参照。' : '',
].join('\n')
await core.summary.addRaw(body).write()
// fork からの PR では GITHUB_TOKEN に書き込み権限が無いため、
// コメント投稿に失敗しても job は落とさない (summary には常に出る)
try {
const { owner, repo } = context.repo
const issue_number = context.issue.number
const { data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number,
per_page: 100,
})
const existing = comments.find((c) => c.body.includes(marker))
if (existing) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existing.id,
body,
})
} else {
await github.rest.issues.createComment({ owner, repo, issue_number, body })
}
} catch (e) {
core.warning(`PR コメントを投稿できなかった (fork PR では想定内): ${e.message}`)
}