|
| 1 | +name: Docs |
| 2 | + |
| 3 | +# One workflow, three outcomes: |
| 4 | +# |
| 5 | +# * fortran-lang/fplotlib, push to main: build and publish the production docs |
| 6 | +# to that repository's GitHub Pages. |
| 7 | +# * A fork, push to its preview branch: build and publish a preview to the |
| 8 | +# fork's own GitHub Pages. The branch is the repository variable |
| 9 | +# DOCS_PREVIEW_BRANCH, or 'sphinx' when that is not set. Running the workflow |
| 10 | +# by hand on a fork publishes whichever branch it was started on. |
| 11 | +# * Anything else, pull requests included: build only, and keep the HTML as a |
| 12 | +# downloadable artifact. |
| 13 | +# |
| 14 | +# Publishing needs Settings > Pages > Source set to "GitHub Actions". On a |
| 15 | +# fork, the github-pages environment must also allow the preview branch to |
| 16 | +# deploy (Settings > Environments > github-pages). |
| 17 | + |
| 18 | +on: |
| 19 | + push: |
| 20 | + paths: &paths |
| 21 | + - 'docs/**' |
| 22 | + - 'README.md' |
| 23 | + - 'VERSION' |
| 24 | + - '.github/workflows/docs.yml' |
| 25 | + # The gallery extension the docs are built with. |
| 26 | + - 'sphinx-fplotlib-gallery/**' |
| 27 | + # The gallery builds the library and runs its examples, and the API |
| 28 | + # reference reads the sources. |
| 29 | + - 'src/**' |
| 30 | + - 'examples/**' |
| 31 | + - 'fpm.toml' |
| 32 | + pull_request: |
| 33 | + paths: *paths |
| 34 | + workflow_dispatch: |
| 35 | + |
| 36 | +concurrency: |
| 37 | + group: docs-${{ github.ref }} |
| 38 | + cancel-in-progress: true |
| 39 | + |
| 40 | +env: |
| 41 | + LANG: "en_US.UTF-8" |
| 42 | + LC_ALL: "en_US.UTF-8" |
| 43 | + PIP_DISABLE_PIP_VERSION_CHECK: "ON" |
| 44 | + PIP_NO_CLEAN: "ON" |
| 45 | + PIP_PREFER_BINARY: "ON" |
| 46 | + TZ: "UTC" |
| 47 | + |
| 48 | +jobs: |
| 49 | + build: |
| 50 | + name: Build |
| 51 | + permissions: |
| 52 | + contents: read |
| 53 | + runs-on: ubuntu-latest |
| 54 | + outputs: |
| 55 | + publish: ${{ steps.target.outputs.publish }} |
| 56 | + steps: |
| 57 | + - uses: actions/checkout@v4 |
| 58 | + |
| 59 | + - name: Decide where the docs go |
| 60 | + id: target |
| 61 | + env: |
| 62 | + UPSTREAM: fortran-lang/fplotlib |
| 63 | + PREVIEW_BRANCH: ${{ vars.DOCS_PREVIEW_BRANCH || 'sphinx' }} |
| 64 | + EVENT: ${{ github.event_name }} |
| 65 | + REPO: ${{ github.repository }} |
| 66 | + BRANCH: ${{ github.ref_name }} |
| 67 | + run: | |
| 68 | + publish=none |
| 69 | + if [ "$REPO" = "$UPSTREAM" ]; then |
| 70 | + if [ "$EVENT" != pull_request ] && [ "$BRANCH" = main ]; then |
| 71 | + publish=production |
| 72 | + fi |
| 73 | + elif [ "$EVENT" = workflow_dispatch ] \ |
| 74 | + || { [ "$EVENT" = push ] && [ "$BRANCH" = "$PREVIEW_BRANCH" ]; }; then |
| 75 | + publish=preview |
| 76 | + fi |
| 77 | + echo "publish=$publish" >> "$GITHUB_OUTPUT" |
| 78 | + echo "Docs for $REPO@$BRANCH ($EVENT): publish=$publish" |
| 79 | +
|
| 80 | + - name: Configure GitHub Pages |
| 81 | + if: steps.target.outputs.publish != 'none' |
| 82 | + uses: actions/configure-pages@v5 |
| 83 | + |
| 84 | + - uses: actions/setup-python@v5 |
| 85 | + with: |
| 86 | + python-version: '3.x' |
| 87 | + |
| 88 | + # The gallery in docs/gallery is built and run during the docs build, so |
| 89 | + # the same toolchain the tests use has to be here too. |
| 90 | + - name: Set up GFortran |
| 91 | + id: fortran |
| 92 | + uses: fortran-lang/setup-fortran@v2.0.0-beta.11 |
| 93 | + with: |
| 94 | + compiler: gfortran |
| 95 | + version: latest |
| 96 | + |
| 97 | + - uses: fortran-lang/setup-fpm@v10 |
| 98 | + with: |
| 99 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 100 | + |
| 101 | + # The gallery extension comes from this checkout rather than from PyPI, |
| 102 | + # so the docs always exercise the version being changed. |
| 103 | + - name: Install dependencies |
| 104 | + run: | |
| 105 | + pip install ./sphinx-fplotlib-gallery -r docs/requirements.txt |
| 106 | + python --version |
| 107 | + sphinx-build --version |
| 108 | + ford --version |
| 109 | +
|
| 110 | + - name: Build Docs |
| 111 | + env: |
| 112 | + # Picked up by docs/conf.py as fplotlib_gallery_compiler. |
| 113 | + FPM_FC: ${{ steps.fortran.outputs.fc }} |
| 114 | + run: sphinx-build -W -b html docs docs/_build/html |
| 115 | + |
| 116 | + - name: Upload the HTML |
| 117 | + uses: actions/upload-artifact@v4 |
| 118 | + with: |
| 119 | + name: docs-html |
| 120 | + path: ./docs/_build/html/ |
| 121 | + |
| 122 | + - name: Upload Pages artifact |
| 123 | + if: steps.target.outputs.publish != 'none' |
| 124 | + uses: actions/upload-pages-artifact@v4 |
| 125 | + with: |
| 126 | + path: ./docs/_build/html/ |
| 127 | + |
| 128 | + deploy: |
| 129 | + name: Publish (${{ needs.build.outputs.publish }}) |
| 130 | + if: needs.build.outputs.publish != 'none' |
| 131 | + needs: build |
| 132 | + permissions: |
| 133 | + pages: write |
| 134 | + id-token: write |
| 135 | + # Never cancel a deployment half way; queue the next one instead. |
| 136 | + concurrency: |
| 137 | + group: pages |
| 138 | + cancel-in-progress: false |
| 139 | + runs-on: ubuntu-latest |
| 140 | + environment: |
| 141 | + name: github-pages |
| 142 | + url: ${{ steps.deployment.outputs.page_url }} |
| 143 | + steps: |
| 144 | + - name: Deploy to GitHub Pages |
| 145 | + id: deployment |
| 146 | + uses: actions/deploy-pages@v4 |
0 commit comments