|
#!/bin/bash |
|
|
|
source "${BASH_SOURCE%/*}/common.sh" |
|
|
|
. "$(git --exec-path)/git-sh-setup" |
|
|
|
if [ -z "$1" ] ; then |
|
c_echo $RED "Need to provide the version ie v0.0.0 as the first argument" |
|
exit 1 |
|
fi |
|
|
|
|
|
confirmation() |
|
{ |
|
c_echo $YELLOW " |
|
-------------------------------------------------------------------------------- |
|
-- Confirmation -- |
|
-------------------------------------------------------------------------------- |
|
" |
|
c_echo $YELLOW "You are about to release the following..." |
|
echo |
|
c_echo $YELLOW "$1" |
|
c_echo $YELLOW "Are you sure you want to continue? (Default: y)" |
|
read -r CONFIRMATION |
|
if [[ -z $CONFIRMATION ]]; then |
|
CONFIRMATION="y" |
|
fi |
|
if [[ $CONFIRMATION != "y" ]]; then |
|
c_echo $RED "Exiting..." |
|
exit 1 |
|
fi |
|
} |
|
|
|
VERSION=$1 |
|
VERSION_BUMP=${VERSION:1} |
|
BRANCH=$(git rev-parse --abbrev-ref HEAD) |
|
|
|
|
|
rx='^v[0-9]+\.[0-9]+\.[0-9]+(-(dev|rc)[0-9]+)?$' |
|
if ! [[ $VERSION =~ $rx ]]; then |
|
c_echo $RED "The version must be in the format 'vX.X.X'" |
|
exit 1 |
|
fi |
|
|
|
|
|
if [ "$BRANCH" != "main" ] |
|
then |
|
c_echo $RED "You must release on the main branch" |
|
exit 1 |
|
fi |
|
|
|
|
|
git fetch |
|
git pull origin main |
|
|
|
if [ x"$(git rev-parse $BRANCH)" != x"$(git rev-parse origin/$BRANCH)" ] |
|
then |
|
c_echo $RED "Out of sync with remote" |
|
git status |
|
exit 1 |
|
fi |
|
|
|
|
|
if [[ -n $(git status -s) ]] |
|
then |
|
c_echo $RED "Untracked files detected. Please stash or commit" |
|
git status -s |
|
exit 1 |
|
fi |
|
|
|
|
|
if [ $(git tag -l "$VERSION") ]; then |
|
c_echo $RED "The tag/version already exists..." |
|
echo |
|
echo Tags: |
|
git tag |
|
exit 1 |
|
fi |
|
|
|
|
|
require_clean_work_tree release "Please commit or stash them and sync with remote" |
|
|
|
|
|
PREVIOUS_TAG=$(git describe --tags --abbrev=0) |
|
|
|
|
|
MESSAGE="Release: $VERSION |
|
|
|
Changes: |
|
|
|
$(git log --pretty=oneline $PREVIOUS_TAG..) |
|
|
|
Diff: |
|
|
|
https://github.com/hasaniqbal777/$APP_NAME/compare/$PREVIOUS_TAG...$VERSION |
|
" |
|
|
|
|
|
confirmation "$MESSAGE" |
|
|
|
c_echo $GREEN "Releasing Version $VERSION" |
|
echo |
|
|
|
|
|
printf "$VERSION" > ./VERSION |
|
bump2version patch --new-version $VERSION_BUMP --allow-dirty --verbose |
|
|
|
|
|
|
|
if [[ "$VERSION" =~ -dev[0-9]+$ || "$VERSION" =~ -rc[0-9]+$ ]]; then |
|
|
|
c_echo $YELLOW "Skipping docs version bump for pre-release" |
|
else |
|
|
|
./docs/scripts/bumpversion.sh --new-version $VERSION_BUMP |
|
fi |
|
|
|
|
|
|
|
git add ./VERSION |
|
git add ./.bumpversion.cfg |
|
git add ./pyproject.toml |
|
git add ./pre-requirements.txt |
|
git add ./src/openfactcheck/__init__.py |
|
git add ./docs/src/_static/versions.json |
|
git commit -m "🚀 $MESSAGE" |
|
git tag $VERSION |
|
git push origin $BRANCH |
|
git push origin $VERSION |
|
|
|
|
|
if [[ "$VERSION" =~ -dev[0-9]+$ ]]; then |
|
|
|
c_echo $YELLOW "Skipping release to GitHub for development release" |
|
exit 0 |
|
fi |
|
if [[ "$VERSION" =~ -rc[0-9]+$ ]]; then |
|
|
|
gh release create "$VERSION" --generate-notes --prerelease |
|
echo "Pre-release $VERSION created." |
|
else |
|
|
|
gh release create "$VERSION" --generate-notes |
|
echo "Release $VERSION created." |
|
fi |