-
Notifications
You must be signed in to change notification settings - Fork 539
131 lines (124 loc) · 4.6 KB
/
docs.yml
File metadata and controls
131 lines (124 loc) · 4.6 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
name: Docs
on:
push:
branches:
- master
- main
- benchmark
pull_request:
merge_group:
permissions:
contents: write
pull-requests: write
jobs:
check-diff:
name: Check diff
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
defaults:
run:
shell: bash -euo pipefail {0}
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build docs from PR branch
run: |
uv sync --group dev --no-install-project
uv run mkdocs build
cp -r site site-pr
- name: Build docs from base branch
run: |
git fetch origin ${{ github.base_ref }}
git checkout origin/${{ github.base_ref }}
uv sync --group dev --no-install-project
uv run mkdocs build
cp -r site site-base
- name: Compare docs and comment if different
run: |
if ! diff -rq site-pr site-base > /dev/null 2>&1; then
echo "DOCS_CHANGED=true" >> $GITHUB_ENV
echo "## Documentation Changes Detected" > comment.md
echo "" >> comment.md
# Get list of changed files, excluding verbose files
# diff returns exit code 1 when differences exist; || true prevents pipefail from failing the script
changed_files=$(diff -rq site-pr site-base | grep "^Files" | grep "differ$" | grep -v "search_index.json" | head -5 || true)
if [ -n "$changed_files" ]; then
file_count=0
echo "$changed_files" | while IFS= read -r line; do
file_count=$((file_count + 1))
# Extract file paths from "Files site-pr/path and site-base/path differ"
file1=$(echo "$line" | awk '{print $2}')
file2=$(echo "$line" | awk '{print $4}')
filename=$(echo "$file1" | sed 's|site-pr/||')
echo "<details>" >> comment.md
echo "<summary>📄 <code>$filename</code></summary>" >> comment.md
echo "" >> comment.md
echo "\`\`\`diff" >> comment.md
diff -u "$file2" "$file1" | head -10 >> comment.md || true
echo "\`\`\`" >> comment.md
echo "</details>" >> comment.md
echo "" >> comment.md
# Check comment size and break if too large
if [ $(wc -c < comment.md) -gt 60000 ]; then
echo "" >> comment.md
echo "_Comment truncated due to size limits. Review remaining changes locally._" >> comment.md
break
fi
done
fi
echo "" >> comment.md
echo "_Showing first 10 lines of diff for each changed file (up to 5 files, excluding search indices)._" >> comment.md
else
echo "DOCS_CHANGED=false" >> $GITHUB_ENV
fi
- name: Post comment
if: env.DOCS_CHANGED == 'true'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
let comment = fs.readFileSync('comment.md', 'utf8');
// GitHub comment size limit is 65536 characters
const MAX_SIZE = 65000;
if (comment.length > MAX_SIZE) {
comment = comment.substring(0, MAX_SIZE) + '\n\n_[Comment truncated due to size limits]_';
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
deploy:
name: Deploy
if: github.event_name == 'push' || github.event_name == 'merge_group'
runs-on: ubuntu-latest
defaults:
run:
shell: bash -euo pipefail {0}
steps:
- uses: actions/checkout@v4
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- uses: actions/setup-python@v5
with:
python-version: 3.x
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- uses: actions/cache@v4
with:
key: mkdocs-material-${{ env.cache_id }}
path: .cache
restore-keys: |
mkdocs-material-
- run: uv sync --group dev --no-install-project
- run: uv run mkdocs gh-deploy --force