diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000000..8538434e35 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,197 @@ +name: docs + +on: + push: + branches: + - master + paths: + - 'doc/**' + + pull_request: + branches: + - master + paths: + - 'doc/**' + + workflow_dispatch: + +permissions: + contents: read +jobs: + + # These first jobs will run regardless of whether the PR branch is from ESCOMP/CTSM or a fork. + + test-build-makefile: + if: ${{ always() }} + name: Test building documentation with makefile + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + lfs: true + - name: Install python 3.x + uses: actions/setup-python@v2 + with: + python-version: '3.x' + # https://github.com/actions/cache/blob/main/examples.md#python---pip + - name: Cache pip + uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('doc/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + - name: Install dependencies + run: | + pip install -r doc/requirements.txt + # Build documentation under ${PWD}/_build + - name: Build Sphinx docs with makefile + run: | + make SPHINXOPTS="-W --keep-going" BUILDDIR=${PWD}/_build -C doc/ html + + test-doc-builder: + if: ${{ always() }} + name: Test building documentation with doc-builder + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + lfs: true + - name: Install python 3.x + uses: actions/setup-python@v2 + with: + python-version: '3.x' + # https://github.com/actions/cache/blob/main/examples.md#python---pip + - name: Cache pip + uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('doc/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + - name: Install dependencies + run: | + pip install -r doc/requirements.txt + # Build documentation under ${PWD}/_build + - name: Build Sphinx docs with doc-builder + run: | + cd doc && ./build_docs -b ${PWD}/_build -c + +# The following jobs will only run if the PR branch is in ESCOMP/CTSM, not a fork. + + cleanup: + permissions: + contents: write # for git push + name: Cleanup branch previews + runs-on: ubuntu-latest + if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.event.pull_request.head.repo.full_name == github.repository + steps: + - uses: actions/checkout@v3 + with: + ref: 'gh-pages' + fetch-depth: 0 + lfs: true + path: gh-pages + - name: Remove branch previews + run: | + pushd $GITHUB_WORKSPACE/gh-pages + + if [[ -e "$GITHUB_WORKSPACE/gh-pages/branch" ]]; then + ls -la "$GITHUB_WORKSPACE/gh-pages/branch" + + for name in `ls branch/` + do + if [[ -z "$(git show-ref --quiet ${name})" ]] + then + git rm -rf branch/${name} + + echo "Removed $GITHUB_WORKSPACE/gh-pages/branch/${name}" + fi + done + + git config user.name github-actions[bot] + git config user.email github-actions[bot]@users.noreply.github.com + git commit -m "Clean up branch previews" + git push + fi + + echo "Done cleaning branches" + build-and-deploy: + permissions: + contents: write # for peaceiris/actions-gh-pages to push + pull-requests: write # to comment on pull requests + # needs: cleanup # + if: github.event.pull_request.head.repo.full_name == github.repository + name: Build and deploy documentation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + lfs: true + - name: Install python 3.x + uses: actions/setup-python@v2 + with: + python-version: '3.x' + # https://github.com/actions/cache/blob/main/examples.md#python---pip + - name: Cache pip + uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('doc/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + - name: Install dependencies + run: | + pip install -r doc/requirements.txt + # Build documentation under ${PWD}/_build + - name: Build Sphinx docs + run: | + make SPHINXOPTS=-W --keep-going BUILDDIR=${PWD}/_build -C doc/ html + - name: Push PR preview + if: | + github.event_name == 'pull_request' && + github.event.pull_request.head.repo.full_name == github.repository + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{secrets.GITHUB_TOKEN}} + publish_branch: gh-pages-preview + publish_dir: './_build/html' + destination_dir: './branch/${{ github.event.pull_request.head.ref }}/html' + user_name: 'github-actions[bot]' + user_email: 'github-actions[bot]@users.noreply.github.com' + - name: Comment about previewing documentation + if: | + github.event_name == 'pull_request' && + github.event.pull_request.head.repo.full_name == github.repository + uses: actions/github-script@v6 + with: + script: | + const comments = await github.paginate(github.rest.issues.listComments, { + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number + }); + + const havePosted = comments.map(x => x.user.login).some(x => x === "github-actions[bot]"); + + if (!havePosted) { + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: 'You can preview documentation at https://escomp.github.io/ctsm/branch/${{ github.event.pull_request.head.ref }}/html/index.html' + }) + } + # - name: Push new docs + # if: ${{ github.event_name == 'push' }} + # uses: peaceiris/actions-gh-pages@v3 + # with: + # github_token: ${{secrets.GITHUB_TOKEN}} + # publish_dir: './_build/html' + # destination_dir: './versions/master/html' + # user_name: 'github-actions[bot]' + # user_email: 'github-actions[bot]@users.noreply.github.com' + diff --git a/.gitmodules b/.gitmodules index 7274b9acd2..cd462315c3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -123,8 +123,8 @@ fxDONOTUSEurl = https://github.com/NCAR/ParallelIO [submodule "doc-builder"] path = doc/doc-builder -url = https://github.com/ESMCI/doc-builder -fxtag = v1.0.8 +url = https://github.com/samsrabin/doc-builder +fxtag = c51795f65d230803418c932bfd8639c85c33a19a fxrequired = ToplevelOptional # Standard Fork to compare to with "git fleximod test" to ensure personal forks aren't committed fxDONOTUSEurl = https://github.com/ESMCI/doc-builder diff --git a/doc/doc-builder b/doc/doc-builder index ab9bc93dd0..c51795f65d 160000 --- a/doc/doc-builder +++ b/doc/doc-builder @@ -1 +1 @@ -Subproject commit ab9bc93dd09d0173f8097c7a18c7d061c1cd3b79 +Subproject commit c51795f65d230803418c932bfd8639c85c33a19a diff --git a/doc/requirements.txt b/doc/requirements.txt new file mode 100644 index 0000000000..f282ec48e4 --- /dev/null +++ b/doc/requirements.txt @@ -0,0 +1,4 @@ +esbonio == 0.16.4 +sphinx == 7.2.6 +sphinx-mdinclude == 0.6.2 +sphinx_rtd_theme == 2.0.0 diff --git a/doc/source/_static/pop_ver.js b/doc/source/_static/pop_ver.js deleted file mode 100644 index b8c58658a8..0000000000 --- a/doc/source/_static/pop_ver.js +++ /dev/null @@ -1,37 +0,0 @@ -$(document).ready(function() { - /* For a URL that looks like - https://blah.github.io/versions/VERSIONFOO/html/bar/index.html, set cur_version_dir to - 'VERSIONFOO' (i.e., the portion of the path following 'versions'). - */ - var proj_end = document.baseURI.indexOf("versions") + 9; - var end = document.baseURI.indexOf("/", proj_end); - var cur_version_dir = document.baseURI.substring(proj_end, end); - var mylist = $("#version-list"); - mylist.empty(); - $.getJSON(version_json_loc, function(data) { - if (data.hasOwnProperty(cur_version_dir)) { - /* First add the current version so that it appears first in the drop-down - menu and starts as the selected element of the menu. If you click on the - current version, you should stay at the current page. - - The conditional around this block should generally be true, but we check it - just in case the current version is missing from the versions.json file for - some reason. - */ - cur_version_name = data[cur_version_dir]; - mylist.append($("