-
Notifications
You must be signed in to change notification settings - Fork 8
/
release.sh
executable file
·88 lines (73 loc) · 2.01 KB
/
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
87
88
#!/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#*=}"
;;
--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-zA-Z0-9]*(\.[0-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"
echo "Checking version in package.json"
if [ -z "$(sed -n -e "/\"version\": \"${VERSION}\"/ p" package.json)" ]; then
echo "Version in package.json is not $VERSION!"
exit 1
fi
if [[ $DRY_RUN = 1 ]]; then
echo "Releasing version $VERSION (dry-run)"
else
echo "Releasing version $VERSION"
fi
npm ci
echo "Linting, building and testing"
npm run lint
npm run build
npm run test
echo "Creating release tag"
git tag -am "$VERSION_PREFIXED" "$VERSION_PREFIXED"
if [[ $DRY_RUN = 1 ]]; then
echo "Pushing tag to GitHub repository (dry-run)"
git push "$UPSTREAM_URL" "$VERSION_PREFIXED" --dry-run
else
echo "Pushing tag to GitHub repository"
git push "$UPSTREAM_URL" "$VERSION_PREFIXED"
fi
if [[ $DRY_RUN = 1 ]]; then
echo "Publish to npmjs (dry-run)"
npm publish --access public --registry https://registry.npmjs.org/ --dry-run
else
echo "Publish to npmjs"
npm publish --access public --registry https://registry.npmjs.org/
fi
if [[ $DRY_RUN = 1 ]]; then
echo "Run this command to clean up: git tag -d $VERSION_PREFIXED"
fi