Skip to content

Commit

Permalink
Refactored release script with migration to hatch
Browse files Browse the repository at this point in the history
  • Loading branch information
nap committed Nov 12, 2023
1 parent 221e858 commit 4e0b025
Showing 1 changed file with 35 additions and 30 deletions.
65 changes: 35 additions & 30 deletions release.sh
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

0 comments on commit 4e0b025

Please sign in to comment.