-
Notifications
You must be signed in to change notification settings - Fork 1
/
publish
executable file
·37 lines (27 loc) · 981 Bytes
/
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
#!/bin/sh
# Login to NPM
npm config set //registry.npmjs.org/:_authToken=$NPM_TOKEN;
version=$(grep -m1 version package.json | awk -F: '{ print $2 }' | sed 's/[", ]//g')
name=$(grep -m1 name package.json | awk -F: '{ print $2 }' | sed 's/[", ]//g')
# npm publish is an idempotent action
tempLog=$(mktemp)
echo "Trying to publish..."
npm publish > ${tempLog} 2>&1
if [ $? -eq 0 ]; then
echo "Successfully published!"
curl -H "Content-Type: application/json" \
-X POST \
-d "{\"text\":\"A new version *$version* of *$name* package has been just published. <https://www.npmjs.com/package/$name>\",\"username\":\"circle-ci\",\"icon_emoji\":\":tada:\"}" \
"https://hooks.slack.com/services/$SLACK_TOKENS"
else
grep -q "You cannot publish over the previously published version" npm-debug.log
grepStatus=$?
if [ $grepStatus -eq 0 ]; then
echo "Already published."
else
cat ${tempLog}
fi
rm -f ${tempLog}
exit 0
fi
rm -f ${tempLog}