|
| 1 | +#!/bin/bash |
| 2 | +# ---------------------------------------------------------------------------------------------------------------------- |
| 3 | +# This script is intended to automate release process. |
| 4 | +# Explanation: This script will pull all latest changes from master and develop and checkout release branch from develop |
| 5 | +# with specified version and then bump up package version and add CHANGELOGS (input required) and commit them. After |
| 6 | +# that merge release branch into master and develop with appropriate tags. |
| 7 | +# |
| 8 | +# Example: "npm run release 1.2.3" |
| 9 | +# ---------------------------------------------------------------------------------------------------------------------- |
| 10 | + |
| 11 | +# Stop on first error |
| 12 | +set -e; |
| 13 | + |
| 14 | +# Ensure that the provided version is in valid semver format |
| 15 | +if [[ ! $1 =~ ^v?[0-9]+(\.[0-9]+){2}(-[a-z]+\.\d+)?$ ]]; then |
| 16 | + echo "A valid version must be provided as the first argument."; |
| 17 | + exit 1; |
| 18 | +fi |
| 19 | + |
| 20 | +ver=${1/v/}; # Strip the leading v from the version (if it exists) |
| 21 | +msg=$2; |
| 22 | + |
| 23 | +[[ -z $msg ]] && msg="Released v${ver}"; |
| 24 | + |
| 25 | +# Update the master branch to the latest |
| 26 | +git checkout master; |
| 27 | +git pull origin master; |
| 28 | + |
| 29 | +# Update develop to the latest, and create a release brach off of it. |
| 30 | +git checkout develop; |
| 31 | +git pull origin develop; |
| 32 | +git checkout -b release/$ver; |
| 33 | + |
| 34 | +# Bump version in package.json, but do not create a git tag |
| 35 | +npm version $ver --no-git-tag-version; |
| 36 | + |
| 37 | +# Inject the current release version and date into the CHANGELOG file |
| 38 | +sed -i "" "3i\\ |
| 39 | +#### v${ver} (`date '+%B %d, %Y'`)\\ |
| 40 | +\\ |
| 41 | +" CHANGELOG.md; |
| 42 | + |
| 43 | +# Find all commits between the HEAD on develop and the latest tag on master, and pipe their messages into the clipboard |
| 44 | +git log $(git describe --tags master --abbrev=0)..HEAD --merges --pretty=format:'* %s' | pbcopy; |
| 45 | + |
| 46 | +# Provision manual intervention for CHANGELOG.md |
| 47 | +vi CHANGELOG.md |
| 48 | + |
| 49 | +# Create the release |
| 50 | +git add CHANGELOG.md package.json; |
| 51 | +[[ -f package-lock.json ]] && git add package-lock.json; |
| 52 | +git commit -am "$msg"; |
| 53 | + |
| 54 | +# Merge the release branch into develop and push |
| 55 | +git checkout develop; |
| 56 | +git merge --no-ff release/$ver; |
| 57 | +git push origin develop; |
| 58 | + |
| 59 | +# Merge the release branch into master, create a tag and push |
| 60 | +git checkout master; |
| 61 | +git merge --no-ff release/$ver; |
| 62 | +git tag -a "$ver" -m "$msg"; |
| 63 | +git push origin master --follow-tags; |
| 64 | + |
| 65 | +# Move back to develop |
| 66 | +git checkout develop; |
| 67 | +git branch -d release/$ver; |
| 68 | + |
| 69 | +unset msg ver; |
0 commit comments