This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
forked from as-ideas/oil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
releaseOil.sh
executable file
·139 lines (108 loc) · 3.93 KB
/
releaseOil.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env bash
# This script requires that the following environment variables are defined (for example by your build server):
# - RELEASE_NAME (the name of your release)
# - RELEASE_NUMBER (the number of your release, will be checked against package.json)
# - GITHUB_USERNAME
# - GITHUB_PASSWORD
# - NPMJS_USERNAME
# - NPMJS_PASSWORD
# - NPMJS_EMAIL
# - AWS_ACCESS_KEY_ID
# - AWS_SECRET_ACCESS_KEY
# - AWS_REGION
# - AWS_BUCKET
#
# Furthermore, it requires that the following command line interface tools are installed:
# - aws
# - npm
# - curl
# - expect
### Helper functions
function checkEnvironment {
variable=$1
if [[ "${!variable}" = "" ]];
then
echo "Error: Necessary environment variable undefined! Please define '$variable'!";
exit 1
fi
}
function putS3 {
path=$1
file=$2
aws_path=$3
aws s3 cp "${path}/${file}" "s3://${AWS_BUCKET}${aws_path}" || exit 1
}
### Configuration
PACKAGE_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]')
GITHUB_REPO_URL=https://api.github.com/repos/as-ideas/oil
AWS_BUCKET_PATH=/rawOil/${PACKAGE_VERSION}
### Main
echo "\n### Checking environment"
checkEnvironment "RELEASE_NAME"
checkEnvironment "RELEASE_NUMBER"
checkEnvironment "GITHUB_USERNAME"
checkEnvironment "GITHUB_PASSWORD"
checkEnvironment "AWS_ACCESS_KEY_ID"
checkEnvironment "AWS_SECRET_ACCESS_KEY"
checkEnvironment "AWS_REGION"
checkEnvironment "AWS_BUCKET"
checkEnvironment "NPMJS_USERNAME"
checkEnvironment "NPMJS_PASSWORD"
checkEnvironment "NPMJS_EMAIL"
echo "### Validating release number"
if [[ "${RELEASE_NUMBER}" != "${PACKAGE_VERSION}" ]];
then
echo "Error: given release number does not match version in package.json!"
exit 1
fi
echo "### NPM version check"
npm -v
echo "### Installing dependencies"
npm install || exit 1
echo "### Building release" $PACKAGE_VERSION$SNAPSHOT
export SNAPSHOT="-RELEASE";npm run build:release || exit 1
echo "### Copying release to release directory"
mkdir release/$PACKAGE_VERSION
cp dist/*.$PACKAGE_VERSION-RELEASE.*.js release/$PACKAGE_VERSION/
cp -r dist/docs release/$PACKAGE_VERSION/
echo "### Copying stats.json to release directory"
cp dist/stats.json release/$PACKAGE_VERSION/
echo "### Copying hub.html to release directory and versioning it"
cp src/hub.html release/$PACKAGE_VERSION/
HUB_HTML=$(cat release/$PACKAGE_VERSION/hub.html)
HUB_JS=$(cat release/$PACKAGE_VERSION/hub.$PACKAGE_VERSION-RELEASE.min.js)
echo "${HUB_HTML/<!--REPLACEME-->/$HUB_JS}" > release/$PACKAGE_VERSION/hub.html
cp release/$PACKAGE_VERSION/hub.html dist/latest/hub.html
echo "### Copying and versioning poi-list to release directory"
cp -r dist/poi-lists release/$PACKAGE_VERSION/
mkdir dist/latest/poi-lists
cp dist/poi-lists/default.json dist/latest/poi-lists/default.json
echo "### Creating release for npmjs.com"
if [[ -d "release/current" ]];
then
rm -rf release/current
fi
cp -r release/$PACKAGE_VERSION release/current
rm -rf release/current/docs release/current/poi-lists release/current/stats.json
echo "### Increasing patch version"
git add .
git commit -a -m "Adding new release $PACKAGE_VERSION$SNAPSHOT" --no-edit
git push origin HEAD:master
echo "### Creating release on GitHub"
curl -i -u "${GITHUB_USERNAME}:${GITHUB_PASSWORD}" -X POST -d "{
\"tag_name\": \"${PACKAGE_VERSION}\",
\"target_commitish\": \"master\",
\"name\": \"${RELEASE_NAME}\",
\"draft\": false,
\"prerelease\": false
}" "${GITHUB_REPO_URL}/releases" || exit 1
echo "### Uploading release to S3 bucket"
for file in release/${PACKAGE_VERSION}/*.js; do
putS3 "release/${PACKAGE_VERSION}" "${file##*/}" "${AWS_BUCKET_PATH}/"
done
putS3 "release/${PACKAGE_VERSION}" "hub.html" "${AWS_BUCKET_PATH}/"
putS3 "release/${PACKAGE_VERSION}/poi-lists" "default.json" "${AWS_BUCKET_PATH}/poi-lists/"
echo "### Pushing release to npmjs.com"
expect ./npm_login.sh "${NPMJS_USERNAME}" "${NPMJS_PASSWORD}" "${NPMJS_EMAIL}" || exit 1
npm publish || exit 1
npm logout || exit 1