如果Traith在github上成功,则增加版本号

gue*_*tli 16 python versioning github travis-ci

我用Python 编写了一个简单的脚本.

现在我想让travis检查我的代码.travis成功后,版本号应该增加.

到目前为止,我的脚本还没有版本号.我可以将它存储在对自动增量工作流程有意义的任何地方.

如何为Python代码执行此操作?

更新

它现在有效:

  1. 运行测试
  2. bumpversion
  3. 推送标签掌握

不幸的是,特拉维斯不支持"全部".这意味着如果我想运行几个Python版本的测试,在所有python版本的测试成功后我无法进行颠倒.

在我的情况下,我将检查Python2.7,直到travis解决了这个问题:https://github.com/travis-ci/travis-ci/issues/929

这是我的简单脚本:https://github.com/guettli/compare-with-remote

解决了 :-)

它现在有效:

  1. 开发人员推送到github
  2. Travis-CI运行
  3. 如果所有测试都成功,则颠倒会增加版本
  4. setup.py中的新版本被推送到github仓库
  5. 使用该工具将python包的新版本上传到pypi twine.

我在这里用github,travis和pypi解释我做CI的方式:https://github.com/guettli/github-travis-bumpversion-pypi

Tho*_*eau 10

如果您接受对版本控制进行额外提交,则可以添加此脚本 continuous_integration/increment_version.py

import os
import pkg_resources


if __name__ == "__main__":
    version = pkg_resources.get_distribution("compare_with_remote").version
    split_version = version.split('.')
    try:
        split_version[-1] = str(int(split_version[-1]) + 1)
    except ValueError:
        # do something about the letters in the last field of version
        pass
    new_version = '.'.join(split_version)
    os.system("sed -i \"s/version='[0-9.]\+'/version='{}'/\" setup.py"
              .format(new_version))
    os.system("git add -u")
    os.system("git commit -m '[ci skip] Increase version to {}'"
              .format(new_version))
    os.system("git push")
Run Code Online (Sandbox Code Playgroud)

并改变你.travis.yml

after_success:
  - python continuous_integration/increment_version.py
Run Code Online (Sandbox Code Playgroud)

我不确定如何使git push部件工作,因为它需要一些测试与回购权利,但我认为你可能设置一些东西,以允许travis推进你的回购.你可以查看那篇文章.

另请注意,我曾经python执行过git操作,但可以在after_success字段中添加为额外的行:

after_success:
  - python continuous_integration/increment_version.py
  - git add -u
  - git commit -m "[ci skip] version changed"
  - git push
Run Code Online (Sandbox Code Playgroud)

我发现将版本号放在commit msg中很方便.

此外,在提交消息中添加[ci skip]以避免无限增量非常重要.也许在特定的commit msg标记上触发版本更改会更安全.