-
Notifications
You must be signed in to change notification settings - Fork 273
/
build.sh
executable file
·106 lines (93 loc) · 2.97 KB
/
build.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
#!/bin/bash
# Copyright OpenSearch Contributors
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
set -ex
# vars / libs
SCRIPT_DIR=`dirname $(realpath $0)`
. $SCRIPT_DIR/../../../lib/shell/file_management.sh
PLUGIN_NAME=$(basename "$PWD")
PLUGIN_PATH=`realpath ../OpenSearch-Dashboards/plugins/$PLUGIN_NAME`
function usage() {
echo "Usage: $0 [args]"
echo ""
echo "Arguments:"
echo -e "-v VERSION\t[Required] OpenSearch version."
echo -e "-q QUALIFIER\t[Optional] Version qualifier."
echo -e "-s SNAPSHOT\t[Optional] Build a snapshot, default is 'false'."
echo -e "-p PLATFORM\t[Optional] Platform, ignored."
echo -e "-a ARCHITECTURE\t[Optional] Build architecture, ignored."
echo -e "-o OUTPUT\t[Optional] Output path, default is 'artifacts'."
echo -e "-h help"
}
function cleanup_all() {
File_Delete $PLUGIN_PATH
}
trap cleanup_all TERM INT EXIT
while getopts ":h:v:q:s:o:p:a:" arg; do
case $arg in
h)
usage
exit 1
;;
v)
VERSION=$OPTARG
;;
q)
QUALIFIER=$OPTARG
;;
s)
SNAPSHOT=$OPTARG
;;
o)
OUTPUT=$OPTARG
;;
p)
PLATFORM=$OPTARG
;;
a)
ARCHITECTURE=$OPTARG
;;
:)
echo "Error: -${OPTARG} requires an argument"
usage
exit 1
;;
?)
echo "Invalid option: -${arg}"
exit 1
;;
esac
done
if [ -z "$VERSION" ]; then
echo "Error: You must specify the OpenSearch Dashboards version"
usage
exit 1
fi
[ -z "$OUTPUT" ] && OUTPUT=artifacts
[ ! -z "$QUALIFIER" ] && QUALIFIER_IDENTIFIER="-$QUALIFIER"
NVM_CMD="source $NVM_DIR/nvm.sh && nvm use"
if [ "$PLATFORM" = "windows" ]; then
NVM_CMD="volta install node@`cat ../OpenSearch-Dashboards/.nvmrc` && volta install yarn@`jq -r '.engines.yarn' ../OpenSearch-Dashboards/package.json`"
fi
HELPER_CMD=$(jq -r '.scripts.plugin_helpers' package.json)
if [ "$HELPER_CMD" != null ]; then
HELPER_STRING=plugin_helpers
else
HELPER_STRING=plugin-helpers
fi
mkdir -p $OUTPUT/plugins
# TODO: [CLEANUP] Needed OpenSearch Dashboards git repo to build the required modules for plugins
# This makes it so there is a dependency on having Dashboards pulled already.
cp -r ../$PLUGIN_NAME/ ../OpenSearch-Dashboards/plugins
echo "BUILD MODULES FOR $PLUGIN_NAME"
CURR_DIR=`pwd`
cd ../OpenSearch-Dashboards; eval $NVM_CMD; yarn osd bootstrap
echo "BUILD RELEASE ZIP FOR $PLUGIN_NAME"
cd plugins/$PLUGIN_NAME; yarn $HELPER_STRING build --opensearch-dashboards-version=$VERSION$QUALIFIER_IDENTIFIER
cd $CURR_DIR
echo "COPY $PLUGIN_NAME.zip"
cp -r ../OpenSearch-Dashboards/plugins/$PLUGIN_NAME/build/$PLUGIN_NAME-$VERSION$QUALIFIER_IDENTIFIER.zip $OUTPUT/plugins/