2020-02-05 05:34:19 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# fail on unset variables and command errors
|
|
|
|
set -eu -o pipefail # -x: is for debugging
|
|
|
|
|
2020-07-14 03:45:04 +00:00
|
|
|
DEFAULT_BRANCH="main"
|
|
|
|
|
2020-02-19 13:56:40 +00:00
|
|
|
CURRENT_BRANCH="$(git branch --show-current)"
|
2020-07-14 03:45:04 +00:00
|
|
|
if [ "${CURRENT_BRANCH}" != "${DEFAULT_BRANCH}" ]; then
|
|
|
|
echo "$0: Current branch ${CURRENT_BRANCH} is not ${DEFAULT_BRANCH}, continue? (y/n)"
|
2020-02-19 13:56:40 +00:00
|
|
|
read -r res
|
|
|
|
if [ "${res}" = "n" ]; then
|
|
|
|
echo "$0: Stop script"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
PRERELEASE_TYPE_LIST="prerelease prepatch preminor premajor"
|
2020-07-14 03:45:04 +00:00
|
|
|
if [ "${CURRENT_BRANCH}" != "${DEFAULT_BRANCH}" ]; then
|
2020-02-19 13:56:40 +00:00
|
|
|
RELEASE_TYPE_LIST="${PRERELEASE_TYPE_LIST}"
|
|
|
|
else
|
|
|
|
RELEASE_TYPE_LIST="${PRERELEASE_TYPE_LIST} patch minor major"
|
2020-02-05 05:34:19 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if command -v fzf; then
|
|
|
|
RELEASE_TYPE=$(echo "${RELEASE_TYPE_LIST}" | tr ' ' '\n' | fzf --layout=reverse)
|
|
|
|
else
|
|
|
|
select sel in ${RELEASE_TYPE_LIST}; do
|
|
|
|
RELEASE_TYPE="${sel}"
|
|
|
|
break
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$0: Create ${RELEASE_TYPE} release, continue? (y/n)"
|
|
|
|
read -r res
|
|
|
|
if [ "${res}" = "n" ]; then
|
|
|
|
echo "$0: Stop script"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
git fetch origin
|
2020-07-14 03:45:04 +00:00
|
|
|
if [ "${CURRENT_BRANCH}" != "${DEFAULT_BRANCH}" ]; then
|
2020-02-19 13:56:40 +00:00
|
|
|
git pull origin "${CURRENT_BRANCH}"
|
|
|
|
else
|
2020-07-14 03:45:04 +00:00
|
|
|
git pull origin ${DEFAULT_BRANCH}
|
2020-02-19 13:56:40 +00:00
|
|
|
git tag -d v3 || true
|
|
|
|
git pull origin --tags
|
|
|
|
fi
|
2020-02-05 05:34:19 +00:00
|
|
|
|
|
|
|
npm ci
|
|
|
|
|
|
|
|
mkdir ./lib
|
|
|
|
npm run build
|
|
|
|
git add ./lib/index.js
|
|
|
|
git commit -m "chore(release): Add build assets"
|
|
|
|
|
|
|
|
npm run release -- --release-as "${RELEASE_TYPE}" --preset eslint
|
|
|
|
|
|
|
|
git rm ./lib/index.js
|
|
|
|
rm -rf ./lib
|
|
|
|
git commit -m "chore(release): Remove build assets [skip ci]"
|
|
|
|
|
2020-07-14 03:45:04 +00:00
|
|
|
if [ "${CURRENT_BRANCH}" != "${DEFAULT_BRANCH}" ]; then
|
2020-02-19 13:56:40 +00:00
|
|
|
git push origin "${CURRENT_BRANCH}"
|
|
|
|
else
|
2020-07-14 03:45:04 +00:00
|
|
|
git push origin ${DEFAULT_BRANCH}
|
2020-02-19 13:56:40 +00:00
|
|
|
fi
|
|
|
|
|
2020-02-05 05:34:19 +00:00
|
|
|
TAG_NAME="v$(jq -r '.version' ./package.json)"
|
|
|
|
git push origin "${TAG_NAME}"
|