forked from apify/proxy-chain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.sh
executable file
·50 lines (39 loc) · 1.67 KB
/
publish.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
#!/bin/bash
set -e
RED='\033[0;31m'
NC='\033[0m' # No Color
PACKAGE_NAME=`node -pe "require('./package.json').name"`
PACKAGE_VERSION=`node -pe "require('./package.json').version"`
BRANCH=`git status | grep 'On branch' | cut -d ' ' -f 3`
BRANCH_UP_TO_DATE=`git status | grep 'nothing to commit' | tr -s \n ' '`;
GIT_TAG="v${PACKAGE_VERSION}"
if [ -z "${BRANCH_UP_TO_DATE}" ]; then
printf "${RED}You have uncommitted changes!${NC}\n"
exit 1
fi
echo "Pushing to git ..."
git push
# Master gets published as LATEST if that version doesn't exists yet and retagged as LATEST otherwise.
if [ "${BRANCH}" = "master" ]; then
EXISTING_NPM_VERSION=$(npm view ${PACKAGE_NAME} versions | grep ${PACKAGE_VERSION} | tee) # Using tee to swallow non-zero exit code
if [ -z "${EXISTING_NPM_VERSION}" ]; then
printf "${RED}Version ${PACKAGE_VERSION} was not yet published on NPM. Note that you can only publish to NPM from \"develop\" branch!${NC}\n"
exit 1
else
echo "Tagging version ${PACKAGE_VERSION} with tag \"latest\" ..."
RUNNING_FROM_SCRIPT=1 npm dist-tag add ${PACKAGE_NAME}@${PACKAGE_VERSION} latest
fi
# Develop branch gets published as BETA and we don't allow to override tag of existing version.
elif [ "${BRANCH}" = "develop" ]; then
echo "Publishing version ${PACKAGE_VERSION} with tag \"beta\" ..."
RUNNING_FROM_SCRIPT=1 npm publish --tag beta
echo "Tagging git commit with ${GIT_TAG} ..."
git tag ${GIT_TAG}
git push origin ${GIT_TAG}
echo "Git tag: ${GIT_TAG} created."
# For other branch throw an error.
else
printf "${RED}You can publish from develop and master branches only!${NC}\n"
exit 1
fi
echo "Done."