-
Notifications
You must be signed in to change notification settings - Fork 2
99 lines (87 loc) · 3.78 KB
/
update-cofhe-errors-docs.yml
File metadata and controls
99 lines (87 loc) · 3.78 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
name: Update CoFHE Errors Docs
on:
workflow_dispatch: # Manual trigger for testing
# Uncomment after testing:
# workflow_run:
# workflows: ["Publish CoFHE Errors to NPM"]
# types: [completed]
jobs:
update-docs:
runs-on: ubuntu-latest
steps:
# Fetch npm package since Mintlify agent may not have npm access
- name: Fetch errors from npm
id: fetch
run: |
npm pack @fhenixprotocol/cofhe-errors
tar -xzf fhenixprotocol-cofhe-errors-*.tgz
# Find errors file
ERRORS_FILE=$(find package -name "*.json" -type f | head -1)
# Store as base64 for safe transfer
echo "errors=$(cat $ERRORS_FILE | base64 -w 0)" >> $GITHUB_OUTPUT
echo "version=$(npm view @fhenixprotocol/cofhe-errors version)" >> $GITHUB_OUTPUT
- uses: actions/github-script@v7
env:
MINTLIFY_API_KEY: ${{ secrets.MINTLIFY_API_KEY }}
PROJECT_ID: ${{ secrets.MINTLIFY_PROJECT_ID }}
ERRORS_B64: ${{ steps.fetch.outputs.errors }}
VERSION: ${{ steps.fetch.outputs.version }}
with:
script: |
const projectId = process.env.PROJECT_ID;
const apiKey = process.env.MINTLIFY_API_KEY;
const errorsJson = Buffer.from(process.env.ERRORS_B64, 'base64').toString('utf8');
const version = process.env.VERSION;
if (!projectId || !apiKey) {
core.setFailed('Missing MINTLIFY_PROJECT_ID or MINTLIFY_API_KEY secrets');
return;
}
const url = `https://api.mintlify.com/v1/agent/${projectId}/job`;
const payload = {
branch: `mintlify/cofhe-errors-v${version}-${Date.now()}`,
messages: [
{
role: 'system',
content: 'You are an action runner that updates documentation. You should never ask questions. If you encounter an error, report it and exit.'
},
{
role: 'user',
content: `Update the CoFHE errors documentation page with these error definitions from @fhenixprotocol/cofhe-errors v${version}:\n\n\`\`\`json\n${errorsJson}\n\`\`\`\n\nCreate/update a reference page with a table: Error Name, Selector, Signature, Source Contract, Parameters. Group by source contract.`
}
],
asDraft: false
};
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
if (!response.ok) {
throw new Error(`API request failed with status ${response.status}: ${await response.text()}`);
}
const reader = response.body.getReader();
const decoder = new TextDecoder();
let buffer = '';
while (true) {
const { done, value } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
const lines = buffer.split('\n');
buffer = lines.pop() || '';
for (const line of lines) {
if (line.trim()) {
console.log(line);
}
}
}
if (buffer.trim()) {
console.log(buffer);
}
core.notice(`Documentation update job triggered for CoFHE errors v${version}`);
} catch (error) {
core.setFailed(`Failed to create documentation update job: ${error.message}`);
}