-
Notifications
You must be signed in to change notification settings - Fork 21
/
devsetup.sh
executable file
·193 lines (158 loc) · 4.43 KB
/
devsetup.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
185
186
187
188
189
190
191
192
193
#!/bin/bash
set -e
# macOS's System Integrity Protection purges the environment variables controlling
# `dyld` when launching protected processes (https://developer.apple.com/library/archive/documentation/Security/Conceptual/System_Integrity_Protection_Guide/RuntimeProtections/RuntimeProtections.html#//apple_ref/doc/uid/TP40016462-CH3-SW1)
# This causes macOS to remove the DYLD_ env variables when running this script, so we have to set them again
if [ ! -z "${FRAGDENSTAAT_DYLD_LIBRARY_PATH:-}" ]; then
export LD_LIBRARY_PATH=${FRAGDENSTAAT_DYLD_LIBRARY_PATH:-}:${LD_LIBRARY_PATH:-}
export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH:${DYLD_LIBRARY_PATH:-}
fi
MAIN=fragdenstaat_de
REPOS=("froide" "froide-campaign" "froide-legalaction" "froide-food" "froide-payment" "froide-crowdfunding" "froide-govplan" "froide-fax" "froide-exam" "django-filingcabinet" "froide-evidencecollection")
FRONTEND=("froide" "froide_food" "froide_exam" "froide_campaign" "froide_payment" "froide_legalaction" "@okfde/filingcabinet")
FRONTEND_DIR=("froide" "froide-food" "froide-exam" "froide-campaign" "froide-payment" "froide-legalaction" "django-filingcabinet")
FROIDE_PEERS=("froide-campaign" "froide-food") # these have peer-dependencies on froide
ask() {
# https://djm.me/ask
local prompt default reply
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi
while true; do
# Ask the question (not using "read -p" as it uses stderr not stdout)
echo -n "$1 [$prompt] "
# Read the answer (use /dev/tty in case stdin is redirected from somewhere else)
read reply </dev/tty
# Default?
if [ -z "$reply" ]; then
reply=$default
fi
# Check if the reply is valid
case "$reply" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac
done
}
install_precommit() {
local repo_dir="$1"
if [ -e "$repo_dir/.pre-commit-config.yaml" ]; then
pushd "$repo_dir"
pre-commit install
popd
fi
}
venv() {
echo "You need python >= 3.10, uv and pnpm installed."
python3 --version
pnpm --version
uv --version
if [ ! -d fds-env ]; then
if ask "Do you want to create a virtual environment using $(python3 --version)?" Y; then
echo "Creating virtual environment with uv and $(python3 --version)"
uv venv fds-env
fi
fi
if [ ! -d fds-env ]; then
echo "Could not find virtual environment fds-env"
fi
}
pull() {
echo "Cloning / installing $MAIN"
if [ ! -d $MAIN ]; then
git clone [email protected]:okfde/$MAIN.git
else
pushd $MAIN
git pull origin "$(git branch --show-current)"
popd
fi
for name in "${REPOS[@]}"; do
if [ ! -d $name ]; then
git clone [email protected]:okfde/$name.git
else
pushd $name
git pull origin "$(git branch --show-current)"
popd
fi
done
}
dependencies() {
source fds-env/bin/activate
echo "Installing $MAIN..."
uv pip install -r $MAIN/requirements-dev.txt
install_precommit "$MAIN"
echo "Cloning / installing all editable dependencies..."
for name in "${REPOS[@]}"; do
uv pip install -e "./$name" --config-setting editable_mode=compat
install_precommit "$name"
done
}
frontend() {
echo "Installing frontend dependencies..."
# we need to link globally since local linking adjusts the lockfile
for name in "${FRONTEND_DIR[@]}"; do
pushd $name
pnpm link --global
popd
done
for name in "${FROIDE_PEERS[@]}"; do
pushd $name
pnpm link --global "froide"
popd
done
for name in "${FRONTEND_DIR[@]}"; do
pushd $name
pnpm install
popd
done
pushd $MAIN
pnpm install
for name in "${FRONTEND[@]}"; do
pnpm link --global "$name"
done
popd
}
upgrade_frontend_repos() {
pnpm update "${FRONTEND[@]}"
}
messages() {
fds-env/bin/python fragdenstaat_de/manage.py compilemessages -l de -i node_modules
}
forall() {
echo "Executing '$@' in all repos"
pushd $MAIN
"$@"
popd
for name in "${REPOS[@]}"; do
pushd $name
"$@"
popd
done
}
help() {
echo "Available commands:"
echo "setup: setup / update all repos"
echo "forall: run command in all repos"
}
if [ -z "$1" ]; then
venv
pull
dependencies
frontend
messages
echo "Done!"
else
if [[ $(type -t "$1") == function ]]; then
"$@"
else
help
exit 1
fi
fi