@@ -58,33 +58,33 @@ function test_push() {
5858
5959 # Push multiple branches
6060 setup_cache " org/repo:heads/change:e9009d51dd6da2c363d1d14779c53dd27fcb0c52" \
61- " org/repo:heads/nochange:a5984bb887dd2fcdc2892cd906d6f004844d1142"
61+ " org/repo:heads/nochange:a5984bb887dd2fcdc2892cd906d6f004844d1142"
6262 setup_dest " org/repo:heads/change:a5984bb887dd2fcdc2892cd906d6f004844d1142" \
63- " org/repo:heads/nochange:a5984bb887dd2fcdc2892cd906d6f004844d1142"
63+ " org/repo:heads/nochange:a5984bb887dd2fcdc2892cd906d6f004844d1142"
6464
6565 push " pushing multiple branches"
6666 assert_dest_sha " org/repo" " heads/change" " e9009d51dd6da2c363d1d14779c53dd27fcb0c52" " updating org/repo:heads/change to new commit"
6767 assert_dest_sha " org/repo" " heads/nochange" " a5984bb887dd2fcdc2892cd906d6f004844d1142" " leaving org/repo:heads/nochange at existing commit"
6868
6969 # Pushing multiple branches and tags
7070 setup_cache " org/repo:heads/main:e9009d51dd6da2c363d1d14779c53dd27fcb0c52" \
71- " org/repo:tags/v1:e9009d51dd6da2c363d1d14779c53dd27fcb0c52"
71+ " org/repo:tags/v1:e9009d51dd6da2c363d1d14779c53dd27fcb0c52"
7272 setup_dest " org/repo:heads/main:a5984bb887dd2fcdc2892cd906d6f004844d1142" \
73- " org/repo:tags/v1:a5984bb887dd2fcdc2892cd906d6f004844d1142"
73+ " org/repo:tags/v1:a5984bb887dd2fcdc2892cd906d6f004844d1142"
7474
7575 push " pushing multiple branches and tags"
7676 assert_dest_sha " org/repo" " heads/main" " e9009d51dd6da2c363d1d14779c53dd27fcb0c52" " updating org/repo:heads/main to new commit"
7777 assert_dest_sha " org/repo" " tags/v1" " e9009d51dd6da2c363d1d14779c53dd27fcb0c52" " updating org/repo:tags/v1 to new commit"
7878
7979 # Pushing multiple repositories
8080 setup_cache " org1/repo1:heads/main:e9009d51dd6da2c363d1d14779c53dd27fcb0c52" \
81- " org1/repo2:heads/main:e9009d51dd6da2c363d1d14779c53dd27fcb0c52" \
82- " org1/repo2:tags/v1:e9009d51dd6da2c363d1d14779c53dd27fcb0c52" \
83- " org2/repo1:heads/main:e9009d51dd6da2c363d1d14779c53dd27fcb0c52"
81+ " org1/repo2:heads/main:e9009d51dd6da2c363d1d14779c53dd27fcb0c52" \
82+ " org1/repo2:tags/v1:e9009d51dd6da2c363d1d14779c53dd27fcb0c52" \
83+ " org2/repo1:heads/main:e9009d51dd6da2c363d1d14779c53dd27fcb0c52"
8484 setup_dest " org1/repo1:heads/main:a5984bb887dd2fcdc2892cd906d6f004844d1142" \
85- " org1/repo2:heads/main:a5984bb887dd2fcdc2892cd906d6f004844d1142" \
86- " org1/repo2:tags/v1:a5984bb887dd2fcdc2892cd906d6f004844d1142" \
87- " org2/repo1:heads/main:a5984bb887dd2fcdc2892cd906d6f004844d1142"
85+ " org1/repo2:heads/main:a5984bb887dd2fcdc2892cd906d6f004844d1142" \
86+ " org1/repo2:tags/v1:a5984bb887dd2fcdc2892cd906d6f004844d1142" \
87+ " org2/repo1:heads/main:a5984bb887dd2fcdc2892cd906d6f004844d1142"
8888
8989 push " pushing multiple repositories"
9090 assert_dest_sha " org1/repo1" " heads/main" " e9009d51dd6da2c363d1d14779c53dd27fcb0c52" " updating org1/repo1:heads/main to new commit"
@@ -94,9 +94,9 @@ function test_push() {
9494
9595 # Honor --repo-name flag, ignore other cache entries
9696 setup_cache " org/repo1:heads/main:e9009d51dd6da2c363d1d14779c53dd27fcb0c52" \
97- " org/repo2:heads/main:e9009d51dd6da2c363d1d14779c53dd27fcb0c52"
97+ " org/repo2:heads/main:e9009d51dd6da2c363d1d14779c53dd27fcb0c52"
9898 setup_dest " org/repo1:heads/main:a5984bb887dd2fcdc2892cd906d6f004844d1142" \
99- " org/repo2:heads/main:a5984bb887dd2fcdc2892cd906d6f004844d1142"
99+ " org/repo2:heads/main:a5984bb887dd2fcdc2892cd906d6f004844d1142"
100100
101101 push2args --repo-name " org/repo1" " pushing only one of the repos in the cache"
102102 assert_dest_sha " org/repo1" " heads/main" " e9009d51dd6da2c363d1d14779c53dd27fcb0c52" " updating org/repo1 passed in repo flag"
@@ -191,9 +191,9 @@ function test_sync() {
191191
192192 # Honor --repo-name flag, ignore other cache entries
193193 setup_cache " org/repo1:heads/main:e9009d51dd6da2c363d1d14779c53dd27fcb0c52" \
194- " org/repo2:heads/main:e9009d51dd6da2c363d1d14779c53dd27fcb0c52"
194+ " org/repo2:heads/main:e9009d51dd6da2c363d1d14779c53dd27fcb0c52"
195195 setup_dest " org/repo1:heads/main:a5984bb887dd2fcdc2892cd906d6f004844d1142" \
196- " org/repo2:heads/main:a5984bb887dd2fcdc2892cd906d6f004844d1142"
196+ " org/repo2:heads/main:a5984bb887dd2fcdc2892cd906d6f004844d1142"
197197
198198 sync --repo-name " org/repo1" " syncing only one of the repos in the cache"
199199 assert_dest_sha " org/repo1" " heads/main" " e9009d51dd6da2c363d1d14779c53dd27fcb0c52" " updating org/repo1 passed in repo flag"
@@ -208,15 +208,15 @@ function before_suite() {
208208 rm -rf test/tmp
209209 mkdir -p test/tmp/dest
210210 mkdir -p test/tmp/src
211- ) > /dev/null
211+ ) > /dev/null
212212
213213 git daemon \
214214 --reuseaddr \
215215 --verbose \
216216 --export-all \
217217 --enable=receive-pack \
218218 --port=" $SRC_GIT_DAEMON_PORT " \
219- --base-path=test/tmp/src & > $SRC_GIT_DAEMON_OUTPUT &
219+ --base-path=test/tmp/src & > $SRC_GIT_DAEMON_OUTPUT &
220220 SRC_GIT_DAEMON_PID=$!
221221
222222 git daemon \
@@ -225,12 +225,24 @@ function before_suite() {
225225 --export-all \
226226 --enable=receive-pack \
227227 --port=" $DEST_GIT_DAEMON_PORT " \
228- --base-path=test/tmp/dest & > $DEST_GIT_DAEMON_OUTPUT &
228+ --base-path=test/tmp/dest & > $DEST_GIT_DAEMON_OUTPUT &
229229 DEST_GIT_DAEMON_PID=$!
230230
231+ # wait for the git daemons to start before continuing
232+
233+ if ! check_git_daemon $SRC_GIT_DAEMON_PORT ; then
234+ echo " timeout waiting for src git daemon to start"
235+ exit 1
236+ fi
237+
238+ if ! check_git_daemon $DEST_GIT_DAEMON_PORT ; then
239+ echo " timeout waiting for dest git daemon to start"
240+ exit 1
241+ fi
242+
231243 go run test/github.go \
232244 -p " $DEST_API_PORT " \
233- -git-daemon-url " git://localhost:$DEST_GIT_DAEMON_PORT /" & > $DEST_API_OUTPUT &
245+ -git-daemon-url " git://localhost:$DEST_GIT_DAEMON_PORT /" & > $DEST_API_OUTPUT &
234246 DEST_API_PID=$!
235247
236248 script/build
@@ -257,7 +269,7 @@ function setup_src() {
257269
258270 local org=$( echo $nwo | cut -d' /' -f1)
259271 mkdir -p test/tmp/src/$org && cp -R test/fixtures/repo.git test/tmp/src/$nwo
260- echo " $sha " > " test/tmp/src/$nwo /refs/$refname "
272+ echo " $sha " > " test/tmp/src/$nwo /refs/$refname "
261273 done
262274}
263275
@@ -270,7 +282,7 @@ function setup_cache() {
270282 local refname=$( echo $r | cut -d' :' -f2)
271283 local sha=$( echo $r | cut -d' :' -f3)
272284 mkdir -p test/tmp/cache/$nwo && cp -R test/fixtures/repo.git test/tmp/cache/$nwo /.git
273- echo " $sha " > " test/tmp/cache/$nwo /.git/refs/$refname "
285+ echo " $sha " > " test/tmp/cache/$nwo /.git/refs/$refname "
274286 done
275287}
276288
@@ -283,13 +295,13 @@ function setup_dest() {
283295 local refname=$( echo $r | cut -d' :' -f2)
284296 local sha=$( echo $r | cut -d' :' -f3)
285297 mkdir -p test/tmp/dest/$nwo && cp -R test/fixtures/repo.git test/tmp/dest/$nwo /.git
286- echo " $sha " > " test/tmp/dest/$nwo /.git/refs/$refname "
298+ echo " $sha " > " test/tmp/dest/$nwo /.git/refs/$refname "
287299 done
288300}
289301
290302function version() {
291303 bin/actions-sync version \
292- & > $OUTPUT ||
304+ & > $OUTPUT ||
293305 fail $1
294306}
295307
@@ -298,7 +310,7 @@ function pull() {
298310 --cache-dir " test/tmp/cache" \
299311 --source-url " git://localhost:$SRC_GIT_DAEMON_PORT " \
300312 " $1 " " $2 " \
301- & > $OUTPUT ||
313+ & > $OUTPUT ||
302314 fail $3
303315}
304316
@@ -308,7 +320,7 @@ function push() {
308320 --disable-push-git-auth \
309321 --destination-token " token" \
310322 --destination-url " http://localhost:$DEST_API_PORT " \
311- & > $OUTPUT ||
323+ & > $OUTPUT ||
312324 fail " $1 "
313325}
314326
@@ -319,7 +331,7 @@ function push2args() {
319331 --destination-token " token" \
320332 --destination-url " http://localhost:$DEST_API_PORT " \
321333 " $1 " " $2 " \
322- & > $OUTPUT ||
334+ & > $OUTPUT ||
323335 fail $3
324336}
325337
@@ -330,7 +342,7 @@ function push_impersonation() {
330342 --destination-token " token" \
331343 --destination-url " http://localhost:$DEST_API_PORT " \
332344 --actions-admin-user $1 \
333- & > $OUTPUT ||
345+ & > $OUTPUT ||
334346 fail " $2 "
335347}
336348
@@ -342,7 +354,7 @@ function sync() {
342354 --destination-token " token" \
343355 --destination-url " http://localhost:$DEST_API_PORT " \
344356 " $1 " " $2 " \
345- & > $OUTPUT ||
357+ & > $OUTPUT ||
346358 fail $3
347359}
348360
@@ -383,6 +395,22 @@ function fail() {
383395 exit 1
384396}
385397
398+ function check_git_daemon {
399+ port=$1
400+ for i in {1..10}; do
401+ process=$( ps aux | grep " git daemon" | grep $port )
402+ if [ -z " $process " ]; then
403+ echo " Waiting for git daemon to start on port $port ..."
404+ sleep 1
405+ else
406+ echo " Git daemon is running on port $port "
407+ return 0
408+ fi
409+ done
410+ echo " Git daemon did not start within the expected time."
411+ return 1
412+ }
413+
386414test_version
387415before_suite
388416test_pull
0 commit comments