Travis-CI在所有构建完成后仅部署一次

问题描述 投票:0回答:1

我正在尝试编写基本的Travis-CI脚本来测试构建我的Python包并针对python 3.5至3.8版本运行pytest。一旦所有这些都成功通过,我便希望Travis-CI构建文档并更新GitHub页面。我已经能够成功测试构建程序包并按预期运行测试,我什至可以构建文档,但是文档被构建了4次。我只希望文档在其他所有方法成功之后就可以构建和更新一次。我已经读过有关Jobs的信息,但尚未成功地使它与deploy关键字一起使用。

这里是到我的仓库的链接,因为它是当前的:https://github.com/CurtLH/my_pkg

这是我现有的Travis-CI脚本,该脚本可以运行,但是会部署到GitHub页面4次。如何调整脚本,使其仅构建和部署一次文档?

language: python
python:
  - 3.8
  - 3.7
  - 3.6
  - 3.5
install:
  - pip install -e .[dev]
script:
  - pytest
  - sphinx-build -n -b html -d docs/build/doctrees docs/source docs/build/html
  - touch docs/build/html/.nojekyll

deploy:
  provider: pages
  skip_cleanup: true
  github_token: $GITHUB_TOKEN
  keep-history: true
  on:
    branch: master
  local_dir: docs/build/html
travis-ci
1个回答
0
投票

您可以将构建分为两个阶段,一个阶段包含用于不同python版本的矩阵,另一个阶段用于部署步骤:https://docs.travis-ci.com/user/build-stages/matrix-expansion/

然后,在部署阶段,您可以为特定的python版本构建代码并进行部署,其中.travis.yml配置将变为:

language: python
python:
  - 3.8
  - 3.7
  - 3.6
  - 3.5
install:
  - pip install -e .[dev]
script:
  - pytest
  - sphinx-build -n -b html -d docs/build/doctrees docs/source docs/build/html
  - touch docs/build/html/.nojekyll

jobs:
  include:
    - stage: deploy
        python: 3.8
        install: pip install -e .[dev]
        script:
          - pytest
          - sphinx-build -n -b html -d docs/build/doctrees docs/source docs/build/html
          - touch docs/build/html/.nojekyll
        deploy:
          provider: pages
          skip_cleanup: true
          github_token: $GITHUB_TOKEN
          keep-history: true
          on:
          branch: master
          local_dir: docs/build/html

您还可以使用工作区(在Beta中)来存储所需的软件包版本,然后在将其发布到GitHub页面之前进行获取:https://docs.travis-ci.com/user/using-workspaces/

© www.soinside.com 2019 - 2024. All rights reserved.