|
1 | | -name: Documentation |
| 1 | +name: Build and Deploy Documentation |
| 2 | + |
2 | 3 | on: |
3 | 4 | push: |
4 | | - branches: |
5 | | - - main |
| 5 | + branches: [main, master] |
6 | 6 | paths: |
7 | 7 | - "docs/**" |
8 | 8 | - "src/**" |
| 9 | + - "examples/**" |
| 10 | + - "README.md" |
9 | 11 | - "pyproject.toml" |
10 | 12 | - ".github/workflows/docs.yml" |
| 13 | + pull_request: |
| 14 | + branches: [main, master] |
| 15 | + paths: |
| 16 | + - "docs/**" |
| 17 | + - "src/**" |
| 18 | + - "examples/**" |
| 19 | + - "README.md" |
| 20 | + - "pyproject.toml" |
| 21 | + - ".github/workflows/docs.yml" |
| 22 | + workflow_dispatch: |
| 23 | + inputs: |
| 24 | + reason: |
| 25 | + description: "Reason for manual documentation build" |
| 26 | + required: false |
| 27 | + default: "Manual trigger" |
11 | 28 |
|
12 | | -# Sets permissions of the GITHUB_TOKEN |
13 | 29 | permissions: |
14 | | - contents: write |
15 | | - pull-requests: write |
| 30 | + contents: read |
| 31 | + pages: write |
| 32 | + id-token: write |
| 33 | + |
| 34 | +concurrency: |
| 35 | + group: "pages" |
| 36 | + cancel-in-progress: false |
16 | 37 |
|
17 | 38 | jobs: |
18 | | - build-docs: |
| 39 | + build: |
19 | 40 | runs-on: ubuntu-latest |
20 | 41 | steps: |
21 | | - - uses: actions/checkout@v4 |
| 42 | + - name: Checkout |
| 43 | + uses: actions/checkout@v4 |
| 44 | + with: |
| 45 | + fetch-depth: 0 |
22 | 46 |
|
23 | 47 | - name: Install uv |
24 | 48 | uses: astral-sh/setup-uv@v6 |
25 | 49 | with: |
26 | 50 | enable-cache: true |
27 | 51 |
|
28 | | - - name: Install dependencies |
29 | | - run: | |
30 | | - uv sync --dev --groups docs |
| 52 | + - name: Set up Python |
| 53 | + run: uv python install |
31 | 54 |
|
32 | | - - name: Configure Git |
33 | | - run: | |
34 | | - git config user.name 'github-actions[bot]' |
35 | | - git config user.email 'github-actions[bot]@users.noreply.github.com' |
| 55 | + - name: Install dependencies |
| 56 | + run: uv sync --locked --group docs |
36 | 57 |
|
37 | 58 | - name: Build documentation |
38 | 59 | run: | |
39 | 60 | cd docs |
40 | | - make clean |
41 | | - make html |
| 61 | + uv run make clean |
| 62 | + uv run make html |
42 | 63 |
|
43 | | - - name: Prepare docs branch |
44 | | - run: | |
45 | | - # Create/switch to docs branch |
46 | | - git checkout -B docs |
| 64 | + - name: Setup Pages |
| 65 | + uses: actions/configure-pages@v4 |
| 66 | + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' |
47 | 67 |
|
48 | | - # Remove existing docs if any |
49 | | - rm -rf docs/build || true |
50 | | -
|
51 | | - # Move built docs to root docs/build directory |
52 | | - mkdir -p docs/build |
53 | | - cp -r docs/_build/html/* docs/build/ |
54 | | -
|
55 | | - # Stage changes |
56 | | - git add docs/build |
57 | | -
|
58 | | - # Only proceed if there are changes to commit |
59 | | - if git diff --staged --quiet; then |
60 | | - echo "No changes to documentation" |
61 | | - exit 0 |
62 | | - fi |
63 | | -
|
64 | | - # Commit changes |
65 | | - git commit -m "Update documentation from main branch" |
66 | | -
|
67 | | - # Push to docs branch |
68 | | - git push origin docs --force |
69 | | -
|
70 | | - - name: Create Pull Request |
71 | | - env: |
72 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
73 | | - run: | |
74 | | - # Check if PR already exists |
75 | | - PR_EXISTS=$(gh pr list --head docs --base main --json number -q length) |
76 | | -
|
77 | | - if [ "$PR_EXISTS" -eq "0" ]; then |
78 | | - # Create PR if it doesn't exist |
79 | | - gh pr create \ |
80 | | - --base main \ |
81 | | - --head docs \ |
82 | | - --title "Documentation Update" \ |
83 | | - --body "Automated documentation update from main branch. |
| 68 | + - name: Upload artifact |
| 69 | + uses: actions/upload-pages-artifact@v3 |
| 70 | + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' |
| 71 | + with: |
| 72 | + path: docs/_build/html |
84 | 73 |
|
85 | | - This PR was automatically generated by the documentation workflow when changes were detected in the docs, source code, or project configuration." \ |
86 | | - --label "documentation" |
87 | | - else |
88 | | - echo "PR from docs branch already exists. Skipping PR creation." |
89 | | - fi |
| 74 | + - name: Upload build artifacts for debugging |
| 75 | + uses: actions/upload-artifact@v4 |
| 76 | + if: failure() |
| 77 | + with: |
| 78 | + name: docs-build-artifacts |
| 79 | + path: | |
| 80 | + docs/_build/ |
| 81 | + docs/*.log |
| 82 | +
|
| 83 | + deploy: |
| 84 | + environment: |
| 85 | + name: github-pages |
| 86 | + url: ${{ steps.deployment.outputs.page_url }} |
| 87 | + runs-on: ubuntu-latest |
| 88 | + needs: build |
| 89 | + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' |
| 90 | + steps: |
| 91 | + - name: Deploy to GitHub Pages |
| 92 | + id: deployment |
| 93 | + uses: actions/deploy-pages@v4 |
0 commit comments