-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun.sh
executable file
·75 lines (57 loc) · 1.6 KB
/
run.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
#!/bin/bash
npm_setup() {
if [ -z "${NPM_TOKEN}" ]; then
fail 'Please specify auth token'
exit 1
fi
if [ -n "${WERCKER_CACHE_DIR}" ]; then
npm config set cache "$WERCKER_CACHE_DIR/wercker/npm"
fi
if [ -z "${WERCKER_NPM_CONFIG_ACCESS}" ]; then
export NPM_CONFIG_ACCESS=public
npm config set access public
else
info "NPM_CONFIG_ACCESS=${NPM_CONFIG_ACCESS}"
fi
}
npm_login() {
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
local retries=3;
for try in $(seq "$retries"); do
info "Starting npm whoami, try: $try"
npm whoami && return
done
fail "Failed to authenticate with npm, retries: $retries"
exit 1
}
npm_publish() {
NPM_VERSION=$(grep package.json -e 'version' | awk '{print substr($2, 2, length($2)-3)}')
NPM_VERSION_PRERELEASE=$(echo "${NPM_VERSION}" | cut -d '-' -f 2 -s)
info "NPM_VERSION=${NPM_VERSION}"
info "NPM_VERSION_PRERELEASE=${NPM_VERSION_PRERELEASE}"
retries=3
for try in $(seq "$retries"); do
info "try: ${try}"
if [ -n "${NPM_CONFIG_TAG}" ]; then
info "npm publish . --tag ${NPM_CONFIG_TAG}"
npm publish . --tag "${NPM_CONFIG_TAG}" && return
elif [ -n "${NPM_VERSION_PRERELEASE}" ]; then
info "npm publish . --tag ${WERCKER_GIT_BRANCH}"
npm publish . --tag "${WERCKER_GIT_BRANCH}" && return
else
info "npm publish . --tag latest"
npm publish . --tag latest && return
fi
done
fail "npm publish failed with status code $?"
exit 1
}
main() {
npm_setup
set +e
npm_login
npm_publish
set -e
success "Package successfully published to NPM"
}
main;