-
Notifications
You must be signed in to change notification settings - Fork 6
81 lines (71 loc) · 2.86 KB
/
Copy pathsqlite_documentation_gen.yml
File metadata and controls
81 lines (71 loc) · 2.86 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
name: SQLite docs auto-generate
on:
push:
paths:
- 'src/tasks.py'
workflow_dispatch:
jobs:
update-readme:
runs-on: ubuntu-latest
# Only regenerate docs when the commit asks for it explicitly, or when the
# workflow is triggered manually. Otherwise the job is skipped (gray, not red).
if: ${{ github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, '--rebuild-docs') }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install 'openai>=1.0,<2'
- name: Generate SQLite docs
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
python <<'PY'
from openai import OpenAI
with open('src/tasks.py', 'r') as f:
lines = f.readlines()
start_line = next(
i for i, line in enumerate(lines, start=1)
if '# auto-generated SQLite documentation starts here' in line
)
content = ''.join(lines[start_line - 1:])
client = OpenAI()
response = client.chat.completions.create(
model='gpt-4o-mini',
messages=[{
'role': 'user',
'content': (
f'{content}\n'
'Generate a documentation markdown table for each table of the '
'SQLite database (including package_data). For example:\n\n'
'**activity table**\n'
'|Column|Description\n'
'|event_name|One sentence to explain to the developers what kind '
'of data they will find here. If the code provided allows you to '
'provide an example of data format or value that is great, but do '
'not invent anything.|same for this column|etc.\n\n'
'**Table 2**\n'
'|Column|Description|...\n\n'
'etc.'
)
}],
)
readme_content = response.choices[0].message.content.strip()
header = (
'Note: this documentation was generated automatically from the tasks.py '
'code using an AI. Although we are confident in the reliability of the '
'data displayed here, errors may occur.\n\n\n'
)
with open('docs/sqlite_database_structure.md', 'w') as f:
f.write(header + readme_content)
PY
- name: Commit and Push
uses: EndBug/add-and-commit@v9
with:
message: 'Update sqlite_database_structure.md'
add: 'docs/sqlite_database_structure.md'