-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
94 lines (76 loc) · 1.87 KB
/
entrypoint.sh
File metadata and controls
94 lines (76 loc) · 1.87 KB
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
#!/usr/bin/env bash
. ~/.nvm/nvm.sh
. ~/.profile
. ~/.bashrc
set -xe
pull_source_code(){
local user repo branch token pr_branch pr_branch_id
user=$1
repo=$2
branch=$3
token=$4
# For pull requests https://help.github.com/articles/checking-out-pull-requests-locally/
if [[ $branch == *PR-[0-9]* ]]; then
pr_branch_id=$(echo $branch | cut -f2 -d "-")
pr_branch="PR-$pr_branch_id"
branch=develop
fi
if [[ -z $token ]]; then
git clone -b $branch "https://github.com/$user/$repo.git" .
else
git clone -b $branch "https://[email protected]/$user/$repo.git" .
fi
if [[ $pr_branch == *PR-[0-9]* ]]; then
git fetch origin "pull/$pr_branch_id/head:$pr_branch"
git checkout $pr_branch
fi
}
execute_with_node_version(){
local node_version; node_version=$1
nvm install $node_version
nvm use $node_version
}
run_npm_command(){
local cmd; cmd=$1
npm run $cmd
}
install_dependencies(){
npm install
}
copy_to_generated_file_folder(){
local from to
from=$1
to="/generated-files"
cp -R $from $to
}
npm_publish_module(){
local version npm_token
version=$1
npm_token=$2
echo $npm_token > .npmrc
npm version --no-git-tag-version $VERSION
npm publish
}
main(){
# If the node version is not specified, it is executed with the previously installed one in base image
if [[ -n $NODE ]]; then
execute_with_node_version $NODE
fi
# If not have a repository get code source from a volume: -v `pwd`:/workspace
if [[ -n $REPO ]]; then
pull_source_code $USER $REPO $BRANCH $GITHUB_TOKEN
fi
# Use dependecies of other executions
if [ ! -d "node_modules" ]; then
install_dependencies
fi
if [ "$NPM_COMMAND" == "publish" ]; then
npm_publish_module $VERSION $NPM_TOKEN
else
run_npm_command $NPM_COMMAND
fi
if [[ -n $GENERATED_FILES ]]; then
copy_to_generated_file_folder $GENERATED_FILES
fi
}
main "$@"