10

我认为:

  • github 提供 github 页面来在我的master分支上的文件夹或专用gh-pages分支中托管文档,但这意味着提交构建工件
  • 我还可以让readthedocs我通过 webhook 为我构建和托管文档,但这意味着在我尝试将与我的项目相关的所有内容整合到github-actions

我已经有一个适合我的文档构建过程(sphinx用作构建器)并且我也可以在本地进行测试,所以我宁愿利用它。它设置了所有规则并html在工件中删除了一些静态 - 它只是没有在任何地方提供服务。在我的项目的所有其他部署配置所在的工作流程中处理它比将它分散在不同的工具或 github 特定选项上感觉更好。

市场上是否已经存在允许我执行此类操作的操作?

name: CI
on: [push]
jobs:
  
  ...  # do stuff like building my-project-v1.2.3.whl, testing, etc.
  
  release_docs:
    steps:
      - uses: actions/sphinx-to-pages@v1  # I wish this existed
        with:
          dependencies:
            - some-sphinx-extension
            - dist/my-project*.whl
          apidoc_args:
            - "--no-toc"
            - "--module-first"
            - "-o docs/autodoc"
            - "src/my-project"
          build-args:
            - "docs"
            - "public"  # the content of this folder will then be served at
                        # https://my_gh_name.github.io/my_project/

换句话说,我希望仍然可以控制构建的发生方式以及工件的丢弃位置,但不想处理与readthedocsor的交互github-pages


###我尝试过的操作

deploy-to-github-pages:在 npm 容器中运行文档构建 - 使其与 python 和 sphinx 一起使用会很不方便

gh-pages-for-github-action:没有文档

gh-pages-deploy似乎针对像 jekyll 这样的主机环境而不是静态内容,并且使用 yml 语法的正确用法尚未记录 - 我尝试了一点,但无法让它工作

github-pages-deploy:看起来不错,但尚未记录 yml 语法的正确用法


github-pages:需要自定义PAT以触发重建(不方便)并上传损坏的 html(这很糟糕,但可能是我的错)

deploy-action-for-github-pages:也可以,并且在日志中看起来更干净一些。虽然与上面的解决方案相同的限制,它需要一个 PAT 并且提供的 html 仍然被破坏。


在行动市场上搜索github+pages时的其他 11 个结果看起来都像是他们想要使用自己的构建器,遗憾的是,它从来没有碰巧是 sphinx。

4

2 回答 2

4

sphinx使用 pip( requirements.txt)、pipenv 或诗歌进行管理的情况下,我们可以将我们的文档部署到 GitHub Pages,如下所示。对于其他基于 Python 的静态站点生成器,例如 pelican 和 MkDocs,工作流程也一样。这是 MkDocs 的一个简单示例。我们只是将工作流程添加为.github/workflows/gh-pages.yml

有关更多选项,请参阅最新的自述文件:peaceiris/actions-gh-pages:GitHub 页面的 GitHub 操作部署静态文件并轻松发布您的网站。静态站点生成器友好。

name: github pages

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/checkout@v2

      - name: Setup Python
        uses: actions/setup-python@v2
        with:
          python-version: '3.8'

      - name: Upgrade pip
        run: |
          # install pip=>20.1 to use "pip cache dir"
          python3 -m pip install --upgrade pip

      - name: Get pip cache dir
        id: pip-cache
        run: echo "::set-output name=dir::$(pip cache dir)"

      - name: Cache dependencies
        uses: actions/cache@v2
        with:
          path: ${{ steps.pip-cache.outputs.dir }}
          key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
          restore-keys: |
            ${{ runner.os }}-pip-

      - name: Install dependencies
        run: python3 -m pip install -r ./requirements.txt

      - run: mkdocs build

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./site
于 2020-10-12T05:05:51.547 回答
2

我让它工作了,但是目前还没有专门的操作来构建和托管 sphinx 文档github pagesreadthedocs所以就我而言,这里还有很多不足之处。

这是我当前release_sphinx的工作,它使用deploy-action-for-github-pages 操作并上传到github-pages

release_sphinx:
  needs: [build]
  runs-on: ubuntu-latest
  container:
    image: python:3.6
    volumes:
      - dist:dist
      - public:public
  steps:

    # check out sources that will be used for autodocs, plus readme
    - uses: actions/checkout@v1

    # download wheel that was build and uploaded in the build step
    - uses: actions/download-artifact@v1
      with:
        name: distributions
        path: dist

    # didn't need to change anything here, but had to add sphinx.ext.githubpages
    # to my conf.py extensions list. that fixes the broken uploads
    - name: Building documentation
      run: |
        pip install dist/*.whl
        pip install sphinx Pallets-Sphinx-Themes
        sphinx-apidoc --no-toc --module-first -o docs/autodoc src/stenotype
        sphinx-build docs public -b dirhtml

    # still need to build and set the PAT to get a rebuild on the pages job,
    # apart from that quite clean and nice 
    - name: github pages deploy
      uses: peaceiris/actions-gh-pages@v2.3.1
      env:
        PERSONAL_TOKEN: ${{ secrets.PAT }}
        PUBLISH_BRANCH: gh-pages
        PUBLISH_DIR: public

    # since gh-pages has a history, this step might no longer be necessary.
    - uses: actions/upload-artifact@v1
      with:
        name: documentation
        path: public

向部署操作的维护者大喊,他们在我将上传问题发布为问题后的 8 分钟内解决了上传问题。

于 2019-09-19T10:23:07.063 回答