forked from Sage-Bionetworks/sage-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev-env.sh
184 lines (147 loc) · 4.67 KB
/
dev-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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# This file to be sourced in the terminal for development.
export WORKSPACE_DIR=$(pwd)
if [ -e /proc/cpuinfo ]; then # Linux
WORKSPACE_BUILD_PROCS=$(grep -c ^processor /proc/cpuinfo)
elif [ $(sysctl -n hw.ncpu) ]; then # Mac
WORKSPACE_BUILD_PROCS=$(sysctl -n hw.ncpu)
else # Other/fail
WORKSPACE_BUILD_PROCS=4
fi
export WORKSPACE_BUILD_PROCS
# cd to the workspace directory
function workspace-cd {
cd $WORKSPACE_DIR
}
# Add local npm binaries to PATH
export PATH="$PATH:$WORKSPACE_DIR/node_modules/.bin"
function workspace-install-nodejs-dependencies {
pnpm install --frozen-lockfile
}
function workspace-install-python-dependencies {
poetry env use $(pyenv which python)
poetry install --with dev
workspace-initialize-env
}
function workspace-install {
workspace-install-nodejs-dependencies
workspace-install-python-dependencies
nx run-many --target=create-config
nx run-many --target=prepare --projects=tag:language:java --parallel=1
nx run-many --target=prepare --projects=tag:language:python --projects=tag:language:r
}
function workspace-install-affected {
workspace-install-nodejs-dependencies
workspace-install-python-dependencies
nx affected --target=create-config
nx affected --target=prepare --exclude '!tag:language:java' --parallel=1
nx affected --target=prepare --exclude 'tag:language:java'
}
# Setup Python virtualenvs
# function challenge-python {
# nx run-many --parallel --target=python
# }
function workspace-kill-port {
port="$1"
pids="$(lsof -t -i:$port)"
if [ -z "$pids" ]; then
echo "There are no processes listening to the port $port."
else
echo "Killing the processes listening to the port $port."
kill -9 $pids
fi
}
function workspace-lint {
nx run-many --target=lint
}
function workspace-build {
nx run-many --target=build
}
function workspace-test {
nx run-many --target=test
}
function workspace-build-images {
nx run-many --parallel --target=build-image
}
function workspace-graph {
nx graph
}
function openchallenges-infra {
node dist/apps/openchallenges/infra/src/main.js "$@"
}
function agora-build-images {
nx run-many --target=build-image --projects=agora-* --parallel=3
}
function agora-test {
nx run-many --target=test --projects=agora-* --parallel=10
}
function agora-test-affected {
nx affected --target=test --projects=agora-* --parallel=10
}
function model-ad-build-images {
nx run-many --target=build-image --projects=model-ad-* --parallel=3
}
function openchallenges-build-images {
nx run-many --target=build-image --projects=openchallenges-* --parallel=3
}
function schematic-build-images {
nx run-many --target=build-image --projects=schematic-* --parallel=3
}
function iatlas-build-images {
nx run-many --target=build-image --projects=iatlas-* --parallel=3
}
function synapse-build-images {
nx run-many --target=build-image --projects=synapse-* --parallel=3
}
function workspace-nx-cloud-help {
printf "%s\n" \
"" \
"This workspace is not configured to use Nx Cloud. To configure it," \
" - Run \`cp nx-cloud.env.example nx-cloud.env\`" \
" - Add Nx Cloud credentials to nx-cloud.env (contact [email protected])"
}
# Utility function to get comparable semver values.
# See https://apple.stackexchange.com/a/123408/11374
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
function check-vscode-version {
expected="1.91.1"
actual="$(code --version | head -n 1)"
if [ $(version $actual) -lt $(version $expected) ]; then
echo "📦 Please update VS Code (${actual}) to version ${expected} or above."
fi
}
function workspace-welcome {
echo "Welcome to Sage monorepo! 👋"
if [ ! -d "node_modules" ]; then
printf "%s\n" \
"" \
"Run \`workspace-install\` to install workspace tools like nx and jest."
fi
if [ ! -f "nx-cloud.env" ]; then
workspace-nx-cloud-help
fi
if command -v code &> /dev/null
then
check-vscode-version
fi
}
function workspace-docker-stop {
num_containers_running=$(docker ps -q | wc -l)
if [[ $num_containers_running -gt 0 ]]; then
docker stop $(docker ps -q)
fi
}
function workspace-initialize-env {
workspace-welcome
if [ -f "./tools/configure-hostnames.sh" ]; then
sudo ./tools/configure-hostnames.sh
fi
# Needed to run ES containers
# See https://github.com/Sage-Bionetworks/sage-monorepo/issues/1899
sudo sysctl -w vm.max_map_count=262144 1> /dev/null
# Prevent Corepack showing the URL when it needs to download software
# https://github.com/nodejs/corepack/blob/main/README.md#environment-variables
export COREPACK_ENABLE_DOWNLOAD_PROMPT="0"
}
function workspace-nuke-venv {
find . -name ".venv" -print0 | xargs -0 rm -fr
}