4. Development

This page covers the relevant aspects for developers.

4.1. Repository

The Git repository for the exporter project is GitHub: https://github.com/zhmcclient/zhmc-prometheus-exporter

4.2. Code of Conduct

Contribution must follow the Code of Conduct as defined by the Contributor Covenant.

4.3. Contributing

Third party contributions to this project are welcome!

In order to contribute, create a Git pull request, considering this:

  • Test is required.
  • Each commit should only contain one “logical” change.
  • A “logical” change should be put into one commit, and not split over multiple commits.
  • Large new features should be split into stages.
  • The commit message should not only summarize what you have done, but explain why the change is useful.
  • The commit message must follow the format explained below.

What comprises a “logical” change is subject to sound judgement. Sometimes, it makes sense to produce a set of commits for a feature (even if not large). For example, a first commit may introduce a (presumably) compatible API change without exploitation of that feature. With only this commit applied, it should be demonstrable that everything is still working as before. The next commit may be the exploitation of the feature in other components.

For further discussion of good and bad practices regarding commits, see:

4.4. Format of commit messages

A commit message must start with a short summary line, followed by a blank line.

Optionally, the summary line may start with an identifier that helps identifying the type of change or the component that is affected, followed by a colon.

It can include a more detailed description after the summary line. This is where you explain why the change was done, and summarize what was done.

It must end with the DCO (Developer Certificate of Origin) sign-off line in the format shown in the example below, using your name and a valid email address of yours. The DCO sign-off line certifies that you followed the rules stated in DCO 1.1. In short, you certify that you wrote the patch or otherwise have the right to pass it on as an open-source patch.

We use GitCop during creation of a pull request to check whether the commit messages in the pull request comply to this format. If the commit messages do not comply, GitCop will add a comment to the pull request with a description of what was wrong.

Example commit message:

cookies: Add support for delivering cookies

Cookies are important for many people. This change adds a pluggable API for
delivering cookies to the user, and provides a default implementation.

Signed-off-by: Random J Developer <random@developer.org>

Use git commit --amend to edit the commit message, if you need to.

Use the --signoff (-s) option of git commit to append a sign-off line to the commit message with your name and email as known by Git.

If you like filling out the commit message in an editor instead of using the -m option of git commit, you can automate the presence of the sign-off line by using a commit template file:

  • Create a file outside of the repo (say, ~/.git-signoff.template) that contains, for example:

    <one-line subject>
    
    <detailed description>
    
    Signed-off-by: Random J Developer <random@developer.org>
    
  • Configure Git to use that file as a commit template for your repo:

    git config commit.template ~/.git-signoff.template
    

4.5. Releasing a version

This section shows the steps for releasing a version to PyPI.

Switch to your work directory of the zhmc-prometheus-exporter Git repo (this is where the Makefile is), and perform the following steps in that directory:

  1. Set a shell variable for the version to be released, e.g.:

    MNU='0.11.0'
    
  2. Verify that your working directory is in a Git-wise clean state:

    git status
    
  3. Check out the master branch, and update it from upstream:

    git checkout master
    git pull
    
  4. Create a topic branch for the release, based upon the master branch:

    git checkout -b release_$MNU
    
  5. Edit the version file and set the version to be released:

    vi zhmc_prometheus_exporter/_version.py
    

    __version__ = 'M.N.U'

    Where M.N.U is the version to be released.

  6. Edit the change log and perform the following changes in the top-most section (that is the section for the version to be released):

    vi docs/changes.rst
    
    • If needed, change the version in the section heading to the version to be released, e.g.:

      Version 0.11.0
      ^^^^^^^^^^^^^^
      
    • Change the release date to today’s date, e.g.:

      Released: 2018-08-20
      
    • Make sure that the change log entries reflect all changes since the previous version, and make sure they are relevant for and understandable by users.

    • In the “Known issues” list item, remove the link to the issue tracker and add any known issues you want users to know about. Just linking to the issue tracker quickly becomes incorrect for released versions:

      **Known issues:**
      
      * ...
      
    • Remove all empty list items in the change log section for this release.

  7. Commit your changes and push them upstream:

    git add zhmc_prometheus_exporter/_version.py docs/changes.rst
    git commit -sm "Release $MNU"
    git push --set-upstream origin release_$MNU
    
  8. On GitHub, create a pull request for branch release_$MNU.

  9. Perform a complete test:

    make test
    

    This should not fail because the same tests have already been run in the Travis CI. However, run it for additional safety before the release.

    If this test fails, fix any issues until the test succeeds.

  10. Once the CI tests on GitHub are complete, merge the pull request.

  11. Update your local master branch:

    git checkout master
    git pull
    
  12. Tag the master branch with the release label and push the tag upstream:

    git tag $MNU
    git push --tags
    
  13. On GitHub, edit the new tag, and create a release description on it. This will cause it to appear in the Release tab.

    You can see the tags in GitHub via Code -> Releases -> Tags.

  14. Upload the package to PyPI:

    make upload
    

    This will show the package version and will ask for confirmation.

    Attention! This only works once for each version. You cannot release the same version twice to PyPI.

  15. Verify that the released version is shown on PyPI.

  16. On GitHub, close milestone M.N.U.

4.6. Starting a new version

This section shows the steps for starting development of a new version.

Switch to your work directory of the zhmc-prometheus-exporter Git repo (this is where the Makefile is), and perform the following steps in that directory:

  1. Set a shell variable for the version to be started, e.g.:

    MNU='0.11.1'
    
  2. Check out the branch the new version is based on, make sure it is up to date with upstream, and create a topic branch for the new version:

    git checkout master
    git pull
    git checkout -b start_$MNU
    
  3. Edit the version file and set the version to the new version and to development:

    vi zhmc_prometheus_exporter/_version.py
    

    __version__ = 'M.N.U.dev1'

    Where M.N.U is the version to be started.

  4. Edit the change log:

    vi docs/changes.rst
    

    and insert the following section before the top-most section:

    Version 0.20.0
    ^^^^^^^^^^^^^^
    
    Released: not yet
    
    **Incompatible changes:**
    
    **Deprecations:**
    
    **Bug fixes:**
    
    **Enhancements:**
    
    **Cleanup:**
    
    **Known issues:**
    
    * See `list of open issues`_.
    
    .. _`list of open issues`: https://github.com/zhmcclient/zhmc-prometheus-exporter/issues
    
  5. Commit your changes and push them upstream:

    git add zhmc_prometheus_exporter/_version.py docs/changes.rst
    git commit -sm "Start $MNU"
    git push --set-upstream origin start_$MNU
    
  6. On GitHub, create a Pull Request for branch start_M.N.U.

  7. On GitHub, create a milestone for the new version M.N.U.

    You can create a milestone in GitHub via Issues -> Milestones -> New Milestone.

  8. On GitHub, go through all open issues and pull requests that still have milestones for previous releases set, and either set them to the new milestone, or to have no milestone.

  9. On GitHub, once the checks for this Pull Request succeed:

    • Merge the Pull Request (no review is needed)
    • Delete the branch of the Pull Request (start_M.N.U)
  10. Checkout the branch the new version is based on, update it from upstream, and delete the local topic branch you created:

    git checkout master
    git pull
    git branch -d start_$MNU
    

4.7. Building the distribution archives

You can build a binary (wheel) distribution archive and a source distribution archive (a more minimal version of the repository) with:

$ make build

You will find the files zhmc_prometheus_exporter-VERSION_NUMBER-py2.py3-none-any.whl and zhmc_prometheus_exporter-VERSION_NUMBER.tar.gz in the dist folder, the former being the binary and the latter being the source distribution archive.

The binary distribution archive could be installed with:

$ pip install zhmc_prometheus_exporter-VERSION_NUMBER-py2.py3-none-any.whl

The source distribution archive could be installed with:

$ tar -xfz zhmc_prometheus_exporter-VERSION_NUMBER.tar.gz
$ pip install zhmc_prometheus_exporter-VERSION_NUMBER

4.8. Building the documentation

You can build the HTML documentation with:

$ make builddoc

The root file for the built documentation will be build_docs/index.html.

4.9. Testing

You can perform unit tests with:

$ make test

You can perform a flake8 check with:

$ make check

You can perform a pylint check with:

$ make pylint