generated from kalisio/skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.travis.env.sh
92 lines (76 loc) · 2.28 KB
/
.travis.env.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
#!/bin/bash
check_code()
{
if [[ $1 -ne $2 ]]; then
echo "$3 has failed [error: $1]"
exit 1
fi
}
parse_semver()
{
local REGEXP="^([0-9]+)\.([0-9]+)\.([0-9]+)"
[[ "$1" =~ $REGEXP ]]
SEMVER=(${BASH_REMATCH[1]} ${BASH_REMATCH[2]} ${BASH_REMATCH[3]})
}
# Define the application name
APP=$(node -p -e "require('./package.json').name")
# Define the application version
VERSION=$(node -p -e "require('./package.json').version")
parse_semver $VERSION
MAJOR=${SEMVER[0]}
MINOR=${SEMVER[1]}
PATCH=${SEMVER[2]}
echo "Building $APP v$MAJOR.$MINOR.$PATCH"
# Define the flavor build
TEST_FLAVOR_REGEX="^test-*|-test$"
PROD_FLAVOR_REGEX="^prod-v[0-9]+\.[0-9]+\.[0-9]+"
if [[ $TRAVIS_TAG =~ $PROD_FLAVOR_REGEX ]];
then
export FLAVOR=prod
KDK_PROJECT_FILE=$APP-$VERSION
else
if [[ $TRAVIS_BRANCH =~ $TEST_FLAVOR_REGEX ]];
then
export FLAVOR=test
KDK_PROJECT_FILE=$APP-$MAJOR.$MINOR
else
export FLAVOR=dev
KDK_PROJECT_FILE=$APP
fi
fi
export NODE_APP_INSTANCE=$FLAVOR
TAG=$VERSION-$FLAVOR
echo "Build flavor is $FLAVOR on branch $TRAVIS_BRANCH"
# Leave the project directory to avoid Webpack to look for files into the project directory
cd ..
# Clone the workspace where to build the app
echo -e "machine github.com\n login $GITHUB_TOKEN" > ~/.netrc
git clone -b $APP https://github.com/kalisio/kdk-workspaces workspace
export WORKSPACE_DIR=`pwd`/workspace
# Read ci environement variables
cp workspace/common/.travis.env .travis.env
if [ -f workspace/$FLAVOR/.travis.env ]
then
echo merging $FLAVOR/.travis.env with common .travis.env
cat workspace/$FLAVOR/.travis.env >> .travis.env
fi
set -a
. .travis.env
set +a
export BUILD_NUMBER=$TRAVIS_BUILD_NUMBER
BUILD_BUCKET=${APP}/$BUILD_NUMBER
# Install the kdk
git clone https://github.com/kalisio/kli.git kalisio && cd kalisio && yarn
# In dev flavor we can build different versions on different branches
# so check if a specific file exists for the target branch first otherwise use default one
if [[ -f $WORKSPACE_DIR/$FLAVOR/$KDK_PROJECT_FILE-$TRAVIS_BRANCH.js ]];
then
cp $WORKSPACE_DIR/$FLAVOR/$KDK_PROJECT_FILE-$TRAVIS_BRANCH.js $APP.js
else
cp $WORKSPACE_DIR/$FLAVOR/$KDK_PROJECT_FILE.js $APP.js
fi
# Clone the project and install the dependencies
node . $APP.js --clone
node . $APP.js --install
node . $APP.js --link
cd $APP