Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

69
Vistas
Increase Version number if Travis at github was successful

I wrote a simple script in Python.

Now I would like travis to check my code. After travis was successful, the version number should get increased.

Up to now my script has no version number yet. I can store it anywhere where it makes sense for the auto-increment workflow.

How to do this for Python code?

Update

It works now:

  1. run tests
  2. bumpversion
  3. push tag to master

Unfortunately travis does not support "after-all". This means if I want to run the tests for several Python versions, I have no way to bumpversion after the tests of all python versions were successful.

In my case I will check on Python2.7 only until travis resolved this issue: https://github.com/travis-ci/travis-ci/issues/929

Here is my simple script: https://github.com/guettli/compare-with-remote

Solved :-)

It works now:

  1. Developer pushes to github
  2. Travis-CI runs
  3. If all tests are successful bumpversion increases the version
  4. The new version in setup.py get's pushed to the github repo
  5. A new release of the python package gets uploaded to pypi with the tool twine.

I explain the way I do CI with github, travis and pypi here: https://github.com/guettli/github-travis-bumpversion-pypi

8 months ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

If you accept having extra commit for your versioning, you could add this script in 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")

And change your .travis.yml to

after_success:
  - python continuous_integration/increment_version.py

I am not sure about how to make the git push part work as it need some testing with the repo rights but I assume that you could probably setup something to allow travis to push in your repo. you could look into that post for instance.

Also note that I used python to perform the git operations but they can be added as extra line in the after_success field:

after_success:
  - python continuous_integration/increment_version.py
  - git add -u
  - git commit -m "[ci skip] version changed"
  - git push

I just find it convenient to put the version number in the commit msg.

Also, it is very important to add [ci skip] in the commit message to avoid infinite increment. Maybe it would be safer to trigger the version change on a specific commit msg tag.

8 months ago · Santiago Trujillo Denunciar

0

Not Python-specific, but this tutorial explains auto-incrementing version numbers by adding .travis.yaml entries which update git tags with each successful build. It seems like a good balance between manual and auto-versioning.

While the tutorial does use npm's package.json for the initial version-check, you could implement a simple equivalent (in Python or otherwise).

8 months ago · Santiago Trujillo Denunciar

0

Assuming that,

  • only commits with successful Travis CI builds get merged into the master branch (e.g. using Pull Requests)
  • the package is always installed with pip from a git repo using, for instance,

    pip install git+https://github.com/user/package.git
    

For auto-incrementing version number, one could simply define the version as the number of commits in the master branch. This can be done with the following lines in setup.py,

minor_version = check_output(['git', 'rev-list',
                              '--count', 'master']).decode('latin-1').strip()

setup(version='0.{}'.format(minor_version), ...)
8 months ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.