-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild-n-publish.sh
128 lines (112 loc) · 3.25 KB
/
build-n-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
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
#!/bin/sh
# constants
pkgName="unlayer-editor"
# parameters
commit=""
name=""
version=""
versionPre=""
print_help () {
echo ""
echo "Usage: sh build-n-publish.sh [OPTIONS]"
echo ""
echo "Use Docker to build project's bundle files and publish them to our CDN"
echo ""
echo "Options:"
echo " -p, --package, package name (optional, default: ${pkgName})"
echo " -c, --commit (mandatory)"
echo " -n, --name, version name"
echo " -v, --version, version number"
echo " -s, --pre-version-suffix (optional, only with version)"
echo " -h, --help"
echo "Only one of name or version parameters is required, and cannot be included together."
echo
echo "Examples:"
echo " sh build-n-publish.sh --commit=aee25c286a7c8265e2b32ccc293f5ab0bd7a9d57 --version=v1.2.11"
echo " sh build-n-publish.sh --c=aee25c286a7c8265e2b32ccc293f5ab0bd7a9d57 -v=v1.2.11"
echo " sh build-n-publish.sh --c=aee25c286a7c8265e2b32ccc293f5ab0bd7a9d57 -v=v1.2.11 -s=beta1"
echo " sh build-n-publish.sh --commit=aee25c286a7c8265e2b32ccc293f5ab0bd7a9d57 --version=v1.2.11 --pre-version-suffix=beta1"
echo " sh build-n-publish.sh --commit=aee25c286a7c8265e2b32ccc293f5ab0bd7a9d57 --name=main"
}
for i in "$@" ; do
case $i in
-p=*|--package=*)
pkgName="${i#*=}"
;;
-c=*|--commit=*)
commit="${i#*=}"
;;
-n=*|--name=*)
name="${i#*=}"
;;
-v=*|--version=*)
version="${i#*=}"
;;
-s=*|--pre-version-suffix=*)
versionPre="${i#*=}"
;;
-h|--help)
print_help
exit 0
;;
esac
done
if [ -z "${pkgName}" ]
then
echo "Error: package parameter is mandatory"
print_help
exit 1
fi
if [ -z "${commit}" ]
then
echo "Error: commit parameter is mandatory"
print_help
exit 1
fi
if [ -n "${version}" ] && [ -n "${name}" ]
then
echo "Error: name and version parameters cannot be included together"
print_help
exit 1
fi
if [ -z "${version}" ] && [ -z "${name}" ]
then
echo "Error: one of name or version parameters is required"
print_help
exit 1
fi
if [ -z "${version}" ] && [ -n "${versionPre}" ]
then
echo "Error: pre-version-suffix parameter is only accepted along with version parameter"
print_help
exit 1
fi
# TODO: validate commit format
# TODO: validate version format (if it is included)
# Stop script on NZEC
set -e
# Stop script if unbound variable found (use ${var:-} if intentional)
set -u
# Lines added to get the script running in the script path shell context
# reference: http://www.ostricher.com/2014/10/the-right-way-to-get-the-directory-of-a-bash-script/
cd "$(dirname "$0")"
# To avoid issues with MINGW and Git Bash, see:
# https://github.com/docker/toolbox/issues/673
# https://gist.github.com/borekb/cb1536a3685ca6fc0ad9a028e6a959e3
export MSYS_NO_PATHCONV=1
export MSYS2_ARG_CONV_EXCL="*"
tag="${pkgName}-${commit}"
docker build . --tag "${tag}"
docker run --rm \
-v /var/lib/jenkins/.ssh:/root/.ssh:ro \
"${tag}" \
/bin/sh -c "\
sh ./prepare.sh \
--commit=\"${commit}\" \
--name=\"${name}\" \
--version=\"${version}\" \
--pre-version-suffix=\"${versionPre}\" \
&& sh ./upload.sh \
--port=\"${CDN_SFTP_PORT}\" \
--destination=\"${CDN_SFTP_USERNAME}@${CDN_SFTP_HOSTNAME}:/${CDN_SFTP_BASE}/${pkgName}/\" \
"