|
| 1 | +name: Documentation build |
| 2 | + |
| 3 | +# cancel any previous running or pending jobs from the same branch |
| 4 | +concurrency: |
| 5 | + group: docs-build-cache-${{ github.ref }} |
| 6 | + cancel-in-progress: true |
| 7 | + |
| 8 | +on: |
| 9 | + workflow_run: |
| 10 | + workflows: ["Build env and test"] |
| 11 | + branches: |
| 12 | + - '*' |
| 13 | + types: |
| 14 | + - completed |
| 15 | + workflow_dispatch: |
| 16 | + |
| 17 | +env: |
| 18 | + CACHE_NUMBER: 0 # increase to reset cache manually |
| 19 | + |
| 20 | +jobs: |
| 21 | + |
| 22 | + build-docs: |
| 23 | + |
| 24 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 25 | + |
| 26 | + defaults: |
| 27 | + run: |
| 28 | + shell: bash -el {0} |
| 29 | + |
| 30 | + strategy: |
| 31 | + matrix: |
| 32 | + include: |
| 33 | + - os: ubuntu-latest |
| 34 | + label: linux-64 |
| 35 | + prefix: /usr/share/miniconda3/envs/my-env |
| 36 | + |
| 37 | + name: ${{ matrix.label }} |
| 38 | + runs-on: ${{ matrix.os }} |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@v5 |
| 41 | + |
| 42 | + - name: Setup Miniforge |
| 43 | + uses: conda-incubator/setup-miniconda@v3 |
| 44 | + with: |
| 45 | + miniforge-version: latest |
| 46 | + activate-environment: my-env |
| 47 | + |
| 48 | + - name: Set cache date |
| 49 | + run: echo "DATE=$(date +'%Y%m')" >> $GITHUB_ENV |
| 50 | + |
| 51 | + - name: Restore doc env cache |
| 52 | + uses: actions/cache@v4 |
| 53 | + with: |
| 54 | + path: ${{ env.CONDA }}/envs |
| 55 | + key: ${{ matrix.label }}-conda-${{ hashFiles('environment.yml') }}-${{ hashFiles('docs/requirements.txt') }}-${{ env.DATE }}-${{ env.CACHE_NUMBER }} |
| 56 | + id: cache-doc |
| 57 | + |
| 58 | + - name: Restore env cache |
| 59 | + if: steps.cache-doc.outputs.cache-hit != 'true' |
| 60 | + uses: actions/cache/restore@v4 |
| 61 | + with: |
| 62 | + path: ${{ env.CONDA }}/envs |
| 63 | + key: ${{ matrix.label }}-conda-${{ hashFiles('environment.yml') }}-${{ env.DATE }}-${{ env.CACHE_NUMBER }} |
| 64 | + fail-on-cache-miss: true |
| 65 | + id: cache |
| 66 | + |
| 67 | + - name: Install documentation requirements |
| 68 | + if: steps.cache-doc.outputs.cache-hit != 'true' |
| 69 | + run: pip install -r docs/requirements.txt |
| 70 | + |
| 71 | + - name: Build documentation src |
| 72 | + run: make build-src -C docs/ |
| 73 | + |
| 74 | + - name: Build HTML |
| 75 | + run: make html -C docs/ |
| 76 | + |
| 77 | + - name: Upload artifacts |
| 78 | + if: github.ref == 'refs/heads/master' && github.event_name == 'push' |
| 79 | + uses: actions/upload-pages-artifact@v3 |
| 80 | + with: |
| 81 | + path: docs/build/html/ |
| 82 | + |
| 83 | + deploy: |
| 84 | + if: github.ref == 'refs/heads/master' && github.event_name == 'push' |
| 85 | + needs: build-docs |
| 86 | + runs-on: ubuntu-latest |
| 87 | + |
| 88 | + environment: |
| 89 | + name: github-pages |
| 90 | + |
| 91 | + permissions: |
| 92 | + pages: write |
| 93 | + id-token: write |
| 94 | + |
| 95 | + steps: |
| 96 | + - name: Deploy |
| 97 | + uses: actions/deploy-pages@v4 |
| 98 | + with: |
| 99 | + token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments