2017-08-22 13:32:41 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Unoffical Bash "strict mode"
|
|
|
|
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
|
|
|
|
set -euo pipefail
|
|
|
|
#ORIGINAL_IFS=$IFS
|
|
|
|
IFS=$'\t\n' # Stricter IFS settings
|
|
|
|
|
2017-10-01 06:18:38 -07:00
|
|
|
# shellcheck disable=SC2006
|
2017-08-22 13:32:41 -07:00
|
|
|
usage() {
|
|
|
|
cat <<EOF
|
|
|
|
|
|
|
|
Usage: release.sh [new version]
|
|
|
|
|
|
|
|
This script is only intended for use by asdf maintainers when releasing new
|
|
|
|
versions of asdf. Plugin developers and asdf users do not need this script.
|
|
|
|
|
|
|
|
This script updates the hardcoded versions in the source code and README and
|
|
|
|
then commits them on the current branch. It then tags that commit with the
|
|
|
|
specified version.
|
|
|
|
|
2017-09-12 15:40:31 -07:00
|
|
|
If you run this script in error, or with the wrong version, you can undo the
|
|
|
|
changes by finding the original state in the list of actions listed in the
|
|
|
|
reflog:
|
|
|
|
|
|
|
|
git reflog
|
|
|
|
|
|
|
|
Then revert to the original state by running `git checkout` with the reference
|
|
|
|
previous to the release tagging changes:
|
|
|
|
|
|
|
|
git checkout HEAD@{21}
|
|
|
|
|
|
|
|
Then checkout the original branch again:
|
|
|
|
|
|
|
|
git checkout master
|
|
|
|
|
|
|
|
You are back to the original state!
|
|
|
|
|
2017-08-22 13:32:41 -07:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
error_exit() {
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
new_version="${1:-}"
|
|
|
|
new_tag_name="v$new_version"
|
|
|
|
|
|
|
|
# Make sure the user provides a version
|
|
|
|
if [[ -z "$new_version" ]]
|
|
|
|
then
|
|
|
|
echo "ERROR: no new version specified"
|
|
|
|
error_exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Make sure version passed in is a plain semantic version to guard against
|
|
|
|
# leading 'v'.
|
|
|
|
if ! [[ "${new_version:0:1}" =~ ^[0-9]+$ ]]; then
|
|
|
|
echo >&2 "ERROR: semantic version should not start with a letter"
|
|
|
|
error_exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Make sure the version the user provided hasn't already been tagged
|
|
|
|
if git tag | grep "$new_tag_name" > /dev/null; then
|
|
|
|
echo >&2 "ERROR: git tag with that version already exists"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-12-26 08:51:05 -07:00
|
|
|
# Make sure the changelog already contains details on the new version
|
2017-12-26 08:56:57 -07:00
|
|
|
if ! grep "$new_version$" CHANGELOG.md; then
|
2017-12-26 08:51:05 -07:00
|
|
|
echo >&2 "ERROR: changelog entry for this version is missing"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-03-12 12:45:02 -07:00
|
|
|
# Make sure the changelog doesn't contain duplicate issue numbers
|
|
|
|
nonunique_issue_numbers=$(grep -o -P '#[\d]+' CHANGELOG.md | sort)
|
|
|
|
unique_issue_numbers=$(grep -o -P '#[\d]+' CHANGELOG.md | sort -u)
|
|
|
|
if [ "$nonunique_issue_numbers" != "$unique_issue_numbers" ]; then
|
|
|
|
echo >&2 "ERROR: Duplicate issue numbers in changelog."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-08-22 13:32:41 -07:00
|
|
|
echo "INFO: Checking that all changes are commited and pushed"
|
|
|
|
git pull
|
|
|
|
|
|
|
|
# Disallow unstaged changes in the working tree
|
|
|
|
if ! git diff-files --check --exit-code --ignore-submodules -- >&2; then
|
|
|
|
echo >&2 "ERROR: You have unstaged changes."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Disallow uncommitted changes in the index
|
|
|
|
if ! git diff-index --cached --exit-code -r --ignore-submodules HEAD -- >&2; then
|
|
|
|
echo >&2 "ERROR: Your index contains uncommitted changes."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Update version in README
|
2017-12-26 10:16:25 -07:00
|
|
|
sed -i.bak "s|^\\(git clone.*--branch \\).*$|\\1$new_tag_name|" README.md
|
2017-12-26 09:04:22 -07:00
|
|
|
rm README.md.bak
|
2017-08-22 13:32:41 -07:00
|
|
|
|
2019-01-12 09:32:30 -07:00
|
|
|
# Update version in docs/core-manage-asdf-vm.md
|
|
|
|
sed -i.bak "s|^\\(git clone.*--branch \\).*$|\\1$new_tag_name|" docs/core-manage-asdf-vm.md
|
|
|
|
rm docs/core-manage-asdf-vm.md.bak
|
|
|
|
|
2017-09-12 15:42:19 -07:00
|
|
|
# Update version in the VERSION file
|
2017-09-12 15:21:04 -07:00
|
|
|
echo "$new_tag_name" > VERSION
|
2017-08-22 13:32:41 -07:00
|
|
|
|
2017-08-22 13:38:14 -07:00
|
|
|
echo "INFO: Committing and tagging new version"
|
|
|
|
|
2017-08-22 13:32:41 -07:00
|
|
|
# Commit the changed files before tagging the new release
|
|
|
|
git add README.md
|
2019-01-19 07:29:55 -07:00
|
|
|
git add docs/core-manage-asdf-vm.md
|
2017-09-12 15:42:19 -07:00
|
|
|
git add VERSION
|
2017-08-22 13:32:41 -07:00
|
|
|
git commit -m "Update version to $new_version"
|
|
|
|
|
2017-08-22 13:38:14 -07:00
|
|
|
git tag -a "$new_tag_name" -m "Version ${new_version}"
|
2017-08-22 13:32:41 -07:00
|
|
|
|
|
|
|
echo "INFO: done."
|
2018-03-11 12:14:22 -07:00
|
|
|
echo "INFO: Now you can push this local branch to the GitHub repository: \`git push <remote> master $new_tag_name\`"
|