Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move release instructions to a script #360

Merged
merged 1 commit into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,8 @@ poetry run pytest
* release:

```
poetry version patch # or minor, major, prepatch, preminor, premajor, prerelease
export CHANGELOG_GITHUB_TOKEN=$(gopass show -o pins/Github/github-changelog-generator)
docker run -it --rm -v "$(pwd)":/usr/local/src/your-app -e CHANGELOG_GITHUB_TOKEN githubchangeloggenerator/github-changelog-generator -u venth -p aws-adfs --future-release=$(poetry version -s)
git add .
git commit -m "Release $(poetry version -s)"
git tag --annotate -m "Release $(poetry version -s)" $(poetry version -s)
git push
./script/release.sh patch # or minor, major, prepatch, preminor, premajor, prerelease, or a valid semver string
```

## Changelog
Expand Down
87 changes: 87 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash

VERSION=$1

set -euo pipefail

# Ensure Github token needed for changelog generation is set
: $CHANGELOG_GITHUB_TOKEN

set -x # TO COMMENT

request_approval_to_continue() {
echo
echo $1
echo
echo 'Continue with release? Only "yes" will be accepted to approve.'
read CONTINUE
[ "$CONTINUE" == "yes" ] || exit 0
}

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
}

# Check GNU sed
sed --version |& head -n 1 | grep "(GNU sed)" || (echo ERROR: this script requires GNU sed ; exit 1)

# 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`
docker run -it --rm -v "$(pwd)":/usr/local/src/your-app -e CHANGELOG_GITHUB_TOKEN githubchangeloggenerator/github-changelog-generator -u venth -p aws-adfs --future-release=$(poetry version -s)

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 '3,${/^## \[/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 remote GitHub repository, and trigger a Github Actions job to publish packages to PyPI"

git push origin --follow-tags
2 changes: 1 addition & 1 deletion scripts/update-readme-help.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

set -xeuo pipefail
set -euo pipefail

FILES=$*

Expand Down