end-to-end/lib/build.sh
Earl Warren 872e4632bf
lib: retry git fetch a few times
The instance hosting the forgejo repository may be down or very slow
while the build tries to fetch from it, retry a few times instead of
giving up immediately.

A total retry time of 3 * 60 seconds is probably sufficient since
Forgejo startup time is lower than this, even on large instances.
2024-05-19 09:16:55 +02:00

39 lines
899 B
Bash
Executable file

#!/bin/bash
# Copyright 2024 The Forgejo Authors
# SPDX-License-Identifier: MIT
set -ex
SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
version=$1
dir_binaries=$2
v=$(echo $version | sed -E -e 's/^([0-9]+\.[0-9]+).*/\1/')
src=$dir_binaries/src-$v
read url ref semver < $SELF_DIR/../forgejo/sources/$v
if ! test -d $src ; then
mkdir -p $src
cd $src
git init
git remote add origin $url
else
cd $src
fi
if ! [[ "$ref" =~ ^refs/ ]] ; then
ref=refs/heads/$ref
fi
for retry in 1 2 3 ; do
timeout 15m git fetch --update-head-ok origin +$ref:$ref && break
echo "Retry git fetch in 60 seconds"
sleep 60
done
git fetch --update-head-ok origin +$ref:$ref
git switch --force-create $v $ref
export TAGS="bindata sqlite sqlite_unlock_notify" FORGEJO_VERSION=$semver
make deps-backend backend
make generate forgejo
cp -a forgejo $dir_binaries/forgejo-$v-dev