-
Notifications
You must be signed in to change notification settings - Fork 7
/
prepare_release.sh
executable file
·86 lines (71 loc) · 2.04 KB
/
prepare_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
UPSTREAM_URL='[email protected]:TNG/momo-scheduler.git'
# default: not dry-run
DRY_RUN=0
UPSTREAM_BRANCH=main
set -eu
for arg in "$@"; do
case $arg in
--version=*)
VERSION="${1#*=}"
VERSION_PREFIXED="v${1#*=}"
;;
--upstream=*)
UPSTREAM_URL="${1#*=}"
;;
--dry-run)
DRY_RUN=1
;;
*)
printf "***************************\n"
printf "* Error: Invalid argument.*\n"
printf "***************************\n"
exit 1
esac
shift
done
if [[ ! $VERSION =~ ^[0-9]*\.[0-9]*\.[0-9]*(-[A-Z0-9]*)?$ ]]; then
echo "You have to provide a version as first parameter (without v-prefix, e.g. 0.14.0)"
exit 1
fi
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ ! $GIT_BRANCH =~ $UPSTREAM_BRANCH ]]; then
echo "You do not seem to be on the $UPSTREAM_BRANCH branch!"
exit 1
fi
if [ -n "$(git status --porcelain)" ]; then
echo "You have local changes!"
if [[ $DRY_RUN = 0 ]]; then
exit 1
fi
fi
git pull "$UPSTREAM_URL" "$UPSTREAM_BRANCH"
RELEASE_BRANCH="$VERSION_PREFIXED-release"
git branch "$RELEASE_BRANCH"
git checkout "$RELEASE_BRANCH"
if [[ $DRY_RUN = 1 ]]; then
echo "Preparing release of version $VERSION (dry-run)"
else
echo "Preparing release of version $VERSION"
fi
echo "Updating version in package.json"
sed -i -e "s/\"version\":.*/\"version\":\ \"$VERSION\"\,/" package.json
npm install
echo "Linting, building and testing"
npm run lint
npm run build
npm run test
echo "Committing version change"
git add package.json package-lock.json
git commit -sm "chore: update version to $VERSION"
if [[ $DRY_RUN = 1 ]]; then
echo "Pushing version to GitHub repository (dry-run)"
git push --set-upstream "$UPSTREAM_URL" "$RELEASE_BRANCH" --dry-run
else
echo "Pushing version to GitHub repository"
git push --set-upstream "$UPSTREAM_URL" "$RELEASE_BRANCH"
fi
echo "Please merge $RELEASE_BRANCH into $UPSTREAM_BRANCH"
if [[ $DRY_RUN = 1 ]]; then
echo "Run these commands to clean up: git checkout $UPSTREAM_BRANCH && git branch -D $RELEASE_BRANCH"
fi