-
Notifications
You must be signed in to change notification settings - Fork 0
/
js-publish.sh
executable file
·100 lines (73 loc) · 2.72 KB
/
js-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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env bash
# Fail entire script at the first command that fails
set -e
PROPERTY_FILE=amf-apicontract.versions
function getProperty {
PROP_KEY=$1
PROP_VALUE=`cat ${PROPERTY_FILE} | grep "amf.apicontract" | cut -d'=' -f2`
echo ${PROP_VALUE}
}
echo "Reading property version from $PROPERTY_FILE"
PROJECT_VERSION=$(getProperty)
if [[ ${PROJECT_VERSION} == *-SNAPSHOT ]]; then
IS_SNAPSHOT=true
else
IS_SNAPSHOT=false
fi
if [[ ${PROJECT_VERSION} == *-RC.* ]]; then
IS_RC=true
else
IS_RC=false
fi
echo "amf-apicontract.versions version: $PROJECT_VERSION"
echo "Is snapshot: $IS_SNAPSHOT"
echo "Is RC: $IS_RC"
cd amf-cli/js
if ${IS_SNAPSHOT}; then
LATEST_SNAPSHOT=`npm v amf-client-js dist-tags.snapshot`
echo "Repo latest snapshot: $LATEST_SNAPSHOT"
if [[ ${LATEST_SNAPSHOT} == ${PROJECT_VERSION}* ]]; then
echo "Just add one prerelease"
npm version ${LATEST_SNAPSHOT} --force --no-git-tag-version
npm version prerelease --force --no-git-tag-version
echo "Publish one more snapshot"
else
echo "Start prerelease from scratch"
npm version ${PROJECT_VERSION} --force --no-git-tag-version
npm version prerelease --force --no-git-tag-version
echo "Publish new snapshot"
fi
echo "NOTE: If this step fails, check that the tag must be wrong and it's trying to publish an existing snapshot!"
npm publish --tag snapshot
echo "Finished snapshot publish"
echo "Add 'beta' tag to snapshot"
# NEW_VERSION=`npm view amf-client-js@snapshot version`
# Extract version from package.json because npm doesn't refresh as fast as we need it to.
NEW_VERSION=`node -p "require('./package.json').version"`
echo "To version: $NEW_VERSION"
npm dist-tag add amf-client-js@${NEW_VERSION} beta
else
if ${IS_RC}; then
echo "Publishing new RC"
echo "NOTE: no intelligence here, just publishes the RC version, make sure it does not exist."
npm version ${PROJECT_VERSION} --force --no-git-tag-version
npm publish --tag rc
echo "Finished RC publish"
else
LATEST_RELEASE=`npm v amf-client-js dist-tags.latest`
if [[ ${PROJECT_VERSION} != ${LATEST_RELEASE} ]]; then
echo "New release $PROJECT_VERSION"
npm version ${PROJECT_VERSION} --force --no-git-tag-version
echo "Publish new release"
else
echo "Latest release is already $PROJECT_VERSION"
fi
npm publish
echo "Finished latest publish"
echo "Add 'release' tag to latest"
npm dist-tag add amf-client-js@${PROJECT_VERSION} release
fi
fi
# Reset package.json so that the new version is not pushed
git checkout package.json
cd ../..