【问题标题】:Using github actions to publish documentation使用 github 操作发布文档
【发布时间】:2020-01-19 05:38:57
【问题描述】:

我的考虑:

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

我已经有一个适合我的文档构建过程(使用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/

换句话说,我希望仍然可以控制构建的发生方式和工件的丢弃位置,但不想处理与readthedocsgithub-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 以触发重建(不方便)和uploads broken html(这很糟糕,但可能是我的错)

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


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

【问题讨论】:

  • 市场上有很多 GitHub Pages 操作。这些都不是你想要的吗? github.com/…
  • 我正在尝试让this one 立即工作,我想这将是一个合理的解决方法。但据我所见,它们都不支持只推送工件,而是会在 master 中创建 docs/ 文件夹或推送到 gh-pages
  • @peterevans 我测试了它,它对我不起作用。我会用我尝试过的操作来更新我的问题。
  • 您提到某些操作不支持 yaml 语法。我认为情况并非如此。只是所有者没有更新他们的示例来展示在 yaml 中引用动作的新方法。对于上述操作之一,您可以在此处看到有人提出 PR 以更新文档。 github.com/Cecilapp/GitHub-Pages-deploy/pull/3/files
  • 我特别尝试摆弄那个动作,并最终假设除非书面,否则样式之间没有翻译。感谢您指出,我会改变我的cmets。

标签: python-sphinx github-pages read-the-docs github-actions


【解决方案1】:

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

有关更多选项,请参阅最新的 README:peaceiris/actions-gh-pages: GitHub Actions for GitHub Pages ? Deploy static files and publish your site easily. Static-Site-Generators-friendly.

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

【讨论】:

    【解决方案2】:

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

    这是我当前的release_sphinx 作业,它使用deploy-action-for-github-pages action 并上传到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
    

    感谢部署操作的维护者,他们解决了上传问题 within 8 minutes 我将其发布为问题。

    【讨论】:

      猜你喜欢
      • 2023-02-14
      • 2020-10-07
      • 2020-11-28
      • 2022-10-21
      • 2021-05-27
      • 2020-10-16
      • 2021-11-22
      • 1970-01-01
      • 2023-02-14
      相关资源
      最近更新 更多