-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored release script with migration to hatch
- Loading branch information
Showing
1 changed file
with
35 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,50 @@ | ||
#!/bin/bash | ||
#!/usr/bin/env bash | ||
set -e -o pipefail | ||
|
||
: "${HATCH_INDEX_REPO:=main}" # or test | ||
|
||
if ! git diff-index --quiet HEAD; then | ||
echo "Can not process, there's uncommited changes." | ||
echo "Cannot proceed, there are uncommited changes." | ||
exit 1 | ||
fi | ||
|
||
if echo "$@" | grep -q -- '--version'; then | ||
VERSION=$(echo "$@" | grep -oh -- '--version=.*' | cut -d '=' -f 2 | cut -d ' ' -f 1) | ||
if [[ -z "${HATCH_INDEX_USER}" ]] || [[ -z "${HATCH_INDEX_AUTH}" ]]; then | ||
echo "Make sure environment variables HATCH_INDEX_USER and HATCH_INDEX_AUTH are set." | ||
exit 1 | ||
fi | ||
|
||
if echo "$@" | grep -q -- '--identity'; then | ||
IDENTITY=$(echo "$@" | grep -oh -- '--identity=.*' | cut -d '=' -f 2 | cut -d ' ' -f 1) | ||
if echo "$@" | grep -q -- 'help' || [[ ${#@} -lt 1 ]]; then | ||
echo "Usage: release.sh [help|major|minor|patch]" | ||
exit 0 | ||
fi | ||
[[ -z "$IDENTITY" ]] && IDENTITY=994A80D2 | ||
|
||
CURRENT_VERSION=$(sed -n "s/__version__ = '\(.*\)'/\1/p" setup.py) | ||
if [[ -z "$VERSION" ]]; then | ||
echo "Usage: $(basename $0) --version=VERSION [--identity=IDENTITY]" | ||
echo " - Current version: $CURRENT_VERSION" | ||
exit 1 | ||
if ! echo "$1" | grep -qE "major|minor|patch"; then | ||
echo "Select one of: major, minor, patch" | ||
echo "Usage: release.sh [help|major|minor|patch]" | ||
exit 1 | ||
fi | ||
|
||
DATE=$(date +%Y-%m-%d) | ||
CHANGELOG=$(mktemp -t tmp) | ||
echo "v$VERSION (${DATE})" > $CHANGELOG | ||
echo "$(git log v${CURRENT_VERSION}..HEAD --oneline | grep -Ev "bump|pypi|pep8|Merge|gitignore|release\.sh")" | while read LINE; do | ||
echo -e " $LINE" >> $CHANGELOG | ||
done | ||
cat CHANGELOG >> $CHANGELOG | ||
cat $CHANGELOG > CHANGELOG | ||
CURRENT_VERSION=$(hatch version) | ||
echo "Current version: {$CURRENT_VERSION}" | ||
|
||
sed -i '' "s/__version__ = '.*'/__version__ = '$VERSION'/" setup.py | ||
sed -i '' "s/:Version: .*/:Version: $VERSION of $DATE/" README.rst | ||
hatch version "$1" > /dev/null 2>&1 | ||
FUTURE_VERSION=$(hatch version) | ||
echo "Current version: ${FUTURE_VERSION}" | ||
|
||
git add README.rst setup.py CHANGELOG | ||
DATE=$(date +%Y-%m-%d) | ||
CHANGELOG=$(mktemp -t tmp) | ||
echo "v{$CURRENT_VERSION} (${DATE}) - $(git config --get user.name) <$(git config --get user.email)>" > "${CHANGELOG}" | ||
while read -r LINE; do | ||
echo -e " ${LINE}" >> "${CHANGELOG}" | ||
done <<< "$(git log "v${CURRENT_VERSION}..HEAD" --pretty='format:%h %s by %cn on %as' -- ':*.py')" | ||
cat ./CHANGELOG >> "${CHANGELOG}" | ||
cat "${CHANGELOG}" > ./CHANGELOG | ||
|
||
git add ./pyjarowinkler/__about__.py ./CHANGELOG | ||
git commit -m "version bump and changelog update" | ||
git push | ||
|
||
rm -Rf dist/* | ||
git tag -a v$VERSION -m "pypi version $VERSION" | ||
git push origin v$VERSION | ||
python2.7 setup.py sdist bdist_wheel --universal | ||
twine upload dist/* --sign --identity $IDENTITY | ||
|
||
hatch build | ||
# see https://hatch.pypa.io/latest/publish/#authentication | ||
# Set HATCH_INDEX_USER | ||
# Set HATCH_INDEX_AUTH | ||
hatch publish |