如何防止travis部署两次?

时间:2016-09-06 05:51:17

标签: continuous-integration travis-ci

我已将travis设置为使用tox(Python 2.7和3.5)进行测试并部署到pypi。

Travis尝试为每次测试运行部署程序包,pypi正确拒绝第二次尝试。

我希望只有当tox成功完成两次运行时,travis才会部署一次。这是如何完成的?

Travis配置:https://github.com/biocommons/biocommons.seqrepo/blob/master/.travis.yml

测试运行:https://travis-ci.org/biocommons/biocommons.seqrepo/builds/157794212(68.2先完成并推送到pypi。pypi错误在68.1。)

相关但陈旧的问题:Why does Travis not wait for all builds to pass before deploying?

1 个答案:

答案 0 :(得分:2)

现在可以使用目前处于测试阶段的build stages来完成此操作。看起来像这样:

stages:  # determines the order everything runs in
- test
- deploy
jobs:  #  specifies the actual job
  include:
    - stage: test
      # configuration for a stage here
    - stage: deploy
      # configuration for the next stage here

给出.travis.yml这样的:

language: python
sudo: false
cache: pip
python:
- 2.7
- 3.4
- 3.5
- 3.6
- pypy
install:
- pip install tox-travis
script:
- tox
deploy:
  provider: pypi
  user: stephenfin
  password:
    secure: <key omitted for brevity>
  on:
    tags: true
  distributions: sdist bdist_wheel

你会像这样转换它:

language: python
sudo: false
cache: pip
python:
- 2.7
- 3.4
- 3.5
- 3.6
- pypy
install:
- pip install tox-travis
script:
- tox
stages:
- test
- deploy
jobs:
  include:
    - stage: deploy
      python: 3.6
      install: skip  # no tests, no depedencies needed
      script: skip  # we're not running tests
      deploy:
        provider: pypi
        user: stephenfin
        password:
          secure: <key omitted for brevity>
        on:
          tags: true
        distributions: sdist bdist_wheel

就个人而言,我发现这有点违反直觉:我希望所有不是 global 的东西都嵌套在stage之下。因此,我明确定义了test阶段并嵌套了pythoninstallscript键。但是,这不起作用,而您需要在顶层设置这些键,然后在各个阶段显式覆盖它们。全局内容将由test阶段调用,这是默认作业。我还没有确定这是Travis或tox-travis插件(目前是0.10)的问题,但值得一提。

另请注意,如果您使用的是Travis Gem,travis lint命令当前失败,因为此功能尚不支持。有bug开放。