Arn*_*rne 8 python-sphinx github-pages read-the-docs github-actions
我考虑的是:
master分支或专用gh-pages分支上的文件夹中托管文档,但这意味着提交构建工件readthedocs通过 webhooks 为我构建和托管文档,但这意味着在我尝试整合与我的项目相关的所有内容的时间点学习如何配置 Yet Another Toolgithub-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/
Run Code Online (Sandbox Code Playgroud)
换句话说,我仍然希望能够控制构建的发生方式以及工件的放置位置,但不想处理与readthedocs或的交互github-pages。
? deploy-to-github-pages:在 npm 容器中运行 docs 构建 - 将不方便使其与 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。
小智 6
sphinx在使用 pip ( requirements.txt)、pipenv 或 Poetry进行管理的情况下,我们可以将文档部署到 GitHub Pages,如下所示。对于其他基于 Python 的静态站点生成器(如 pelican 和 MkDocs),工作流程是相同的。这是 MkDocs 的一个简单示例。我们只需将工作流程添加为.github/workflows/gh-pages.yml
有关更多选项,请参阅最新的自述文件:peaceiris/actions-gh-pages:GitHub Pages 的 GitHub Actions 轻松部署静态文件并发布站点。静态站点生成器友好。
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
Run Code Online (Sandbox Code Playgroud)
github pages我已经让它工作了,但是到目前为止还没有专门的行动来构建和托管 sphinx 文档readthedocs,所以就我而言,这里还有很多需要改进的地方。
这是我当前的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
Run Code Online (Sandbox Code Playgroud)
感谢部署操作的维护者,他在我将上传问题发布为问题后 8 分钟内解决了该问题。
| 归档时间: |
|
| 查看次数: |
2124 次 |
| 最近记录: |