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/releases/0.1.0/gitroot-0.1.0-linux-amd64 && 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 " name: ladybug" >> .gitroot/plugins.yml
140echo "- url: '/tmp/testUpdate/silo-0.0.1.wasm'" >> .gitroot/plugins.yml
141echo " name: silo" >> .gitroot/plugins.yml
142echo "- url: '/tmp/testUpdate/grafter-0.0.1.wasm'" >> .gitroot/plugins.yml
143echo " name: grafter" >> .gitroot/plugins.yml
144echo "- url: '/tmp/testUpdate/apex-0.0.1.wasm'" >> .gitroot/plugins.yml
145echo " name: apex" >> .gitroot/plugins.yml
146quiet_git add .
147quiet_git commit -m "init plugins"
148quiet_git push origin main
149
150wait_ls "${SERVER_DATA_DIR}/data/plugins/ladybug" 3
151wait_ls "${SERVER_DATA_DIR}/data/plugins/silo" 3
152wait_ls "${SERVER_DATA_DIR}/data/plugins/grafter" 3
153wait_ls "${SERVER_DATA_DIR}/data/plugins/apex" 3
154
155quiet_git pull origin main
156
157sed -i -e 's/active: false/active: true/g' .gitroot/plugins.yml
158quiet_git add .
159quiet_git commit -m "active plugins"
160quiet_git push origin main
161
162mySleep 0.5
163
164quiet_git pull origin main
165
166mkdir issues
167for (( i=0; i<=10; i++ ))
168do
169 echo "my issue $i" >> issues/$i.md
170done
171quiet_git add .
172quiet_git commit -m "create 10 issues"
173quiet_git push origin main
174
175mySleep 0.5
176
177quiet_git pull origin main
178
179report "🏁 kill and launch new gitroot"
180APP=$(lsof -i tcp:${SERVER_PORT} | awk 'NR!=1 {print $2}')
181if [ -z "$APP" ]; then
182 report "🟢 Gitroot not launched"
183else
184 kill ${APP}
185 report "🟢 Gitroot killed"
186fi
187
188cd ${SCRIPT_DIR}/../server
189GIT_TRACE_PACKET=false go run -race . -data="${SERVER_DATA_DIR}" &>> /tmp/mylog.txt &
190
191mySleep 3
192
193cd /tmp/${ROOT_REPO_NAME}
194
195sed -i -e 's/ladybug-0.0.1.wasm/ladybug-0.0.2.wasm/g' .gitroot/plugins.yml
196sed -i -e 's/silo-0.0.1.wasm/silo-0.0.2.wasm/g' .gitroot/plugins.yml
197sed -i -e 's/grafter-0.0.1.wasm/grafter-0.0.2.wasm/g' .gitroot/plugins.yml
198sed -i -e 's/apex-0.0.1.wasm/apex-0.0.2.wasm/g' .gitroot/plugins.yml
199echo "- url: '/tmp/testUpdate/pollen-0.0.1.wasm'" >> .gitroot/plugins.yml
200echo " active: true" >> .gitroot/plugins.yml
201quiet_git add .
202quiet_git commit -m "update plugins"
203quiet_git push origin main
204
205wait_ls "${SERVER_DATA_DIR}/data/plugins/ladybug" 4
206wait_ls "${SERVER_DATA_DIR}/data/plugins/silo" 4
207wait_ls "${SERVER_DATA_DIR}/data/plugins/grafter" 4
208wait_ls "${SERVER_DATA_DIR}/data/plugins/apex" 4
209wait_ls "${SERVER_DATA_DIR}/data/plugins/pollen" 3
210
211mySleep 12
212
213quiet_git pull origin main
214
215for (( i=0; i<=10; i++ ))
216do
217 echo "my issue $i second" >> issues/$i.md
218done
219quiet_git add .
220quiet_git commit -m "update 10 issues"
221quiet_git push origin main
222
223mySleep 0.5
224
225quiet_git pull origin main
226
227report "🏁 create $REPO1_NAME"
228
229echo "$REPO1_NAME:" >> .gitroot/repositories.yml
230echo " defaultbranch: main" >> .gitroot/repositories.yml
231quiet_git add .
232quiet_git commit -m "create $REPO1_NAME"
233quiet_git push origin main
234
235mySleep 0.5
236
237quiet_git pull origin main
238
239cd /tmp
240quiet_git clone --quiet -c "core.sshCommand=ssh -i ${SSH_KEY} -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new" ${REPO1_URL}
241cd ${REPO1_NAME}
242.gitroot/init.sh --pubKey "${SSH_KEY}.pub" --privKey "${SSH_KEY}" --email forgeConfig@gitroot.dev --name forgeConfig >> /tmp/mylog.txt
243quiet_git add .
244quiet_git commit -m "init user"
245quiet_git push origin main
246
247if grep -q -i "version: 0.0.2" .gitroot/plugins.yml
248then
249 report "🟢 Plugins version ok"
250else
251 report "🛑 Plugins need to contains 0.0.2"
252 EXIT_CODE=1
253fi