Skip to main content
Module

x/value_schema/create-release-branch

simple, easy-to-use, and declarative input validator; supports Node.js, TypeScript, and Deno
Go to Latest
File
#!/bin/bash# requires following packages:# - git; I believe you have already installed.# - sed; GNU sed is preferred. POSIX sed may not work.
BASE_BRANCH="develop"
URL_PRODUCT="https://github.com/shimataro/node-adjuster"URL_RELEASE="${URL_PRODUCT}/releases"
COLOR_ERROR="\e[1;41m"COLOR_SECTION="\e[1;34m"COLOR_COMMAND_NAME="\e[1;34m"COLOR_OPTION="\e[4;36m"COLOR_COMMAND="\e[4m"COLOR_FILE="\e[1;34m"COLOR_BRANCH="\e[1;31m"COLOR_INPUT="\e[1;31m"COLOR_SELECT="\e[1;32m"COLOR_RESET="\e[m"
function main() { cd `dirname ${0}`
if [ $# -lt 1 ]; then usage ${0} fi
local VERSION=$1 local BRANCH="feature-v${VERSION}" local TAG="v${VERSION}"
check_version_format ${VERSION} check_current_branch
run create_branch ${BRANCH} run update_changelog ${VERSION} run update_package_version ${VERSION} run update_dependencies_version run regenerate_npm_shrinkwrap run verify_package run commit_changes ${VERSION} run finish ${VERSION} ${BRANCH} ${TAG}}
function usage() { local COMMAND=`basename ${1}`
echo -e "${COLOR_SECTION}NAME${COLOR_RESET} ${COMMAND} - Prepare for new release
${COLOR_SECTION}SYNOPSIS${COLOR_RESET} ${COLOR_COMMAND_NAME}${COMMAND}${COLOR_RESET} <${COLOR_OPTION}new-version${COLOR_RESET}>
${COLOR_SECTION}DESCRIPTION${COLOR_RESET} This command will... - create a new branch for release - update ${COLOR_FILE}CHANGELOG.md${COLOR_RESET} - update package version in ${COLOR_FILE}package.json${COLOR_RESET} - update dependencies version in ${COLOR_FILE}package.json${COLOR_RESET} - verify - ...and commit!
${COLOR_OPTION}new-version${COLOR_RESET} must follow \"Symantec Versioning\" <https://semver.org/>." exit 1}
function check_version_format() { if [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then return fi
echo -e "${COLOR_ERROR}ERROR:${COLOR_RESET} Follow \"Semantic Versioning\" for new version: https://semver.org/" >&2 exit 2}
function check_current_branch() { local CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD` if [ ${CURRENT_BRANCH} = ${BASE_BRANCH} ]; then return fi
echo -e "${COLOR_ERROR}ERROR:${COLOR_RESET} Work on ${COLOR_BRANCH}${BASE_BRANCH}${COLOR_RESET} branch ${COLOR_COMMAND}git checkout ${BASE_BRANCH}${COLOR_RESET}" >&2 exit 2}
function run() { "$@" || exit 1}
function create_branch() { local BRANCH=$1
git checkout -b ${BRANCH} ${BASE_BRANCH}}
function update_changelog() { local VERSION=$1 local DATE=`date "+%Y-%m-%d"` local KEYWORD="Unreleased"
sed -i".bak" -r \ -e "s/^((##\s+)\[${KEYWORD}\])$/\1\n\n\2[${VERSION}] - ${DATE}/" \ -e "s/^(\[${KEYWORD}\](.*))(v.*)\.\.\.HEAD$/\1v${VERSION}...HEAD\n[${VERSION}]\2\3...v${VERSION}/" \ CHANGELOG.md}
function update_package_version() { local VERSION=$1
sed -i".bak" -r \ -e "s/(\"version\"\s*:\s*)\".*?\"/\1\"${VERSION}\"/" \ package.json}
function update_dependencies_version() { npm run check-updates -- -u}
function regenerate_npm_shrinkwrap() { rm -rf npm-shrinkwrap.json node_modules && npm install && npm shrinkwrap}
function verify_package() { npm test && npm run lint}
function commit_changes() { local VERSION=$1
git add CHANGELOG.md package.json npm-shrinkwrap.json && git commit -m "version ${VERSION}"}
function finish() { local VERSION=$1 local BRANCH=$2 local TAG=$3
echo -e "Branch ${COLOR_BRANCH}${BRANCH}${COLOR_RESET} has been created.Remaining processes are...
1. Make sure all changes are correct ${COLOR_COMMAND}git diff ${BASE_BRANCH} ${BRANCH}${COLOR_RESET}2. Push to remote origin ${COLOR_COMMAND}git push --set-upstream origin ${BRANCH}${COLOR_RESET}3. Visit ${URL_PRODUCT}4. Create a pull-request: ${COLOR_BRANCH}${BRANCH}${COLOR_RESET} to ${COLOR_BRANCH}${BASE_BRANCH}${COLOR_RESET} select ${COLOR_SELECT}Squash and merge${COLOR_RESET}5. Create a pull-request: ${COLOR_BRANCH}${BASE_BRANCH}${COLOR_RESET} to ${COLOR_BRANCH}master${COLOR_RESET} select ${COLOR_SELECT}Create a merge commit${COLOR_RESET}6. Create release: ${URL_RELEASE} Tag version: ${COLOR_INPUT}${TAG}${COLOR_RESET} Target: ${COLOR_INPUT}master${COLOR_RESET} Release title: ${COLOR_INPUT}node-adjuster ${VERSION} released${COLOR_RESET} Description this release: (see CHANGELOG.md)7. Publish! ${COLOR_COMMAND}git checkout master${COLOR_RESET} ${COLOR_COMMAND}git pull${COLOR_RESET} ${COLOR_COMMAND}npm publish --access=public${COLOR_RESET}8. Post processing ${COLOR_COMMAND}git checkout ${BASE_BRANCH}${COLOR_RESET} ${COLOR_COMMAND}git pull${COLOR_RESET}
That's all!"}
main "$@"