|
3 | 3 | push:
|
4 | 4 | branches:
|
5 | 5 | - main
|
| 6 | + paths: |
| 7 | + - "docs/**" |
| 8 | + - "mkdocs.yml" |
| 9 | + - ".github/workflows/docs.yml" |
| 10 | + - "**/*.py" # Watch all Python files |
6 | 11 | pull_request:
|
7 | 12 | branches:
|
8 | 13 | - main
|
| 14 | + paths: |
| 15 | + - "docs/**" |
| 16 | + - "mkdocs.yml" |
| 17 | + - ".github/workflows/docs.yml" |
| 18 | + - "**/*.py" # Watch all Python files |
| 19 | + |
9 | 20 | permissions:
|
10 | 21 | contents: write
|
| 22 | + |
11 | 23 | jobs:
|
12 | 24 | Docs:
|
13 | 25 | runs-on: ubuntu-latest
|
14 | 26 | steps:
|
15 | 27 | - 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 | +
|
16 | 58 | - uses: actions/setup-python@v5
|
| 59 | + if: steps.check_changes.outputs.should_deploy == 'true' |
17 | 60 | with:
|
18 | 61 | python-version: 3.x
|
| 62 | + |
19 | 63 | - uses: actions/cache@v4
|
| 64 | + if: steps.check_changes.outputs.should_deploy == 'true' |
20 | 65 | with:
|
21 | 66 | key: ${{github.ref}}
|
22 | 67 | path: .cache
|
| 68 | + |
23 | 69 | - name: Install dependencies
|
| 70 | + if: steps.check_changes.outputs.should_deploy == 'true' |
24 | 71 | run: |
|
25 | 72 | python -m pip install --upgrade pip
|
26 | 73 | 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