|
| 1 | +name: Docs |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [main] |
| 6 | + types: [opened, synchronize] |
| 7 | + paths: |
| 8 | + - "docs/**" |
| 9 | + push: |
| 10 | + branches: [main] |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +defaults: |
| 14 | + run: |
| 15 | + shell: bash |
| 16 | + |
| 17 | +env: |
| 18 | + MISE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 19 | + |
| 20 | +concurrency: |
| 21 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 22 | + cancel-in-progress: true |
| 23 | + |
| 24 | +jobs: |
| 25 | + build: |
| 26 | + runs-on: build-arm64 |
| 27 | + container: |
| 28 | + image: ghcr.io/nvidia/nv-agent-env/ci:latest |
| 29 | + credentials: |
| 30 | + username: ${{ github.actor }} |
| 31 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 32 | + steps: |
| 33 | + - name: Checkout |
| 34 | + uses: actions/checkout@v4 |
| 35 | + |
| 36 | + - name: Install tools |
| 37 | + run: mise install |
| 38 | + |
| 39 | + - name: Build documentation |
| 40 | + run: mise run docs:build:strict |
| 41 | + |
| 42 | + - name: Delete unnecessary files |
| 43 | + run: | |
| 44 | + find _build -name .doctrees -prune -exec rm -rf {} \; |
| 45 | + find _build -name .buildinfo -exec rm {} \; |
| 46 | +
|
| 47 | + - name: Upload HTML |
| 48 | + uses: actions/upload-artifact@v4 |
| 49 | + with: |
| 50 | + name: html-build-artifact |
| 51 | + path: _build/docs |
| 52 | + if-no-files-found: error |
| 53 | + retention-days: 1 |
| 54 | + - name: Store PR information |
| 55 | + if: github.event_name == 'pull_request' |
| 56 | + run: | |
| 57 | + mkdir ./pr |
| 58 | + echo ${{ github.event.number }} > ./pr/pr.txt |
| 59 | + echo ${{ github.event.pull_request.merged }} > ./pr/merged.txt |
| 60 | + echo ${{ github.event.action }} > ./pr/action.txt |
| 61 | +
|
| 62 | + - name: Upload PR information |
| 63 | + if: github.event_name == 'pull_request' |
| 64 | + uses: actions/upload-artifact@v4 |
| 65 | + with: |
| 66 | + name: pr |
| 67 | + path: pr/ |
| 68 | + |
| 69 | + publish: |
| 70 | + if: github.event_name == 'push' && github.repository_owner == 'NVIDIA' |
| 71 | + needs: [build] |
| 72 | + runs-on: build-arm64 |
| 73 | + container: |
| 74 | + image: ghcr.io/nvidia/nv-agent-env/ci:latest |
| 75 | + credentials: |
| 76 | + username: ${{ github.actor }} |
| 77 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 78 | + steps: |
| 79 | + - uses: actions/checkout@v4 |
| 80 | + with: |
| 81 | + ref: "gh-pages" |
| 82 | + |
| 83 | + - name: Initialize Git configuration |
| 84 | + run: | |
| 85 | + git config user.name docs-build |
| 86 | + git config user.email do-not-send@github.com |
| 87 | +
|
| 88 | + - name: Download artifacts |
| 89 | + uses: actions/download-artifact@v4 |
| 90 | + with: |
| 91 | + name: html-build-artifact |
| 92 | + path: ${{ github.ref_name }} |
| 93 | + |
| 94 | + - name: Copy HTML directories |
| 95 | + run: | |
| 96 | + ls -asl |
| 97 | + for i in `ls -d *` |
| 98 | + do |
| 99 | + echo "Git adding ${i}" |
| 100 | + git add "${i}" |
| 101 | + done |
| 102 | + - name: Check or create dot-no-jekyll file |
| 103 | + |
| 104 | + run: | |
| 105 | + if [ -f ".nojekyll" ]; then |
| 106 | + echo "The dot-no-jekyll file already exists." |
| 107 | + exit 0 |
| 108 | + fi |
| 109 | + touch .nojekyll |
| 110 | + git add .nojekyll |
| 111 | +
|
| 112 | + - name: Check or create redirect page |
| 113 | + env: |
| 114 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 115 | + run: | |
| 116 | + resp=$(grep 'http-equiv="refresh"' index.html 2>/dev/null) || true |
| 117 | + if [ -n "${resp}" ]; then |
| 118 | + echo "The redirect file already exists." |
| 119 | + exit 0 |
| 120 | + fi |
| 121 | + def_branch=$(gh api "repos/${GITHUB_REPOSITORY}" --jq ".default_branch") |
| 122 | + html_url=$(gh api "repos/${GITHUB_REPOSITORY}/pages" --jq ".html_url") |
| 123 | + echo '<!DOCTYPE html>' > index.html |
| 124 | + echo '<html>' >> index.html |
| 125 | + echo ' <head>' >> index.html |
| 126 | + echo ' <title>Redirect to documentation</title>' >> index.html |
| 127 | + echo ' <meta charset="utf-8">' >> index.html |
| 128 | + echo ' <meta http-equiv="refresh" content="3; URL='${html_url}${def_branch}'/index.html">' >> index.html |
| 129 | + echo ' <link rel="canonical" href="'${html_url}${def_branch}'/index.html">' >> index.html |
| 130 | + echo ' <script language="javascript">' >> index.html |
| 131 | + echo ' function redirect() {' >> index.html |
| 132 | + echo ' window.location.assign("'${html_url}${def_branch}'/index.html")' >> index.html |
| 133 | + echo ' }' >> index.html |
| 134 | + echo ' </script>' >> index.html |
| 135 | + echo ' </head>' >> index.html |
| 136 | + echo ' <body onload="redirect()">' >> index.html |
| 137 | + echo ' <p>Please follow the link to the <a href="'${html_url}${def_branch}'/index.html">' >> index.html |
| 138 | + echo ${def_branch}'</a> branch documentation.</p>' >> index.html |
| 139 | + echo ' </body>' >> index.html |
| 140 | + echo '</html>' >> index.html |
| 141 | + git add index.html |
| 142 | +
|
| 143 | + - name: Commit changes to the GitHub Pages branch |
| 144 | + run: | |
| 145 | + git status |
| 146 | + if git commit -m 'Pushing changes to GitHub Pages.'; then |
| 147 | + git push -f |
| 148 | + else |
| 149 | + echo "Nothing changed." |
| 150 | + fi |
0 commit comments