Skip to content

Commit 461c457

Browse files
Add workflow to create and save versioned references (#332)
* Updates script to persist references * Workflow to generate references to a folder * Get rid of references, to be generated * Update .github/workflows/generate-references.yaml Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Update .github/workflows/generate-references.yaml Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Review comments * Update .github/workflows/generate-references.yaml * Pin hashes and only run on releases * Pin uv --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1 parent a221bff commit 461c457

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: "Generate References"
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
jobs:
9+
docs-generation:
10+
name: Generate references
11+
permissions:
12+
contents: write
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout the repository
16+
uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
17+
with:
18+
fetch-depth: 0
19+
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55
23+
with:
24+
python-version: 3.11.11
25+
26+
- name: Install uv
27+
uses: astral-sh/setup-uv@0c5e2b8115b80b4c7c5ddf6ffdd634974642d182 # v5.4.1
28+
with:
29+
enable-cache: true
30+
pyproject-file: 'pyproject.toml'
31+
32+
- name: Generate references
33+
run: |
34+
uv run bin/docs generate-references
35+
36+
- name: Check for changes in references
37+
id: changes
38+
run: |
39+
if [ -n "$(git status --porcelain references/)" ]; then
40+
echo "changed=true" >> $GITHUB_OUTPUT
41+
echo "New references generated in references directory:"
42+
git status --porcelain references/
43+
else
44+
echo "changed=false" >> $GITHUB_OUTPUT
45+
echo "No new references generated in references directory"
46+
fi
47+
48+
- uses: stefanzweifel/git-auto-commit-action@b3e3f72439fc3af08948f989a19a825463598a
49+
if: steps.changes.outputs.changed == 'true'
50+
with:
51+
commit_message: "Update generated references"
52+
file_pattern: references/

bin/docs_scripts/doc_constant.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
from typing import Dict, Union
6+
from posthog.version import VERSION
67

78
# Documentation generation metadata
89
DOCUMENTATION_METADATA = {
@@ -27,8 +28,9 @@
2728

2829
# Output file configuration
2930
OUTPUT_CONFIG: Dict[str, Union[str, int]] = {
30-
"output_dir": ".",
31-
"filename": "posthog-python-references.json",
31+
"output_dir": "./references",
32+
"filename": f"posthog-python-references-{VERSION}.json",
33+
"filename_latest": "posthog-python-references-latest.json",
3234
"indent": 2,
3335
}
3436

bin/docs_scripts/generate_json_schemas.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,19 @@ def generate_sdk_documentation():
460460
try:
461461
documentation = generate_sdk_documentation()
462462

463-
# Write to file
464463
output_file = os.path.join(
465464
str(OUTPUT_CONFIG["output_dir"]), str(OUTPUT_CONFIG["filename"])
466465
)
466+
output_file_latest = os.path.join(
467+
str(OUTPUT_CONFIG["output_dir"]), str(OUTPUT_CONFIG["filename_latest"])
468+
)
469+
470+
# Write to current version
467471
with open(output_file, "w") as f:
468472
json.dump(documentation, f, indent=int(OUTPUT_CONFIG["indent"]))
473+
# Write to latest
474+
with open(output_file_latest, "w") as f:
475+
json.dump(documentation, f, indent=int(OUTPUT_CONFIG["indent"]))
469476

470477
print(f"✓ Generated {output_file}")
471478

0 commit comments

Comments
 (0)