Skip to content

Commit ee37670

Browse files
committed
CI: run workflow on docs changes only
1 parent ff2d057 commit ee37670

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

.github/workflows/docs.yml

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,75 @@ on:
33
push:
44
branches:
55
- main
6+
paths:
7+
- "docs/**"
8+
- "mkdocs.yml"
9+
- ".github/workflows/docs.yml"
10+
- "**/*.py" # Watch all Python files
611
pull_request:
712
branches:
813
- main
14+
paths:
15+
- "docs/**"
16+
- "mkdocs.yml"
17+
- ".github/workflows/docs.yml"
18+
- "**/*.py" # Watch all Python files
19+
920
permissions:
1021
contents: write
22+
1123
jobs:
1224
Docs:
1325
runs-on: ubuntu-latest
1426
steps:
1527
- uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0 # Fetch all history for comparing changes
30+
31+
- name: Check for docstring changes
32+
id: check_changes
33+
run: |
34+
# Get the last two commits
35+
CHANGED_FILES=$(git diff --name-only HEAD^ HEAD)
36+
37+
# Check if docs files changed directly
38+
if echo "$CHANGED_FILES" | grep -q -E "^docs/|mkdocs.yml"; then
39+
echo "Direct documentation changes found"
40+
echo "should_deploy=true" >> $GITHUB_OUTPUT
41+
exit 0
42+
fi
43+
44+
# Check Python files for docstring changes
45+
for file in $(echo "$CHANGED_FILES" | grep '\.py$'); do
46+
if [ -f "$file" ]; then
47+
if git diff HEAD^ HEAD "$file" | grep -q '^[+-][\t ]*['"'"'\"]\{3\}'; then
48+
echo "Docstring changes found in $file"
49+
echo "should_deploy=true" >> $GITHUB_OUTPUT
50+
exit 0
51+
fi
52+
fi
53+
done
54+
55+
echo "No relevant changes found"
56+
echo "should_deploy=false" >> $GITHUB_OUTPUT
57+
1658
- uses: actions/setup-python@v5
59+
if: steps.check_changes.outputs.should_deploy == 'true'
1760
with:
1861
python-version: 3.x
62+
1963
- uses: actions/cache@v4
64+
if: steps.check_changes.outputs.should_deploy == 'true'
2065
with:
2166
key: ${{github.ref}}
2267
path: .cache
68+
2369
- name: Install dependencies
70+
if: steps.check_changes.outputs.should_deploy == 'true'
2471
run: |
2572
python -m pip install --upgrade pip
2673
pip install mkdocs-material mkdocstrings-python mkdocs-include-markdown-plugin
27-
- run: mkdocs gh-deploy --force
74+
75+
- name: Deploy docs
76+
if: steps.check_changes.outputs.should_deploy == 'true'
77+
run: mkdocs gh-deploy --force

0 commit comments

Comments
 (0)