|
| 1 | +name: Documentation |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + branches: [ main ] |
| 9 | + paths: |
| 10 | + - 'src/**/*.py' |
| 11 | + - 'docs/**' |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + pages: write |
| 17 | + id-token: write |
| 18 | + pull-requests: write |
| 19 | + |
| 20 | +# Allow only one concurrent deployment |
| 21 | +concurrency: |
| 22 | + group: "pages" |
| 23 | + cancel-in-progress: true |
| 24 | + |
| 25 | +jobs: |
| 26 | + check-docs: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + if: github.event_name == 'pull_request' |
| 29 | + # Make this job informational only - don't block PR |
| 30 | + continue-on-error: true |
| 31 | + steps: |
| 32 | + - name: Checkout repository |
| 33 | + uses: actions/checkout@v4 |
| 34 | + |
| 35 | + - name: Set up Python |
| 36 | + uses: actions/setup-python@v5 |
| 37 | + with: |
| 38 | + python-version: '3.11' |
| 39 | + cache: 'pip' |
| 40 | + |
| 41 | + - name: Install Poetry |
| 42 | + run: | |
| 43 | + curl -sSL https://install.python-poetry.org | python3 - |
| 44 | + echo "$HOME/.local/bin" >> $GITHUB_PATH |
| 45 | +
|
| 46 | + - name: Install dependencies |
| 47 | + run: | |
| 48 | + poetry install --with docs |
| 49 | +
|
| 50 | + - name: Check documentation sync |
| 51 | + run: | |
| 52 | + cd ${{ github.workspace }} |
| 53 | + # Generate the documentation |
| 54 | + poetry run python docs/generate_docs.py |
| 55 | +
|
| 56 | + # Check if any files were modified (docs are out of sync) |
| 57 | + if [ -n "$(git status --porcelain docs/source/)" ]; then |
| 58 | + echo "::warning::Documentation is out of sync with the codebase!" |
| 59 | + echo "::warning::Please run 'python docs/generate_docs.py' and commit the updated documentation files." |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | + echo "Documentation is in sync with the codebase." |
| 63 | +
|
| 64 | + - name: Notify about out-of-sync docs |
| 65 | + if: failure() |
| 66 | + uses: actions/github-script@v6 |
| 67 | + with: |
| 68 | + script: | |
| 69 | + github.rest.issues.createComment({ |
| 70 | + issue_number: context.issue.number, |
| 71 | + owner: context.repo.owner, |
| 72 | + repo: context.repo.repo, |
| 73 | + body: '⚠️ **Documentation is out of sync with the code!**\n\nPlease run `python docs/generate_docs.py` and commit the updated documentation files.' |
| 74 | + }) |
| 75 | +
|
| 76 | + build: |
| 77 | + runs-on: ubuntu-latest |
| 78 | + if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request' |
| 79 | + needs: [check-docs] |
| 80 | + # Make this job informational only for PRs - don't block PR |
| 81 | + continue-on-error: ${{ github.event_name == 'pull_request' }} |
| 82 | + steps: |
| 83 | + - name: Checkout repository |
| 84 | + uses: actions/checkout@v4 |
| 85 | + |
| 86 | + - name: Set up Python |
| 87 | + uses: actions/setup-python@v5 |
| 88 | + with: |
| 89 | + python-version: '3.11' |
| 90 | + cache: 'pip' |
| 91 | + |
| 92 | + - name: Install Poetry |
| 93 | + run: | |
| 94 | + curl -sSL https://install.python-poetry.org | python3 - |
| 95 | + echo "$HOME/.local/bin" >> $GITHUB_PATH |
| 96 | +
|
| 97 | + - name: Install dependencies |
| 98 | + run: | |
| 99 | + poetry install --with docs |
| 100 | +
|
| 101 | + - name: Generate RST files |
| 102 | + run: | |
| 103 | + cd ${{ github.workspace }} |
| 104 | + poetry run python docs/generate_docs.py |
| 105 | +
|
| 106 | + - name: Build documentation |
| 107 | + run: | |
| 108 | + cd ${{ github.workspace }}/docs |
| 109 | + poetry run sphinx-build -b html source build/html |
| 110 | +
|
| 111 | + - name: Setup Pages |
| 112 | + uses: actions/configure-pages@v4 |
| 113 | + |
| 114 | + - name: Upload artifact |
| 115 | + uses: actions/upload-pages-artifact@v3 |
| 116 | + with: |
| 117 | + path: ${{ github.workspace }}/docs/build/html |
| 118 | + |
| 119 | + deploy: |
| 120 | + # Only deploy on push to main or workflow_dispatch, skip on PRs |
| 121 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' |
| 122 | + needs: build |
| 123 | + environment: |
| 124 | + name: github-pages |
| 125 | + url: ${{ steps.deployment.outputs.page_url }} |
| 126 | + runs-on: ubuntu-latest |
| 127 | + steps: |
| 128 | + - name: Deploy to GitHub Pages |
| 129 | + id: deployment |
| 130 | + uses: actions/deploy-pages@v4 |
0 commit comments