【问题标题】:Travis-CI only deploy once after all builds finishTravis-CI 仅在所有构建完成后部署一次
【发布时间】:2019-12-20 01:46:16
【问题描述】:

我正在尝试编写一个基本的 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】:

    您可以将您的构建分为两个阶段,一个用于不同 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/

    【讨论】:

      猜你喜欢
      • 2019-10-08
      • 2019-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-17
      • 2018-04-14
      • 2016-07-06
      • 2020-07-01
      相关资源
      最近更新 更多