-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (130 loc) · 4.44 KB
/
docs.yml
File metadata and controls
153 lines (130 loc) · 4.44 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
name: Docs
on:
release:
types:
- published
push:
branches:
- main
paths:
- "docs/**"
- "mkdocs.yml"
- "hooks/**"
- "src/**"
- "demo/**"
- "package.json"
- "package-lock.json"
- ".github/workflows/docs.yml"
# Only one docs deployment runs at a time; additional runs queue up
concurrency:
group: docs-deployment
cancel-in-progress: false
jobs:
docs:
name: Docs
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- name: Install JS dependencies
run: npm ci
- name: Build package
run: npm run build
- name: Copy dist into docs assets
run: |
mkdir -p docs/assets/dist
cp -R dist/* docs/assets/dist/
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install docs dependencies
run: pip install -r docs/requirements.txt
- name: Setup Git user
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Deploy docs (release)
if: ${{ github.event_name == 'release' && github.event.action == 'published' }}
run: |
# Fetch the latest gh-pages state to reduce conflicts
git fetch origin gh-pages --depth=1 || true
# Build and commit docs locally
mike deploy --update-aliases --allow-empty "${{ github.event.release.tag_name }}" latest
mike set-default latest
# Push with retry logic to handle race conditions
for i in {1..3}; do
if git push origin gh-pages; then
echo "Successfully pushed documentation for ${{ github.event.release.tag_name }}"
break
else
echo "Push failed (attempt $i/3)"
if [ $i -eq 3 ]; then
echo "Failed to push documentation after 3 attempts"
exit 1
fi
echo "Fetching latest gh-pages and rebasing..."
git fetch origin gh-pages
git rebase origin/gh-pages
sleep 2
fi
done
- name: Deploy docs (dev)
if: ${{ github.event_name == 'push' }}
run: |
# Fetch the latest gh-pages state to reduce conflicts
git fetch origin gh-pages --depth=1 || true
# Build and commit docs locally
mike deploy --update-aliases --allow-empty dev
# Set dev as default only if no 'latest' alias exists yet
if ! mike list 2>/dev/null | grep -q 'latest'; then
mike set-default dev
fi
# Push with retry logic
for i in {1..3}; do
if git push origin gh-pages; then
echo "Successfully pushed dev documentation"
break
else
echo "Push failed (attempt $i/3)"
if [ $i -eq 3 ]; then
echo "Failed to push documentation after 3 attempts"
exit 1
fi
echo "Fetching latest gh-pages and rebasing..."
git fetch origin gh-pages
git rebase origin/gh-pages
sleep 2
fi
done
- name: Reorder versions.json on gh-pages
if: ${{ github.event_name == 'release' || github.event_name == 'push' }}
run: |
# Copy the reordering script to temp location before switching branches
cp scripts/reorder_versions.py /tmp/reorder_versions.py
# Fetch and checkout gh-pages branch
git fetch origin gh-pages
git checkout gh-pages
# Run the reordering script
python /tmp/reorder_versions.py versions.json
# Commit and push if there are changes
if git diff --quiet; then
echo "No changes to versions.json"
else
git add versions.json
git commit -m "Reorder versions.json for proper version dropdown sorting"
git push origin gh-pages
fi
# Switch back to the original branch
git checkout -
# Clean up temp file
rm /tmp/reorder_versions.py