|
| 1 | +name: Documentation Build |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + branches: |
| 7 | + - main |
| 8 | + paths: |
| 9 | + - '.github/workflows/docs-build-and-publish.yml' |
| 10 | + - 'docs/**' |
| 11 | + push: |
| 12 | + branches: |
| 13 | + - main |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + concurrency: |
| 19 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 20 | + cancel-in-progress: true |
| 21 | + steps: |
| 22 | + - name: Checkout code |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Install dependencies |
| 26 | + run: | |
| 27 | + sudo apt-get update |
| 28 | + sudo apt-get install -y python3 python3-pip |
| 29 | +
|
| 30 | + - name: Install Python dependencies |
| 31 | + working-directory: docs |
| 32 | + run: | |
| 33 | + python3 -m pip install -r requirements.txt |
| 34 | +
|
| 35 | + - name: Build documentation |
| 36 | + working-directory: docs |
| 37 | + run: | |
| 38 | + sphinx-build -M html . build |
| 39 | +
|
| 40 | + - name: Upload artifact |
| 41 | + uses: actions/upload-artifact@v4 |
| 42 | + with: |
| 43 | + name: doc-build |
| 44 | + if-no-files-found: error |
| 45 | + retention-days: 2 |
| 46 | + path: | |
| 47 | + docs/build/html/ |
| 48 | +
|
| 49 | + - name: Update gh-pages |
| 50 | + if: ${{ github.event_name == 'push' }} |
| 51 | + env: |
| 52 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + run: | |
| 54 | + git config --global --add safe.directory "$(pwd)" |
| 55 | + git config --global user.name "GitHub Actions" |
| 56 | + git config --global user.email "[email protected]" |
| 57 | +
|
| 58 | + git pull origin gh-pages |
| 59 | +
|
| 60 | + # Update docs |
| 61 | + rm -rf docs/html |
| 62 | + mkdir docs/html |
| 63 | + cp docs/build/html docs/html |
| 64 | + rm -rf docs/build |
| 65 | +
|
| 66 | + # Create commit with doc updates |
| 67 | + git add docs/html |
| 68 | + git commit -m "Updating documentation based on ${{ github.sha }}" |
| 69 | +
|
| 70 | + # Push changes |
| 71 | + git push origin gh-pages:gh-pages |
0 commit comments