GitRoot
craft your forge, build your project, grow your community freely
1#!/usr/bin/env bash
2
3# SPDX-FileCopyrightText: 2025 Romain Maneschi <romain@gitroot.dev>
4#
5# SPDX-License-Identifier: EUPL-1.2
6
7trap 'catch $LINENO' ERR
8
9EXPECTED_ERROR=0
10
11catch() {
12 if [[ $EXPECTED_ERROR == 0 ]]; then
13 echo "🛑 unexpected error line $1"
14 exit 1
15 fi
16 report "🟢 expected err line $1"
17}
18
19quiet_git() {
20 echo "🚀 git $@" >> /tmp/mylog.txt
21 GIT_TRACE=false GIT_TRACE_PACKET=false git "$@" &>> /tmp/mylog.txt
22}
23
24report() {
25 echo "$1" >> /tmp/mylog.txt
26 echo "$1"
27}
28
29mySleep() {
30 echo "🕐 $1" >> /tmp/mylog.txt
31 sleep $1
32}
33
34function wait_for() {
35 start=`date +%s`
36 timeout=100
37 until [ $timeout -le 0 ] || (grep -q $1 $2 &> /dev/null); do
38 sleep 0.1
39 timeout=$(( timeout - 1 ))
40 done
41 if [ $timeout -le 0 ]; then
42 return 1
43 fi
44 end=`date +%s`
45 echo "🕐 $@ in `expr $end - $start` seconds"
46}
47
48function wait_ls() {
49 start=`date +%s`
50 timeout=100
51 until [ $timeout -le 0 ] || [ $(ls $1 | wc -l) -eq $2 ]; do
52 sleep 0.1
53 timeout=$(( timeout - 1 ))
54 done
55 if [ $timeout -le 0 ]; then
56 return 1
57 fi
58 end=`date +%s`
59 echo "🕐 $@ in `expr $end - $start` seconds"
60 mySleep 0.3
61}
62
63EXIT_CODE=0
64
65SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
66
67SERVER_PORT="4545"
68SERVER_URL=${1:-"127.0.0.1:$SERVER_PORT"}
69SERVER_DATA_DIR="/tmp/gitrootData"
70
71ROOT_REPO_NAME="root"
72ROOT_REPO_URL="ssh://user@${SERVER_URL}/${ROOT_REPO_NAME}"
73REPO1_NAME="repo1"
74REPO1_URL="ssh://user@${SERVER_URL}/${REPO1_NAME}"
75REPO2_NAME="repo2"
76REPO2_URL="ssh://user@${SERVER_URL}/${REPO2_NAME}"
77REPO3_NAME="repo3"
78REPO3_URL="ssh://user@${SERVER_URL}/${REPO3_NAME}"
79
80SSH_KEY="${SCRIPT_DIR}/user1/ed25519"
81SSH_KEY2="${SCRIPT_DIR}/user2/ed25519"
82
83##### clean
84report "🏁 clean"
85
86cd /tmp
87rm -rf ${SERVER_DATA_DIR}
88rm -rf ${ROOT_REPO_NAME}
89rm -rf ${ROOT_REPO_NAME}_2
90rm -rf ${REPO1_NAME}
91rm -rf ${REPO2_NAME}
92rm -rf ${REPO1_NAME}_2
93rm -rf ${REPO2_NAME}_2
94rm -rf ${REPO3_NAME}
95rm -f /tmp/mylog.txt
96APP=$(lsof -i tcp:${SERVER_PORT} | awk 'NR!=1 {print $2}')
97if [ -z "$APP" ]; then
98 report "🟢 Gitroot not launched"
99else
100 kill ${APP}
101 report "🟢 Gitroot killed"
102fi
103ssh-keygen -f "$HOME/.ssh/known_hosts" -R "[127.0.0.1]:$SERVER_PORT"
104
105##### launch gitroot
106report "🏁 launch gitroot 0.1.0"
107
108if [ ! -f "/tmp/testUpdate/gitroot" ]; then
109 mkdir /tmp/testUpdate
110 cd /tmp/testUpdate
111
112 wget -O gitroot https://gitroot.dev/gitroot-0.1.0 && chmod +x gitroot && ./gitroot --initConfig ./conf.yml
113
114 wget https://gitroot.dev/ladybug-0.0.1.wasm
115 wget https://gitroot.dev/silo-0.0.1.wasm
116 wget https://gitroot.dev/grafter-0.0.1.wasm
117 wget https://gitroot.dev/apex-0.0.1.wasm
118
119 cp ${SCRIPT_DIR}/../plugins/*/*-0.0.2.wasm /tmp/testUpdate/
120 cp ${SCRIPT_DIR}/../plugins/pollen/*-0.0.1.wasm /tmp/testUpdate/
121fi
122
123/tmp/testUpdate/gitroot --config /tmp/testUpdate/conf.yml -data="${SERVER_DATA_DIR}" &>> /tmp/mylog.txt &
124wait_for "starting SSH server on" /tmp/mylog.txt
125
126##### forgeConfig
127report "🏁 forgeConfig"
128
129cd /tmp
130quiet_git clone --quiet -c "core.sshCommand=ssh -i ${SSH_KEY} -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new" ${ROOT_REPO_URL}
131cd ${ROOT_REPO_NAME}
132.gitroot/init.sh --pubKey "${SSH_KEY}.pub" --privKey "${SSH_KEY}" --email forgeConfig@gitroot.dev --name forgeConfig >> /tmp/mylog.txt
133
134##### install plugins
135report "🏁 install plugins"
136
137cd /tmp/${ROOT_REPO_NAME}
138echo "- url: '/tmp/testUpdate/ladybug-0.0.1.wasm'" >> .gitroot/plugins.yml
139echo " crc32: null" >> .gitroot/plugins.yml
140echo " name: ladybug" >> .gitroot/plugins.yml
141echo "- url: '/tmp/testUpdate/silo-0.0.1.wasm'" >> .gitroot/plugins.yml
142echo " crc32: null" >> .gitroot/plugins.yml
143echo " name: silo" >> .gitroot/plugins.yml
144echo "- url: '/tmp/testUpdate/grafter-0.0.1.wasm'" >> .gitroot/plugins.yml
145echo " crc32: null" >> .gitroot/plugins.yml
146echo " name: grafter" >> .gitroot/plugins.yml
147echo "- url: '/tmp/testUpdate/apex-0.0.1.wasm'" >> .gitroot/plugins.yml
148echo " crc32: null" >> .gitroot/plugins.yml
149echo " name: apex" >> .gitroot/plugins.yml
150quiet_git add .
151quiet_git commit -m "init plugins"
152quiet_git push origin main
153
154wait_ls "${SERVER_DATA_DIR}/data/plugins/ladybug" 3
155wait_ls "${SERVER_DATA_DIR}/data/plugins/silo" 3
156wait_ls "${SERVER_DATA_DIR}/data/plugins/grafter" 3
157wait_ls "${SERVER_DATA_DIR}/data/plugins/apex" 3
158
159quiet_git pull origin main
160
161sed -i -e 's/active: false/active: true/g' .gitroot/plugins.yml
162quiet_git add .
163quiet_git commit -m "active plugins"
164quiet_git push origin main
165
166mySleep 0.5
167
168quiet_git pull origin main
169
170mkdir issues
171for (( i=0; i<=10; i++ ))
172do
173 echo "my issue $i" >> issues/$i.md
174done
175quiet_git add .
176quiet_git commit -m "create 10 issues"
177quiet_git push origin main
178
179mySleep 0.5
180
181quiet_git pull origin main
182
183report "🏁 kill and launch new gitroot"
184APP=$(lsof -i tcp:${SERVER_PORT} | awk 'NR!=1 {print $2}')
185if [ -z "$APP" ]; then
186 report "🟢 Gitroot not launched"
187else
188 kill ${APP}
189 report "🟢 Gitroot killed"
190fi
191
192cd ${SCRIPT_DIR}/../server
193GIT_TRACE_PACKET=false go run -race . -data="${SERVER_DATA_DIR}" &>> /tmp/mylog.txt &
194
195mySleep 3
196
197cd /tmp/${ROOT_REPO_NAME}
198
199sed -i -e 's/ladybug-0.0.1.wasm/ladybug-0.0.2.wasm/g' .gitroot/plugins.yml
200sed -i -e 's/silo-0.0.1.wasm/silo-0.0.2.wasm/g' .gitroot/plugins.yml
201sed -i -e 's/grafter-0.0.1.wasm/grafter-0.0.2.wasm/g' .gitroot/plugins.yml
202sed -i -e 's/apex-0.0.1.wasm/apex-0.0.2.wasm/g' .gitroot/plugins.yml
203echo "- url: '/tmp/testUpdate/pollen-0.0.1.wasm'" >> .gitroot/plugins.yml
204echo " crc32: null" >> .gitroot/plugins.yml
205echo " name: pollen" >> .gitroot/plugins.yml
206echo " active: true" >> .gitroot/plugins.yml
207quiet_git add .
208quiet_git commit -m "update plugins"
209quiet_git push origin main
210
211wait_ls "${SERVER_DATA_DIR}/data/plugins/ladybug" 4
212wait_ls "${SERVER_DATA_DIR}/data/plugins/silo" 4
213wait_ls "${SERVER_DATA_DIR}/data/plugins/grafter" 4
214wait_ls "${SERVER_DATA_DIR}/data/plugins/apex" 4
215wait_ls "${SERVER_DATA_DIR}/data/plugins/pollen" 3
216
217mySleep 12
218
219quiet_git pull origin main
220
221for (( i=0; i<=10; i++ ))
222do
223 echo "my issue $i second" >> issues/$i.md
224done
225quiet_git add .
226quiet_git commit -m "update 10 issues"
227quiet_git push origin main
228
229mySleep 0.5
230
231quiet_git pull origin main
232
233report "🏁 create $REPO1_NAME"
234
235echo "$REPO1_NAME:" >> .gitroot/repositories.yml
236echo " defaultbranch: main" >> .gitroot/repositories.yml
237quiet_git add .
238quiet_git commit -m "create $REPO1_NAME"
239quiet_git push origin main
240
241mySleep 0.5
242
243quiet_git pull origin main
244
245cd /tmp
246quiet_git clone --quiet -c "core.sshCommand=ssh -i ${SSH_KEY} -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new" ${REPO1_URL}
247cd ${REPO1_NAME}
248.gitroot/init.sh --pubKey "${SSH_KEY}.pub" --privKey "${SSH_KEY}" --email forgeConfig@gitroot.dev --name forgeConfig >> /tmp/mylog.txt
249quiet_git add .
250quiet_git commit -m "init user"
251quiet_git push origin main
252
253if grep -q -i "version: 0.0.2" .gitroot/plugins.yml
254then
255 report "🟢 Plugins version ok"
256else
257 report "🛑 Plugins need to contains 0.0.2"
258 EXIT_CODE=1
259fi