File size: 4,306 Bytes
b98ce8c 12cfa80 b98ce8c ad40307 b98ce8c ad40307 b98ce8c 12cfa80 85d6725 eb7e1d8 85d6725 eb7df4e b98ce8c 12cfa80 eb7df4e 12cfa80 eb7df4e 790a3cd b98ce8c 5c1400d eb7e1d8 a4eeeee eb7e1d8 a4eeeee 5c1400d 214a527 5c1400d 214a527 5c1400d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
#!/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 message, take two arguments
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)
# Require valid format for version
rx='^v[0-9]+\.[0-9]+\.[0-9]+((a|alpha|b|beta|dev|rc)[0-9]+)?$'
if ! [[ $VERSION =~ $rx ]]; then
c_echo $RED "The version must be in the format 'vX.X.X or vX.X.XaX or vX.X.XalphaX or vX.X.XbX or vX.X.XbetaX or vX.X.XdevX or vX.X.XrcX'"
exit 1
fi
# Require main branch for release
if [ "$BRANCH" != "main" ]
then
c_echo $RED "You must release on the main branch"
exit 1
fi
# make sure you have the most recent from remote main
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
# Require no untracked files
if [[ -n $(git status -s) ]]
then
c_echo $RED "Untracked files detected. Please stash or commit"
git status -s
exit 1
fi
# Require new tag/version
if [ $(git tag -l "$VERSION") ]; then
c_echo $RED "The tag/version already exists..."
echo
echo Tags:
git tag
exit 1
fi
# Require clean working tree for release
require_clean_work_tree release "Please commit or stash them and sync with remote"
# Get most recent tag
PREVIOUS_TAG=$(git describe --tags --abbrev=0)
# Build commit message for version bump
MESSAGE="Release: $VERSION
Changes:
$(git log --pretty=oneline $PREVIOUS_TAG..)
Diff:
https://github.com/hasaniqbal777/$APP_NAME/compare/$PREVIOUS_TAG...$VERSION
"
# Confirmation message
confirmation "$MESSAGE"
c_echo $GREEN "Releasing Version $VERSION"
echo
# Modify the VERSION file
printf "$VERSION" > ./VERSION
bump2version patch --new-version $VERSION_BUMP --allow-dirty --verbose
# Modify the docs version
# Regex to match development or release candidate versions
if [[ "$VERSION" =~ dev[0-9]+$ || "$VERSION" =~ a[0-9]+$ || "$VERSION" =~ alpha[0-9]+$ || "$VERSION" =~ b[0-9]+$ || "$VERSION" =~ beta[0-9]+$ || "$VERSION" =~ rc[0-9]+$ ]]; then
# It's a pre-release because it contains `dev` or `rc`
c_echo $YELLOW "Skipping docs version bump for pre-release"
else
# It's a full release
./docs/scripts/bumpversion.sh --new-version $VERSION_BUMP
fi
# Commit and tag the release
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
# Regex to match development or release candidate versions
if [[ "$VERSION" =~ dev[0-9]+$ ]]; then
# It's a development release because it contains `dev`
c_echo $YELLOW "Skipping release to GitHub for development release"
exit 0
fi
if [[ "$VERSION" =~ a[0-9]+$ || "$VERSION" =~ alpha[0-9]+$ || "$VERSION" =~ b[0-9]+$ || "$VERSION" =~ beta[0-9]+$ || "$VERSION" =~ rc[0-9]+$ ]]; then
# It's a pre-release because it contains `rc`
gh release create "$VERSION" --generate-notes --prerelease
echo "Pre-release $VERSION created."
# Also release in the organization
gh release create "$VERSION" --generate-notes --prerelease --repo "mbzuai-nlp/openfactcheck"
else
# It's a full release
gh release create "$VERSION" --generate-notes
echo "Release $VERSION created."
# Also release in the organization
gh release create "$VERSION" --generate-notes --repo "mbzuai-nlp/openfactcheck"
fi |