-
Notifications
You must be signed in to change notification settings - Fork 0
287 lines (277 loc) · 11.5 KB
/
docs.yml
File metadata and controls
287 lines (277 loc) · 11.5 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
---
name: Docs
on:
push:
branches: [main, 'v[0-9]+.[0-9]+.[0-9]+*']
paths:
- docs/**
- src/**
- pyproject.toml
- uv.lock
- .github/workflows/docs.yml
- scripts/docs.py
- zensical.toml
- CHANGELOG.md
pull_request:
branches: [main, 'v[0-9]+.[0-9]+.[0-9]+*']
paths:
- docs/**
- src/**
- pyproject.toml
- uv.lock
- .github/workflows/docs.yml
- scripts/docs.py
- zensical.toml
- CHANGELOG.md
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
# renovate: datasource=python-version depName=python
PYTHON_VERSION: 3.13.11
ARTIFACT_RETENTION_DAYS: 7
jobs:
changes:
name: File Detection
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
docs: ${{ steps.docs_changes.outputs.any_changed }}
code: ${{ steps.code_changes.outputs.any_changed }}
any: ${{ steps.docs_changes.outputs.any_changed == 'true' || steps.code_changes.outputs.any_changed == 'true' }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
- name: Check Docs
uses: tj-actions/changed-files@24d32ffd492484c1d75e0c0b894501ddb9d30d62 # v47
id: docs_changes
with:
files: |
docs/**
zensical.toml
scripts/docs.py
.github/workflows/docs.yml
CHANGELOG.md
- name: Check Code
uses: tj-actions/changed-files@24d32ffd492484c1d75e0c0b894501ddb9d30d62 # v47
id: code_changes
with:
files: |
src/**
pyproject.toml
uv.lock
build:
name: Build
runs-on: ubuntu-latest
needs: [changes]
if: needs.changes.outputs.any || github.event_name == 'workflow_dispatch'
permissions:
contents: read
pull-requests: write
outputs:
any: ${{ needs.changes.outputs.any }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
sparse-checkout: |
docs
src
scripts
.github/actions
.github/workflows
.github/scripts
zensical.toml
pyproject.toml
uv.lock
- name: Setup Python
uses: ./.github/actions/setup-python
with:
python-version: ${{ env.PYTHON_VERSION }}
enable-cache: true
- name: Install Dependencies
run: |
echo "Installing documentation dependencies..."
uv sync
- name: Build Zensical Documentation
run: |
echo "Building Zensical documentation..."
uv run zensical build
echo "Documentation build completed successfully"
- name: Upload Documentation Artifact
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
with:
name: docs
path: site
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }}
if-no-files-found: warn
# Optimize cache for CI: Remove pre-built wheels, keep source-built wheels
# This improves cache efficiency by only keeping wheels that take time to build
# Docs: https://docs.astral.sh/uv/concepts/cache/#caching-in-continuous-integration
- name: Prune uv cache for CI
if: always()
run: uv cache prune --ci
deploy:
name: Deploy
runs-on: ubuntu-latest
needs: [build]
if: (github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref,
'refs/heads/v'))) || github.event_name == 'pull_request' || github.event_name
== 'workflow_dispatch'
permissions:
contents: read
deployments: write
pull-requests: write
issues: write
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Download Documentation Artifact
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7
with:
name: docs
path: site
# Deploy to Cloudflare (requires Cloudflare API)
# Note: These steps require Cloudflare API access and won't work with act (local testing)
# They will fail gracefully in act, allowing manual testing of docs build steps
- name: Ensure Wrangler v4 is available
run: npx wrangler@4 --version
- name: Deploy to Production
if: github.ref == 'refs/heads/main'
id: production_deploy
uses: mkcode/wrangler-version-deploy-action-with-metadata@35ee741c298be6c3bb124fbeef5feb85dabe3fcc # v1
continue-on-error: true
with:
api_token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
wrangler_command: npx wrangler@4
config: wrangler.toml
upload_args: --env production
deploy_args: --env production
message_template: 'Production: {{repo}}@{{short_sha}} on {{branch}} by {{actor}}
(run {{run_number}})'
- name: Upload Preview Version
if: github.ref != 'refs/heads/main' || github.event_name == 'pull_request'
id: preview_upload
run: |
# Check if Cloudflare API token is available
if [ -z "$CLOUDFLARE_API_TOKEN" ]; then
echo "⚠️ CLOUDFLARE_API_TOKEN not available - skipping preview deployment" >> "$GITHUB_STEP_SUMMARY"
echo "preview_url=🚀 Preview deployment skipped (no Cloudflare API token)" >> "$GITHUB_OUTPUT"
echo "version_id=skipped" >> "$GITHUB_OUTPUT"
exit 0
fi
# Debug: Check if site directory exists
{
echo "Checking site directory..."
if [ -d "site" ]; then
find site -maxdepth 1 -type f -o -type d | head -20
else
echo "Site directory not found at site"
fi
} >> "$GITHUB_STEP_SUMMARY"
# Run wrangler upload directly to capture the preview URL
UPLOAD_OUTPUT=$(npx wrangler@4 versions upload --config wrangler.toml --env preview --message="Preview: tux@${{ github.sha }}" 2>&1)
UPLOAD_EXIT_CODE=$?
# Echo the output for debugging and set outputs
{
echo "Upload output:"
echo "$UPLOAD_OUTPUT"
echo "Exit code: $UPLOAD_EXIT_CODE"
# If upload failed, log error
if [ $UPLOAD_EXIT_CODE -ne 0 ]; then
echo "❌ Wrangler upload failed with exit code $UPLOAD_EXIT_CODE"
fi
} >> "$GITHUB_STEP_SUMMARY"
# If upload failed, exit with error
if [ $UPLOAD_EXIT_CODE -ne 0 ]; then
echo "$UPLOAD_OUTPUT" >&2
exit $UPLOAD_EXIT_CODE
fi
# Extract version ID
VERSION_ID=$(echo "$UPLOAD_OUTPUT" | grep "Worker Version ID:" | sed 's/.*Worker Version ID: //' | tr -d '\n')
# Extract preview URL from upload output
PREVIEW_URL=$(echo "$UPLOAD_OUTPUT" | grep "Version Preview URL:" | sed 's/.*Version Preview URL: //' | tr -d '\n')
# Set outputs and log results
{
if [ -n "$VERSION_ID" ]; then
echo "version_id=$VERSION_ID" >> "$GITHUB_OUTPUT"
echo "✅ Found version ID: $VERSION_ID"
else
echo "❌ No version ID found in upload output"
fi
if [ -n "$PREVIEW_URL" ]; then
echo "preview_url=$PREVIEW_URL" >> "$GITHUB_OUTPUT"
echo "✅ Found preview URL: $PREVIEW_URL"
else
echo "⚠️ No preview URL found in upload output"
fi
} >> "$GITHUB_STEP_SUMMARY"
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
- name: Deploy Preview Version
if: github.ref != 'refs/heads/main' || github.event_name == 'pull_request'
id: preview_deploy
run: |
# Skip deployment if upload was skipped due to missing token
if [ "${{ steps.preview_upload.outputs.version_id }}" = "skipped" ]; then
echo "⚠️ Skipping preview deployment - no Cloudflare API token available" >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
# Deploy the uploaded version
npx wrangler@4 versions deploy "${{ steps.preview_upload.outputs.version_id }}" -y --config wrangler.toml --env preview --message="Preview: tux@${{ github.sha }} on ${{ github.ref_name }} by ${{ github.actor }} (run ${{ github.run_number }})"
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
- name: Find Pull Request
if: github.event_name == 'push'
uses: juliangruber/find-pull-request-action@48b6133aa6c826f267ebd33aa2d29470f9d9e7d0 # v1
id: find_pr
with:
branch: ${{ github.ref_name }}
state: open
- name: Find Documentation Comment
if: github.event_name == 'pull_request' || steps.find_pr.outputs.number !=
''
uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad # v4
id: find_comment
with:
issue-number: ${{ github.event.pull_request.number || steps.find_pr.outputs.number }}
comment-author: github-actions[bot]
body-includes: '## 📚 Documentation Preview'
- name: Prepare Preview URL
if: github.event_name == 'pull_request' || steps.find_pr.outputs.number !=
''
id: prepare_url
run: |
if [ "${{ steps.preview_upload.outputs.version_id }}" = "skipped" ]; then
echo "preview_url=🚀 Preview deployment skipped (no Cloudflare API token)" >> "$GITHUB_OUTPUT"
echo "is_url=false" >> "$GITHUB_OUTPUT"
echo "⚠️ Preview deployment skipped due to missing Cloudflare API token" >> "$GITHUB_STEP_SUMMARY"
elif [ -n "${{ steps.preview_upload.outputs.preview_url }}" ]; then
echo "preview_url=${{ steps.preview_upload.outputs.preview_url }}" >> "$GITHUB_OUTPUT"
echo "is_url=true" >> "$GITHUB_OUTPUT"
echo "✅ Using preview URL from wrangler upload output" >> "$GITHUB_STEP_SUMMARY"
else
echo "preview_url=🚀 Preview deployed successfully" >> "$GITHUB_OUTPUT"
echo "is_url=false" >> "$GITHUB_OUTPUT"
echo "Preview deployment completed successfully" >> "$GITHUB_STEP_SUMMARY"
fi
- name: Create or Update Comment
if: github.event_name == 'pull_request' || steps.find_pr.outputs.number !=
''
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
continue-on-error: true
with:
comment-id: ${{ steps.find_comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number || steps.find_pr.outputs.number }}
edit-mode: replace
body: |-
## 📚 Documentation Preview
| Type | URL | Version | Message |
|------|-----|---------|---------|
| Production | [https://tux.atl.dev](https://tux.atl.dev) | - | - |
| Preview | ${{ steps.prepare_url.outputs.is_url == 'true' && format('[{0}]({0})', steps.prepare_url.outputs.preview_url) || steps.prepare_url.outputs.preview_url }} | ${{ steps.preview_upload.outputs.version_id || '-' }} | Preview: tux@${{ github.sha }} on ${{ github.ref_name }} by ${{ github.actor }} (run ${{ github.run_number }}) |