-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathtag-release.sh
executable file
·46 lines (39 loc) · 1.62 KB
/
tag-release.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env bash
# Bump patch version in package.json & examples/parent-child-demo/package.json, commit as "Release X.Y.Z",
# and add git tag "vX.Y.Z" with message "Release X.Y.Z".
set -o errexit -o pipefail
if [[ !($1 =~ ^major|minor|patch$) ]]; then
echo "Usage: tag-release.sh [major|minor|patch]"
exit 1
fi
set -o nounset
gitStatus=$(git status -s)
if [[ -n $gitStatus ]]; then
echo "ERROR: Working tree has modified/untracked files:"
echo "${gitStatus}"
exit 1
fi
if [[ `cat package.json` =~ .*\"version\":\ *\"([0-9]+)\.([0-9]+)\.([0-9]+)\" ]]
then
vMajor=${BASH_REMATCH[1]}
vMinor=${BASH_REMATCH[2]}
vPatch=${BASH_REMATCH[3]}
vMajorNew=$vMajor
vMinorNew=$vMinor
vPatchNew=$vPatch
if [[ $1 == major ]]; then vMajorNew=$(( $vMajor + 1 )); vMinorNew=0; vPatchNew=0; fi
if [[ $1 == minor ]]; then vMinorNew=$(( $vMinor + 1 )); vPatchNew=0; fi
if [[ $1 == patch ]]; then vPatchNew=$(( $vPatch + 1 )); fi
newVersion=$vMajorNew.$vMinorNew.$vPatchNew
echo "Bumping version from ${vMajor}.${vMinor}.${vPatch} to ${newVersion}"
sed -i '' -e "s/\(\"version\": *\"\).*\(\".*\)$/\1${newVersion}\2/" package.json
# Demo dependency is updated manually after release, when the new version has been verified to run on CodeSandbox.
# sed -i '' -e "s/\(\"react-lifecycle-visualizer\": *\"[\^~]\{0,1\}\).*\(\".*\)$/\1${newVersion}\2/" examples/parent-child-demo/package.json
npm i
git add package.json package-lock.json examples/parent-child-demo/package.json
git commit -m "Release ${newVersion}"
git tag -a "v${newVersion}" -m "Release ${newVersion}"
else
echo "ERROR: No \"version\" found in package.json"
exit 1
fi