diff --git a/_test/bump_version.py b/_test/bump_version.py new file mode 100644 index 000000000..a4cf5fb2c --- /dev/null +++ b/_test/bump_version.py @@ -0,0 +1,36 @@ +#!/usr/bin/python3 +import getopt +import semver +import sys +import yaml + + +def bump_patch(chart_path): + chart_dot_yaml = "%s/Chart.yaml" % chart_path + chart_file = open(chart_dot_yaml) + + chart = yaml.load(chart_file, Loader=yaml.FullLoader) + + version = semver.VersionInfo.parse(chart['version']) + + print(str(version.bump_patch())) + + +def main(argv): + try: + opts, args = getopt.getopt(argv, "i:", ["increment="]) + except getopt.GetoptError: + print("bad options") + sys.exit(2) + for opt, arg in opts: + if opt in ("-i", "-increment"): + bump_patch(arg) + sys.exit() + + +if __name__ == "__main__": + main(sys.argv[1:]) +pelorus_chart = "charts/pelorus" +operator_chart = "charts/operators" + +bump_patch(pelorus_chart) diff --git a/_test/pre-commit b/_test/pre-commit index d778dab67..9ed1ed558 100755 --- a/_test/pre-commit +++ b/_test/pre-commit @@ -1,3 +1,34 @@ #!/bin/bash -ct lint +bump_version() { + chart=${1} + version=$(python _test/bump_version.py -i ${chart}) + sed -i "s/version:\ .*$/version:\ ${version}/" ${chart}/Chart.yaml + echo "Updated chart ${chart} version to ${version}." +} + +set_app_version() { + version=$(vert -g ^1 $(git describe)) + sed -i "s/appVersion:\ .*$/appVersion:\ ${version}/" charts/pelorus/Chart.yaml +} + +chart_lint=$(ct lint --remote upstream 2>&1) +failed=$? +failed_charts=$(echo "${chart_lint}" | sed -n 's/.*\(path:\ \"\)\(.*\)\".*Chart\ version.*$/\2/p') + +if [ ${failed} -ne 0 ] && [ "${failed_charts}" != "" ]; then + for chart in ${failed_charts}; do + bump_version ${chart} + done + # Recursively call script to ensure tests pass now + ./$0 + + # Ensure app version is correct + set_app_version + if [ "$(git diff charts/pelorus/Chart.yaml)" != "" ]; then + echo "Updated charts/pelorus appVersion to $(git describe)." + fi + + echo "Please re-commit." + exit 1 +fi diff --git a/charts/pelorus/Chart.yaml b/charts/pelorus/Chart.yaml index 88c3def7d..8a22af3de 100644 --- a/charts/pelorus/Chart.yaml +++ b/charts/pelorus/Chart.yaml @@ -14,8 +14,8 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. -version: 1.2.2 +version: 1.2.3 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. -appVersion: 1.2.1+20.gb9cac53 +appVersion: 1.2.1+19.gd313016 diff --git a/docs/Development.md b/docs/Development.md index d755b94ec..588ff7785 100644 --- a/docs/Development.md +++ b/docs/Development.md @@ -36,17 +36,17 @@ We use Helm's [chart-testing](https://github.com/helm/chart-testing) tool to ens ### Updating the chart versions -When any of our Helm charts are updated, we need to bump the version number. This allows for a seemless upgrade experience. In order to maintain versioning with our repository, our version numbers are derived from our tagged releases. Git provides a command which will give us that version, via `git describe`. However, the [git generated version number is not fully semver compatible](https://github.com/semver/semver/issues/200). To bridge that gap we use a tool called [Version Tester (vert)](https://github.com/Masterminds/vert). Here are the steps to generate the version: +When any of our Helm charts are updated, we need to bump the version number. This allows for a seemless upgrade experience. In order to maintain versioning with our repository, our version numbers are derived from our tagged releases. Git provides a command which will give us that version, via `git describe`. However, the [git generated version number is not fully semver compatible](https://github.com/semver/semver/issues/200). To bridge that gap we use a tool called [Version Tester (vert)](https://github.com/Masterminds/vert). We have also written a pre-commit hook script that will automatically detect when a version bump is needed and will make the required change. Here are the steps to get the hook set up. +1. Install Helm's [chart-testing](https://github.com/helm/chart-testing) tool. 1. Install the latest release of [vert](https://github.com/Masterminds/vert/releases/) -2. Run `vert -g ^1 $(git describe)`. -3. Insert the version into the `version` field of your `Chart.yaml` file. - -Before committing, you can run `ct lint` to confirm the version bump worked. Or, you can automate this process by adding our pre-commit script to your local git hooks. + 1. Run `vert -g ^1 $(git describe)` to test that its working. +1. Copy the pre-commit hook into your git hooks directory. + ``` + cp _test/pre-commit .git/hooks/pre-commit + ``` -``` -cp _test/pre-commit .git/hooks/pre-commit -``` +This script will use Helm's built-in linter to check whether a version bump is necessary, and if it is, it will take the current `version` from Chart.yaml and increment it one patch version. It will also keep `appVersion` fo the Pelorus chart up to date with the repo version using `git describe`. ## Dashboard Development diff --git a/exporters/requirements-dev.txt b/exporters/requirements-dev.txt index fea764c82..1f35340cc 100644 --- a/exporters/requirements-dev.txt +++ b/exporters/requirements-dev.txt @@ -1,2 +1,3 @@ pytest -coverage \ No newline at end of file +coverage +semver \ No newline at end of file