-
-
Notifications
You must be signed in to change notification settings - Fork 435
148 lines (142 loc) · 5.66 KB
/
generated-docs-sync.yaml
File metadata and controls
148 lines (142 loc) · 5.66 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
144
145
146
147
148
name: Sync Generated Docs
on:
push:
branches: [main]
paths:
- 'src/datamodel_code_generator/**'
- 'tests/main/**'
- 'tests/test_main_kr.py'
- 'scripts/build_cli_docs.py'
- 'scripts/build_prompt_data.py'
- 'scripts/build_schema_docs.py'
- 'scripts/build_llms_txt.py'
- 'scripts/update_docs_version.py'
- 'docs/**/*.md'
- 'CHANGELOG.md'
- 'README.md'
- 'zensical.toml'
permissions:
contents: read
concurrency:
group: generated-docs-main
cancel-in-progress: false
jobs:
generate:
runs-on: ubuntu-latest
outputs:
has_changes: ${{ steps.patch.outputs.has_changes }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ github.sha }}
persist-credentials: false
- name: Install the latest version of uv
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
- name: Install tox
run: uv tool install --python-preference only-managed --python 3.13 tox --with tox-uv
- name: Setup README environment
run: tox run -vv --notest --skip-missing-interpreters false -e readme
env:
UV_PYTHON_PREFERENCE: "only-managed"
- name: Setup CLI docs environment
run: tox run -vv --notest --skip-missing-interpreters false -e cli-docs
env:
UV_PYTHON_PREFERENCE: "only-managed"
- name: Setup schema docs environment
run: tox run -vv --notest --skip-missing-interpreters false -e schema-docs
env:
UV_PYTHON_PREFERENCE: "only-managed"
- name: Setup llms.txt environment
run: tox run -vv --notest --skip-missing-interpreters false -e llms-txt
env:
UV_PYTHON_PREFERENCE: "only-managed"
- name: Update README
run: .tox/readme/bin/python scripts/update_command_help_on_markdown.py
- name: Collect CLI doc metadata
run: .tox/cli-docs/bin/pytest --collect-cli-docs -p no:xdist -q
- name: Build CLI docs
run: .tox/cli-docs/bin/python scripts/build_cli_docs.py
- name: Build prompt data
run: .tox/cli-docs/bin/python scripts/build_prompt_data.py
- name: Build schema docs
run: .tox/schema-docs/bin/python scripts/build_schema_docs.py
- name: Build llms.txt
run: .tox/llms-txt/bin/python scripts/build_llms_txt.py
- name: Create generated docs patch
id: patch
env:
PATCH_PATH: ${{ runner.temp }}/generated-docs.patch
run: |
set -euo pipefail
if git diff --quiet -- README.md docs/index.md docs/cli-reference/ docs/llms.txt docs/llms-full.txt docs/supported_formats.md src/datamodel_code_generator/prompt_data.py; then
echo "has_changes=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git diff --binary -- README.md docs/index.md docs/cli-reference/ docs/llms.txt docs/llms-full.txt docs/supported_formats.md src/datamodel_code_generator/prompt_data.py > "$PATCH_PATH"
echo "has_changes=true" >> "$GITHUB_OUTPUT"
- name: Upload generated docs patch
if: steps.patch.outputs.has_changes == 'true'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: generated-docs-patch
path: ${{ runner.temp }}/generated-docs.patch
if-no-files-found: error
push:
needs: generate
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
final_sha: ${{ steps.record_sha.outputs.final_sha }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
ref: ${{ github.sha }}
persist-credentials: false
- name: Download generated docs patch
if: needs.generate.outputs.has_changes == 'true'
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: generated-docs-patch
path: ${{ runner.temp }}
# Use GITHUB_TOKEN intentionally so this sync commit does not fan out into
# another push-triggered workflow run. Docs deployment is chained below.
- name: Commit generated docs
if: needs.generate.outputs.has_changes == 'true'
env:
GH_TOKEN: ${{ github.token }}
TARGET_REPO: ${{ github.repository }}
TARGET_REF: ${{ github.ref_name }}
PATCH_PATH: ${{ runner.temp }}/generated-docs.patch
run: |
set -euo pipefail
git apply --index --whitespace=nowarn "$PATCH_PATH"
if git diff --staged --quiet; then
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git commit -m "docs: sync generated docs"
git fetch origin "${TARGET_REF}"
git rebase "origin/${TARGET_REF}"
git push "https://x-access-token:${GH_TOKEN}@github.com/${TARGET_REPO}.git" "HEAD:${TARGET_REF}"
- name: Record final revision
id: record_sha
env:
DEFAULT_SHA: ${{ github.sha }}
run: |
if [ "${{ needs.generate.outputs.has_changes }}" = "true" ]; then
echo "final_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
else
echo "final_sha=${DEFAULT_SHA}" >> "$GITHUB_OUTPUT"
fi
deploy-docs:
needs: push
uses: ./.github/workflows/docs-deploy.yaml
with:
checkout_ref: ${{ needs.push.outputs.final_sha }}
deploy_branch: dev
secrets:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}