我考虑的是:
master
上的文件夹中托管文档。分行或专线gh-pages
分支,但这意味着提交构建工件 readthedocs
通过 webhooks 为我构建和托管文档,但这意味着在我尝试整合与我的项目相关的所有内容的时间点学习如何配置 Yet Another Tool 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/
换句话说,我仍然希望能够控制构建的发生方式以及工件的放置位置,但不想处理与
readthedocs
的交互。或 github-pages
.我尝试过的 Action
❌ deploy-to-github-pages : 在 npm 容器中运行 docs build - 不方便让它与 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 个结果在 Action 市场上,所有人看起来都想使用自己的构建器,可悲的是从来没有出现过 sphinx。
最佳答案
在管理sphinx
的情况下使用 pip ( requirements.txt
)、pipenv 或诗歌,我们可以将我们的文档部署到 GitHub 页面,如下所示。对于其他基于 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
关于python-sphinx - 使用 github 操作发布文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57989790/