From f87ff36be4f7bf5f20abeb184f00d35944934d86 Mon Sep 17 00:00:00 2001 From: Patrick Decat Date: Tue, 26 Oct 2021 14:56:22 +0200 Subject: [PATCH] TER-486: script release process --- README.md | 33 +++++++++--------- scripts/release.sh | 84 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 18 deletions(-) create mode 100755 scripts/release.sh diff --git a/README.md b/README.md index 118a36d4..5f9ec953 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ - [README TOC](#readme-toc) - [Using terraform development builds](#using-terraform-development-builds) - [git pre-commit hooks](#git-pre-commit-hooks) - - [Publishing new releases to PyPI](#publishing-new-releases-to-pypi) + - [Tagging and publishing new releases to PyPI](#tagging-and-publishing-new-releases-to-pypi) @@ -666,31 +666,28 @@ If updating hooks configuration, run checks against all files to make sure every Note: the `pre-commit` tool itself can be installed with `pip` or `pipx`. -## Publishing new releases to PyPI +## Tagging and publishing new releases to PyPI -Bump the version with poetry: +Use the `scripts/release.sh` script from `master` branch to: -```bash -# poetry version [patch|minor|major|prepatch|preminor|premajor|prerelease] -``` - -Commit, tag and push this change to Github, then publish the release to test.pypi.org for validation: +- bump the version with poetry, +- update `CHANGELOG.md`, +- commit these changes, +- tag with last CHANGELOG.md item content as annotation, +- bump the version with poetry again to mark it for development, +- commit this change, +- push all commits and tags to all remote repositories. -```bash -# poetry config repositories.testpypi https://test.pypi.org/legacy/ -# poetry publish --build --repository testpypi -``` +This will trigger a Github Actions job to publish packages to PyPI. -If all is ok, publish to pypi.org: +To invoke the script, pass it the desired bump rule, e.g.: ```bash -# poetry publish --build +# ./scripts/release.sh minor ``` -Bump the version with poetry again in master to mark it for development: +For more options, check the help: ```bash -# poetry version prerelease +# ./scripts/release.sh --help ``` - -TODO: automate this process with Github Actions diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 00000000..b0470e09 --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +# set -x # TO REMOVE + +VERSION=$1 + +set -euo pipefail + +request_approval_to_continue() { + echo + echo $1 + echo + echo 'Continue with release? Only "yes" will be accepted to approve.' + read CONTINUE + [ "$CONTINUE" == "yes" ] || exit 1 +} + +show_help () { + echo Usage: $0 VERSION + echo + echo VERSION should ideally be a valid semver string or a valid bump rule: patch, minor, major, prepatch, preminor, premajor, prerelease. + exit 0 +} + +show_git_diff_staged() { + echo + echo Current staged diff: + echo + git diff --staged +} + +# Show help if needed +([ "$VERSION" == "-h" ] || [ "$VERSION" == "--help" ] || [ "$VERSION" == "" ]) && show_help + +# Ensure we are on master branch (we do not backport fixes for older major versions yet) +[ "$(git rev-parse --abbrev-ref HEAD)" == "master" ] || (echo ERROR: not on "master" branch, aborting. && exit 1) + +# Ensure pyproject.toml and CHANGELOG.md do not have unstaged modifications +git diff --exit-code CHANGELOG.md &> /dev/null || (echo ERROR: CHANGELOG.md file has unstaged changes, aborting. && exit 1) +git diff --exit-code pyproject.toml &> /dev/null || (echo ERROR: pyproject.toml file has unstaged changes, aborting. && exit 1) + +# Bump the version with poetry and re-read it +poetry version $VERSION +VERSION=$(poetry version --short) + +request_approval_to_continue "New version will be: $VERSION" + +# Update `CHANGELOG.md` (TODO: generate it from JIRA issue ids?) +sed -i "1 i\# ${VERSION} ($(date +'%Y/%m/%d'))\n\n" CHANGELOG.md +vi CHANGELOG.md +CHANGELOG=$(sed '2,${/^#/Q}' CHANGELOG.md) + +git add pyproject.toml CHANGELOG.md +show_git_diff_staged + +request_approval_to_continue "Ready to commit" + +# Commit these changes +git commit -m "Release v$VERSION" + +request_approval_to_continue "Ready to create annotated tag" + +# Tag with last CHANGELOG.md item content as annotation +sed '2,${/^#/Q}' CHANGELOG.md | git tag -a -F- v$VERSION + +# Bump the version with poetry again to mark it for development +echo +echo Bump the version with poetry again to mark it for development +echo +poetry version prerelease +VERSION=$(poetry version --short) + +git add pyproject.toml +show_git_diff_staged + +request_approval_to_continue "Ready to commit" + +# Commit this changes +git commit -m "Develop v$VERSION" + +request_approval_to_continue "Ready to push to all remote repositories. On GitHub, this will trigger a Github Actions job to publish packages to PyPI" + +# FIXME: uncomment when ready +# for remote in $(git remote); do git push $remote --follow-tags ; done