-
Notifications
You must be signed in to change notification settings - Fork 1
91 lines (79 loc) · 3.05 KB
/
Copy pathcheck-api-spec.yml
File metadata and controls
91 lines (79 loc) · 3.05 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
name: Check API Spec Changes
on:
schedule:
- cron: '0 9 * * *' # 9am UTC daily
workflow_dispatch: # allow manual runs
jobs:
check-spec:
runs-on: ubuntu-latest
permissions:
contents: write # to commit updated spec
issues: write # to create issues
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Download latest spec
run: curl -sf https://developers.kit.com/api-reference/v4.json -o spec/v4.new.json
- name: Check for changes
id: diff
run: node scripts/check-spec-changes.js
- name: Create GitHub issue
if: steps.diff.outputs.has_changes == 'true'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const title = fs.readFileSync('spec/.issue-title.txt', 'utf8').trim();
const body = fs.readFileSync('spec/.issue-body.md', 'utf8');
// Ensure label exists
try {
await github.rest.issues.getLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'api-spec-change',
});
} catch {
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'api-spec-change',
color: '0075ca',
description: 'Kit API spec has changed — CLI support may be needed',
});
}
// Don't open a duplicate if an identical-title issue is already open
const { data: existing } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: 'api-spec-change',
per_page: 10,
});
const duplicate = existing.find(i => i.title === title);
if (duplicate) {
core.info(`Issue already exists: ${duplicate.html_url}`);
return;
}
const { data: issue } = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title,
body,
labels: ['api-spec-change'],
});
core.info(`Created issue: ${issue.html_url}`);
- name: Commit updated spec
if: steps.diff.outputs.has_changes == 'true'
run: |
mv spec/v4.new.json spec/v4.json
rm -f spec/.issue-title.txt spec/.issue-body.md
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add spec/v4.json
git commit -m "chore: update Kit API spec snapshot [skip ci]"
git push
- name: Clean up temp files (no changes case)
if: steps.diff.outputs.has_changes != 'true'
run: rm -f spec/v4.new.json spec/.issue-title.txt spec/.issue-body.md