-
Notifications
You must be signed in to change notification settings - Fork 18
/
publish
executable file
·82 lines (63 loc) · 2.02 KB
/
publish
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
#!/bin/bash
set -e
# Ensure there's a version number
if [ $# -eq 0 ]; then
echo "Please specify a SemVer version to publish 'X.Y.Z(-PRERELEASE)(+BUILD)'"
exit 1
fi
VERSION_NUMBER=$1
# regex taken from: https://github.com/fsaintjacques/semver-tool/blob/master/src/semver
NAT='0|[1-9][0-9]*'
ALPHANUM='[0-9]*[A-Za-z-][0-9A-Za-z-]*'
IDENT="$NAT|$ALPHANUM"
FIELD='[0-9A-Za-z-]+'
SEMVER_REGEX="\
^[vV]?\
($NAT)\\.($NAT)\\.($NAT)\
(\\-(${IDENT})(\\.(${IDENT}))*)?\
(\\+${FIELD}(\\.${FIELD})*)?$"
# Make sure our version is an actual semantic version
if [[ ! $VERSION_NUMBER =~ $SEMVER_REGEX ]]; then
echo "The version needs to follow a SemVer naming scheme 'X.Y.Z(-PRERELEASE)(+BUILD)'"
exit 1
fi
# Make sure our working dir is the dir of the publish script
cd $(dirname ${BASH_SOURCE[0]})
echo "Fetching git remotes"
git fetch
if ! git status | grep -q 'On branch master'; then
echo "Error! Must be on master branch to publish"
exit 1
fi
if ! git status | grep -q "Your branch is up to date with 'origin/master'."; then
echo "Error! Must be up to date with origin/master to publish"
exit 1
fi
if ! git status | grep -q 'working tree clean'; then
echo "Error! Cannot publish with dirty working tree"
#exit 1
fi
echo "Installing dependencies"
yarn -s install --frozen-lockfile
echo "Running tests"
yarn -s run ci
echo "Building production build"
yarn run build
echo "Clockface was built successfully!"
# Lifted from https://stackoverflow.com/a/3232082/92446
read -r -p "Are you sure you want to publish the build to npm? [y/N] " response
case "$response" in
[yY][eE][sS]|[yY])
echo "Tagging and publishing $VERSION_NUMBER release"
yarn -s publish --$VERSION_NUMBER --access=public
echo "Pushing git commit and tag"
git push --follow-tags
echo "Publishing new Clockface Storybook to Github Pages"
yarn run publishStorybook
echo "Publish successful!"
;;
*)
echo "Understandable, have a great day. Exiting without publishing."
exit 1
;;
esac