/ release.sh
release.sh
1 #!/usr/bin/env bash 2 3 # fail on unset variables and command errors 4 set -eu -o pipefail # -x: is for debugging 5 6 DEFAULT_BRANCH="main" 7 8 CURRENT_BRANCH="$(git branch --show-current)" 9 if [ "${CURRENT_BRANCH}" != "${DEFAULT_BRANCH}" ]; then 10 echo "$0: Current branch ${CURRENT_BRANCH} is not ${DEFAULT_BRANCH}, continue? (y/n)" 11 read -r res 12 if [ "${res}" = "n" ]; then 13 echo "$0: Stop script" 14 exit 0 15 fi 16 fi 17 18 PRERELEASE_TYPE_LIST="prerelease prepatch preminor premajor" 19 if [ "${CURRENT_BRANCH}" != "${DEFAULT_BRANCH}" ]; then 20 RELEASE_TYPE_LIST="${PRERELEASE_TYPE_LIST}" 21 else 22 RELEASE_TYPE_LIST="${PRERELEASE_TYPE_LIST} patch minor major" 23 fi 24 25 if command -v fzf; then 26 RELEASE_TYPE=$(echo "${RELEASE_TYPE_LIST}" | tr ' ' '\n' | fzf --layout=reverse) 27 else 28 select sel in ${RELEASE_TYPE_LIST}; do 29 RELEASE_TYPE="${sel}" 30 break 31 done 32 fi 33 34 echo "$0: Create ${RELEASE_TYPE} release, continue? (y/n)" 35 read -r res 36 if [ "${res}" = "n" ]; then 37 echo "$0: Stop script" 38 exit 0 39 fi 40 41 git fetch origin 42 if [ "${CURRENT_BRANCH}" != "${DEFAULT_BRANCH}" ]; then 43 git pull origin "${CURRENT_BRANCH}" 44 else 45 git pull origin ${DEFAULT_BRANCH} 46 git tag -d v3 || true 47 git pull origin --tags 48 fi 49 50 npm ci 51 52 mkdir ./lib 53 npm run build 54 git add ./lib/index.js 55 git commit -m "chore(release): Add build assets" 56 57 npm run release -- --release-as "${RELEASE_TYPE}" --preset eslint 58 59 git rm ./lib/index.js 60 rm -rf ./lib 61 git commit -m "chore(release): Remove build assets [skip ci]" 62 63 if [ "${CURRENT_BRANCH}" != "${DEFAULT_BRANCH}" ]; then 64 git push origin "${CURRENT_BRANCH}" 65 else 66 git push origin ${DEFAULT_BRANCH} 67 fi 68 69 TAG_NAME="v$(jq -r '.version' ./package.json)" 70 git push origin "${TAG_NAME}"