我认为:

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

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

    市场上是否已有某种 Action 可以让我做这样的事情?
    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的交互。

    我尝试过的 Action

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

    gh-pages-for-github-action:无文档

    oji gh-pages-deploy:像jekyll一样,目标主机环境而不是静态内容,并且尚未记录yml语法的正确用法-我尝试了一下,无法使其正常工作

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

    oji github-pages:需要自定义PAT才能触发重建(不方便)和uploads broken html(这很糟糕,但这可能是我的错)

    deploy-action-for-github-pages:也可以,并且在日志中看起来更干净一些。与上层解决方案相同的局限性是,它需要使用PAT,并且所提供的html仍然损坏。

    在 Action 市场上搜索github+pages时,其他11个结果都看起来像是他们想要使用自己的构建器,可悲的是,从来没有碰巧是狮身人面像。

    最佳答案

    在使用pip(sphinx),pipenv或诗歌管理requirements.txt的情况下,我们可以按以下方式将文档部署到GitHub Pages。对于其他基于Python的静态站点生成器(如pelican和MkDocs),工作流程也是如此。这是MkDocs的一个简单示例。我们只是将工作流程添加为.github/workflows/gh-pages.yml有关更多选项,请参见最新的自述文件: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
    

    关于python-sphinx - 使用github操作发布文档,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57989790/

    10-12 00:12
    查看更多