-
-
Notifications
You must be signed in to change notification settings - Fork 35
143 lines (126 loc) · 4.71 KB
/
extract-api.yml
File metadata and controls
143 lines (126 loc) · 4.71 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: Extract Typesense API
on:
workflow_dispatch:
schedule:
- cron: "17 4 * * *"
push:
branches:
- master
paths:
- "src/**"
- "config.json"
- "package.json"
- "package-lock.json"
- "tsconfig.json"
- ".github/workflows/extract-api.yml"
permissions:
contents: write
issues: write
jobs:
extract:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- name: Install dependencies
run: npm ci
- name: Build CLI
run: npm run build
- name: Save previous extracted spec
run: |
if git cat-file -e HEAD:output/typesense_api_spec.json 2>/dev/null; then
git show HEAD:output/typesense_api_spec.json > "$RUNNER_TEMP/previous-typesense-api-spec.json"
else
printf '%s\n' '{"rootDir":"","routeFile":"","routes":[],"diagnostics":[]}' > "$RUNNER_TEMP/previous-typesense-api-spec.json"
fi
- name: Run extractor
id: extract
continue-on-error: true
run: node dist/cli.js extract --config ./config.json --fail-on-diagnostics
- name: Upload extractor artifacts for debugging
if: steps.extract.outcome != 'success'
uses: actions/upload-artifact@v4
with:
name: extractor-debug-artifacts
if-no-files-found: warn
path: |
output/typesense_api_spec.json
output/typesense_api_diagnostics.json
- name: Stop on extractor diagnostics
if: steps.extract.outcome != 'success'
run: exit 1
- name: Check for extracted output changes
id: changes
run: |
if git diff --quiet -- output/typesense_api_spec.json output/typesense_api_diagnostics.json; then
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Build semantic API diff
if: steps.changes.outputs.changed == 'true'
run: |
node dist/cli.js semantic-diff \
--previous "$RUNNER_TEMP/previous-typesense-api-spec.json" \
--next output/typesense_api_spec.json \
--json-output "$RUNNER_TEMP/typesense-api-diff.json" \
--markdown-output "$RUNNER_TEMP/typesense-api-diff.md"
- name: Read semantic API diff result
if: steps.changes.outputs.changed == 'true'
id: semantic_diff
run: |
jq -r '"changed=\(.changed)"' "$RUNNER_TEMP/typesense-api-diff.json" >> "$GITHUB_OUTPUT"
- name: Commit extracted artifacts
if: steps.changes.outputs.changed == 'true'
id: commit_artifacts
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add output/typesense_api_spec.json output/typesense_api_diagnostics.json
git commit -m "chore: update extracted Typesense API artifacts"
git push
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Open OpenAPI update issue
if: steps.changes.outputs.changed == 'true' && steps.semantic_diff.outputs.changed == 'true'
uses: actions/github-script@v7
with:
script: |
const fs = require("node:fs");
const owner = context.repo.owner;
const repo = context.repo.repo;
const commitSha = "${{ steps.commit_artifacts.outputs.sha }}";
const shortSha = commitSha.slice(0, 12);
const commitUrl = `https://github.com/${owner}/${repo}/commit/${commitSha}`;
const title = `Update openapi.yml for extracted Typesense API changes [${shortSha}]`;
const existing = await github.paginate(github.rest.issues.listForRepo, {
owner,
repo,
state: "open",
per_page: 100,
});
const alreadyOpen = existing.some((issue) => issue.title === title);
if (alreadyOpen) {
core.info(`Open issue already exists: ${title}`);
return;
}
const bodyPath = `${process.env.RUNNER_TEMP}/typesense-api-diff.md`;
const diffBody = fs.readFileSync(bodyPath, "utf8");
const body = [
"<!-- typesense-api-sync-issue -->",
`Commit: ${commitUrl}`,
"",
diffBody,
].join("\n");
await github.rest.issues.create({
owner,
repo,
title,
body,
});