|
| 1 | +name: Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + schedule: |
| 8 | + - cron: 0 1 * * * # daily |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: pages |
| 13 | + cancel-in-progress: true |
| 14 | + |
| 15 | +jobs: |
| 16 | + list-docs: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + matrix: ${{ steps.make-matrix.outputs.matrix }} |
| 20 | + index_json: ${{ steps.make-matrix.outputs.index_json }} |
| 21 | + hash: ${{ steps.check-hash.outputs.hash }} |
| 22 | + changed: ${{ steps.check-hash.outputs.changed }} |
| 23 | + env: |
| 24 | + # This option controls which branches/tags are included in the documentation. |
| 25 | + list_docs_options: -d master -m v4.3.1 -e v5.0.0-beta.1 -s |
| 26 | + steps: |
| 27 | + - name: Checkout the repository |
| 28 | + uses: actions/checkout@v6 |
| 29 | + |
| 30 | + - name: Build docs index |
| 31 | + id: make-matrix |
| 32 | + run: | |
| 33 | + ./scripts/list-docs.sh ${{ env.list_docs_options }} >_index.json |
| 34 | + cat _index.json |
| 35 | +
|
| 36 | + matrix="$(jq -c '{include: .docs}' _index.json)" |
| 37 | + echo "matrix=$matrix" >>"$GITHUB_OUTPUT" |
| 38 | +
|
| 39 | + index_json="$(jq -cS . _index.json)" |
| 40 | + echo "index_json=$index_json" >>"$GITHUB_OUTPUT" |
| 41 | + echo "$index_json" >_index.json |
| 42 | +
|
| 43 | + - name: Compute hash and check if updated |
| 44 | + id: check-hash |
| 45 | + env: |
| 46 | + hash: ${{ hashFiles('_index.json', 'scripts/make-docs.sh', 'scripts/update-index.sh', 'docs/_config.yml') }} |
| 47 | + run: | |
| 48 | + changed=true |
| 49 | + git fetch --no-tags origin pages-state:refs/remotes/origin/pages-state 2>/dev/null || : |
| 50 | + if git show origin/pages-state:.pages.hash >/dev/null 2>&1; then |
| 51 | + old_hash=$(git show origin/pages-state:.pages.hash | tr -d '\r\n') |
| 52 | + if [ "$hash" = "$old_hash" ]; then |
| 53 | + changed=false |
| 54 | + fi |
| 55 | + fi |
| 56 | + echo "changed=$changed" >>"$GITHUB_OUTPUT" |
| 57 | + echo "hash=$hash" >>"$GITHUB_OUTPUT" |
| 58 | +
|
| 59 | + build-docs: |
| 60 | + name: build-docs (${{ matrix.dir }}) |
| 61 | + needs: list-docs |
| 62 | + runs-on: ubuntu-latest |
| 63 | + outputs: |
| 64 | + index_json: ${{ needs.list-docs.outputs.index_json }} |
| 65 | + hash: ${{ needs.list-docs.outputs.hash }} |
| 66 | + changed: ${{ needs.list-docs.outputs.changed }} |
| 67 | + strategy: |
| 68 | + fail-fast: false |
| 69 | + matrix: ${{ fromJSON(needs.list-docs.outputs.matrix) }} |
| 70 | + steps: |
| 71 | + - name: Checkout the repository |
| 72 | + uses: actions/checkout@v6 |
| 73 | + |
| 74 | + - name: Cache docs |
| 75 | + id: cache-docs |
| 76 | + uses: actions/cache@v4 |
| 77 | + with: |
| 78 | + path: docs/${{ matrix.dir }} |
| 79 | + key: docs-${{ matrix.dir }}-${{ matrix.ref }}-${{ matrix.dev }}-${{ hashFiles('scripts/make-docs.sh') }} |
| 80 | + |
| 81 | + - name: Install dependencies |
| 82 | + if: steps.cache-docs.outputs.cache-hit != 'true' && needs.list-docs.outputs.changed == 'true' |
| 83 | + run: | |
| 84 | + sudo apt-get update |
| 85 | + sudo apt-get install -y --no-install-recommends doxygen-latex graphviz groff latex2html |
| 86 | +
|
| 87 | + - name: Build docs |
| 88 | + if: steps.cache-docs.outputs.cache-hit != 'true' && needs.list-docs.outputs.changed == 'true' |
| 89 | + run: ./scripts/make-docs.sh ${{ matrix.dev && '-d ' || '' }}${{ matrix.ref }} docs/${{ matrix.dir }} |
| 90 | + |
| 91 | + - name: Upload docs artifact |
| 92 | + if: needs.list-docs.outputs.changed == 'true' |
| 93 | + uses: actions/upload-artifact@v4 |
| 94 | + with: |
| 95 | + name: docs-${{ matrix.dir }} |
| 96 | + path: | |
| 97 | + docs/${{ matrix.dir }} |
| 98 | + workaround/for/upload-artifact/issues/174 # See: https://github.com/actions/upload-artifact/issues/174 |
| 99 | + if-no-files-found: error |
| 100 | + |
| 101 | + collect-docs: |
| 102 | + needs: build-docs |
| 103 | + if: needs.build-docs.outputs.changed == 'true' |
| 104 | + runs-on: ubuntu-latest |
| 105 | + outputs: |
| 106 | + hash: ${{ needs.build-docs.outputs.hash }} |
| 107 | + steps: |
| 108 | + - name: Checkout the repository |
| 109 | + uses: actions/checkout@v6 |
| 110 | + |
| 111 | + - name: Download all docs artifacts |
| 112 | + uses: actions/download-artifact@v4 |
| 113 | + with: |
| 114 | + merge-multiple: true |
| 115 | + |
| 116 | + - name: Build docs index page |
| 117 | + run: | |
| 118 | + echo '${{ needs.build-docs.outputs.index_json }}' >_index.json |
| 119 | + ./scripts/update-index.sh _index.json docs |
| 120 | + cat docs/index.md |
| 121 | +
|
| 122 | + - name: Configure GitHub Pages |
| 123 | + uses: actions/configure-pages@v5 |
| 124 | + |
| 125 | + - name: Build site with Jekyll |
| 126 | + uses: actions/jekyll-build-pages@v1 |
| 127 | + with: |
| 128 | + source: docs |
| 129 | + destination: _site |
| 130 | + |
| 131 | + - name: Upload Pages artifact |
| 132 | + uses: actions/upload-pages-artifact@v3 |
| 133 | + with: |
| 134 | + path: _site |
| 135 | + |
| 136 | + deploy-docs: |
| 137 | + needs: collect-docs |
| 138 | + runs-on: ubuntu-latest |
| 139 | + outputs: |
| 140 | + hash: ${{ needs.collect-docs.outputs.hash }} |
| 141 | + permissions: |
| 142 | + pages: write |
| 143 | + id-token: write |
| 144 | + environment: |
| 145 | + name: github-pages |
| 146 | + url: ${{ steps.deployment.outputs.page_url }} |
| 147 | + steps: |
| 148 | + # Prerequisite: The following repository setting is required: |
| 149 | + # Pages -> Build and deployment -> Source: GitHub Actions |
| 150 | + - name: Deploy to GitHub Pages |
| 151 | + id: deployment |
| 152 | + uses: actions/deploy-pages@v4 |
| 153 | + |
| 154 | + update-state: |
| 155 | + needs: deploy-docs |
| 156 | + runs-on: ubuntu-latest |
| 157 | + permissions: |
| 158 | + contents: write |
| 159 | + steps: |
| 160 | + - name: Checkout the repository |
| 161 | + uses: actions/checkout@v6 |
| 162 | + |
| 163 | + - name: Update pages-state hash |
| 164 | + run: | |
| 165 | + git fetch --no-tags origin pages-state:refs/remotes/origin/pages-state 2>/dev/null || : |
| 166 | + if git show-ref --verify --quiet refs/remotes/origin/pages-state; then |
| 167 | + git switch -c pages-state --track origin/pages-state 2>/dev/null || git switch pages-state |
| 168 | + else |
| 169 | + git switch --orphan pages-state |
| 170 | + fi |
| 171 | + echo '${{ needs.deploy-docs.outputs.hash }}' >.pages.hash |
| 172 | + git add .pages.hash |
| 173 | + git -c user.name='github-actions[bot]' \ |
| 174 | + -c user.email='41898282+github-actions[bot]@users.noreply.github.com' \ |
| 175 | + commit -m 'chore(pages): update deployed hash' || true |
| 176 | + git push origin pages-state |
0 commit comments