Skip to content

Commit

Permalink
TER-486: script release process
Browse files Browse the repository at this point in the history
  • Loading branch information
pdecat committed Oct 27, 2021
1 parent 22671ee commit f87ff36
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 18 deletions.
33 changes: 15 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<!--TOC-->

Expand Down Expand Up @@ -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
84 changes: 84 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f87ff36

Please sign in to comment.