Skip to content
This repository was archived by the owner on Jan 20, 2022. It is now read-only.

Commit f4eb5e5

Browse files
committed
chore(package): add release script
1 parent 339716d commit f4eb5e5

3 files changed

Lines changed: 141 additions & 162 deletions

File tree

build/release.sh

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#!/usr/bin/env bash
2+
3+
# ensure git is latest clean branch
4+
# require npm user
5+
# bump package version
6+
# commit
7+
# create tag
8+
# push commit & tag
9+
# publish
10+
11+
usage() {
12+
set -e
13+
14+
echo ""
15+
echo " Usage: bash $0 <comand>"
16+
echo ""
17+
echo " Commands:"
18+
echo " <major|minor|patch> # run checks and publish"
19+
echo " check # run checks only"
20+
echo " publish <major|minor|patch> # publish without checking"
21+
}
22+
23+
print() {
24+
set -e
25+
26+
echo "RELEASE: $1"
27+
}
28+
29+
check() {
30+
set -e
31+
32+
local failed="false"
33+
34+
# ensure git is ready, fetch before making comparisons
35+
git fetch
36+
local local_sha=$(git rev-parse @)
37+
local remote_sha=$(git rev-parse @{u})
38+
local base_sha=$(git merge-base @ @{u})
39+
40+
if [[ -n $(git status --porcelain) ]]; then
41+
print "[check: FAIL] Commit or stash you changes before releasing."
42+
exit 1
43+
else
44+
print "[check: PASSED] Working directory is clean."
45+
fi
46+
47+
if [ $local_sha = $remote_sha ]; then
48+
print "[check: PASSED] Local branch is up-to-date."
49+
elif [ $local_sha = $base_sha ]; then
50+
print "[check: FAIL] You need to pull changes before you can release."
51+
exit 1
52+
elif [ $remote_sha = $base_sha ]; then
53+
print "[check: FAIL] You need to push changes before you can release."
54+
exit 1
55+
else
56+
print "[check: FAIL] Your branch has diverged from the remote, you cannot release."
57+
exit 1
58+
fi
59+
60+
# ensure npm is ready
61+
local npm_user=$(npm whoami)
62+
63+
# check perms only if package exists, otherwise it will be created
64+
if [ $(npm view > /dev/null 2>&1) ]; then
65+
local is_collaborator=$(npm access ls-collaborators | grep ".*$npm_user.*:.*write.*")
66+
local is_owner=$(npm owner ls | grep ".*$npm_user <.*")
67+
68+
if ! [[ "$npm_user" ]]; then
69+
print "[check: FAIL] You must be logged in to NPM to publish, run \"npm login\" first."
70+
exit 1
71+
fi
72+
73+
if [[ -z "$is_collaborator" ]] && [[ -z "$is_owner" ]]; then
74+
print "[check: FAILED] $npm_user is not an NPM owner or collaborator. Request access from:"
75+
npm owner ls
76+
exit 1
77+
fi
78+
fi
79+
80+
print "[check: DONE] Ready to publish!"
81+
}
82+
83+
publish() {
84+
set -e
85+
86+
local version=$1
87+
88+
if [[ -z ${version} ]]; then
89+
usage
90+
exit 1
91+
fi
92+
93+
# all checks out, publish
94+
print "[publish] Publishing new $version version."
95+
96+
print "[publish] ...npm version $version"
97+
npm version ${version}
98+
99+
print "[publish] ...git push"
100+
git push
101+
102+
print "[publish] ...git push --follow-tags"
103+
git push --follow-tags
104+
105+
print "[publish] ...npm publish"
106+
npm publish
107+
108+
print "[publish] ...done!"
109+
}
110+
111+
run() {
112+
check
113+
publish
114+
}
115+
116+
case $1 in
117+
"major" | "minor" | "patch")
118+
run
119+
;;
120+
121+
"check")
122+
check
123+
;;
124+
125+
"publish")
126+
publish $2
127+
;;
128+
129+
*)
130+
usage
131+
exit 1
132+
;;
133+
esac

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
"prettier:fix": "prettier --write \"**/*.{ts,tsx}\"",
2323
"precommit": "lint-staged && gulp build:docs:toc",
2424
"postcommit": "git update-index --again",
25-
"prerelease": "yarn ci && cross-env NODE_ENV=production yarn build",
25+
"prerelease": "bash build/release.sh check && yarn ci && cross-env NODE_ENV=production yarn build",
2626
"postrelease": "yarn deploy:docs",
27-
"release:major": "yarn prerelease && ta-script npm/release major && yarn postrelease",
28-
"release:minor": "yarn prerelease && ta-script npm/release minor && yarn postrelease",
29-
"release:patch": "yarn prerelease && ta-script npm/release patch && yarn postrelease",
27+
"release:major": "yarn prerelease && bash build/release.sh publish major && yarn postrelease",
28+
"release:minor": "yarn prerelease && bash build/release.sh publish minor && yarn postrelease",
29+
"release:patch": "yarn prerelease && bash build/release.sh publish patch && yarn postrelease",
3030
"prestart": "yarn satisfied --fix yarn",
3131
"start": "gulp --series dll docs",
3232
"satisfied": "satisfied --skip-invalid",
@@ -134,7 +134,6 @@
134134
"semantic-ui-css": "^2.3.1",
135135
"semantic-ui-react": "^0.81.1",
136136
"simulant": "^0.2.2",
137-
"ta-scripts": "^2.5.2",
138137
"through2": "^2.0.3",
139138
"ts-jest": "^22.4.6",
140139
"ts-node": "^6.1.0",

0 commit comments

Comments
 (0)