forked from demisto/content
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap
executable file
·100 lines (84 loc) · 2.68 KB
/
bootstrap
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
#!/usr/bin/env bash
# exit on errors
set -e
#
# Bootstraps a development environment.
#
# This includes:
# * install pre-commit hooks
# * setup content dependencies with poetry
# * Setup npm
# poetry is installed in ~/.local/bin
PATH=~/.local/bin:$PATH
if [ "$1" == "-h" -o "$1" == "--help" ]; then
cat << EOF
Setup development environment (run with no arguments):
* install pre-commit hooks (set NO_HOOKS=1 to skip)
EOF
exit 0
fi
if [ ! "$PWD" == "$(git rev-parse --show-toplevel)" ]; then
cat >&2 <<__EOF__
ERROR: this script must be run at the root of the source tree
__EOF__
exit 1
fi
HOOKS_DIR="${PWD}/.hooks"
GIT_HOOKS_DIR="${PWD}/.git/hooks"
if [ -n "$NO_HOOKS" ]; then
echo "Skipping hooks setup as environment varialbe NO_HOOKS is set"
else
if [ ! -e "${GIT_HOOKS_DIR}/pre-commit" ]; then
echo "Installing 'pre-commit' hooks"
ln -s "${HOOKS_DIR}/pre-commit" "${GIT_HOOKS_DIR}/pre-commit"
else
echo "Skipping install of pre-commit hook as it already exists."
echo "If you want to re-install: 'rm ${GIT_HOOKS_DIR}/pre-commit' and then run this script again."
fi
fi
echo "======================="
if ! command -v poetry >/dev/null 2>&1; then
echo "ERROR: poetry is missing. Please run the following command to install poetry:
curl -sSL https://install.python-poetry.org | python3 -" 1>&2
exit 1
fi
echo "Check if poetry files are valid"
poetry check
echo "Installing dependencies..."
if [ -n "$CI" ]; then
echo "Detected CI env. Running extra requiements"
for _ in {1..3}; do
poetry install --with ci && s=0 && break || s=$?
rm -rf .venv
echo "Sleeping for 10 seconds before retrying"
sleep 10
done
if [ $s -ne 0 ]; then
echo "Failed to install dependencies after 3 tries"
exit 1
fi
else
echo "Detected local env."
poetry install
fi
echo "=========================="
echo "Done setting up virtualenv with poetry"
echo "Activate the venv by running: poetry shell"
echo "Deactivate by running: deactivate"
echo "======================="
if [ -n "$CI" ]; then
echo "Detected CI env. Running npm ci..."
npm ci --cache .npm --prefer-offline
elif [ -n "$NO_NPM" ]; then
echo "Skipping npm node modules setup as environment varialbe NO_NPM is set"
else
if ! command -v npm >/dev/null 2>&1; then
echo "Skipping npm node modules as 'npm' command was not found!!"
echo "node and npm are optional but recommended. We use node for validating README files."
echo "You can install node and npm on your machine."
echo "and then run: 'npm install'"
else
echo "Running: npm install ..."
npm install
fi
fi