Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Releasing servicemanager

Tim Bennett edited this page Jul 3, 2020 · 10 revisions

Release to Pypi

These instructions apply to members of the HMRC organisation

Changes should be made on a branch and a Pull Request raised.

As well as the required changes, the PR should increment the version number in setup.py.

Steps to release a new version:

  1. Review the changes in the PR. A travis build as well as a PR builder on Jenkins should kick off automatically and build and run the tests
  2. If all tests pass, and you are happy with the changes, merge the PR
    1. (Optional) For non-trivial changes, you may wish to release and test the new artefact more widely internally before merging. See the section below
  3. In build Jenkins, run the service-manager job, with the option checked to release to artefactory
  4. Review and test the new artefact internally. See the section below
  5. Once happy, run the service-manager-pypi-release job on the build server to push it to pypi.

Done. Anyone using servicemanager should now be able to upgrade their local install with:

pip install servicemanager --upgrade

Testing a pre-release version

The servicemanager artefact is released to the public pypi repository. When testing, you will likely want to be able to test a new version without actually releasing it to the open.

pip can be pointed at different repositories to allow testing pre-release artefacts.

This can be done from either artefactory or test.pypi (which is a completely separate pypi server just for testing).

From Artefactory:

In build Jenkins, run the service-manager job, with the option checked to release to artefactory.

If you want to build the new release off of the branch before merging to master, just set the param to the required branch

Once released to artefactory, anyone in HMRC should be able to install with:

pip install servicemanager==1.8.3 --index "https://artefacts.tax.service.gov.uk/artifactory/api/pypi/hmrc-pips-local/simple" --extra-index- 
url=https://pypi.org/simple/

The second index is required as pip needs to resolve all of the dependencies of servicemanager, which will not be found if only looking in artefactory.

From test.pypi:

First release to artefactory as above. Then in labs build Jenkins, you can run the service-manager-pypi-release job to release the new artifact to test.pypi

Once released, anyone (not just hmrc) should be able to install with:

pip install servicemanager==1.8.3 -i https://test.pypi.org/simple/ 

NB. Once something has been uploaded to pypi, that filename is permanently reserved. i.e. you can only push a version once, this applies for test.pypi also. If you try to upload an artefact that you have already uploaded before, you will hit: 400 This filename has already been used, use a different version. See https://test.pypi.org/help/#file-name-reuse for more information. For this reason, you may want to use artefactory as a preference/initially, where the artefact can be removed and reuploaded with no issue (though you will need to ask B&D to do this).

Releasing manually via tox

This is only provided for reference. You should use the build jobs described above for releasing

Releasing is handled via tox, and using twine

First, ensure you have tox installed:

pip install tox

Then set env vars for the release repository:

export TWINE_REPOSITORY_URL=<yourrepo>
export TWINE_USERNAME=<username>
export TWINE_PASSWORD=<password>
tox -e release

N.B. for uploading to test.pypi.org and pypi.org, the username will always be __token__ and the password should be an API token that you have generated in the account

Releasing manually without tox

This is only provided for reference. You should use the build jobs described above for releasing

Create a .pypirc configuration file

This file holds your information for authenticating with PyPI

[distutils]
index-servers =
  pypi

[pypi]
repository=https://upload.pypi.org/legacy/
username=FOO
password=BAR

This is just to make your life easier, so that when it comes time to upload you don't have to type/remember your username and password. Make sure to put this file in your home folder – its path should be ~/.pypirc.

Publish a new version

  1. Change to service-manager directory
  2. Increment the build number in setup.py, commit and push the change to master
  3. Ensure virtualenv is installed (might require superuser):
    pip install virtualenv
  4. The following will, in order, delete existing virtual env, create a new virtual env and start it:
    rm -rf venv && virtualenv venv && source venv/bin/activate;

Note: The service-manager build and release process is not yet compatible with Python 3, until it is the above command must be run inside a Python 2.x environment. You might need to tailor the virtualenv command in order to ensure this (or use pyenv to set the local Python environment to a 2.x version first). If you try and build in a Python 3.x environment you will get this error: LookupError: unknown encoding: mbcs

  1. From the service-manager directory again
    python setup.py sdist upload

  2. Check the service-manager PyPi repository to ensure that the new version has been uploaded successfully.

  3. Exit the virtual env:
    deactivate