2023-02-06 21:29:43 +11:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
CI_VERIFY_API="https://codeberg.org" # Query the Forgejo API at this URL to check upstream CI status
|
|
|
|
CI_VERIFY_REPO="forgejo/forgejo" # Check this repo at the Forgejo API for upstream CI status
|
|
|
|
CI_VERIFY_RETRY_TIME=120 # How long to wait in seconds before retrying if the pipeline is pending
|
|
|
|
CI_VERIFY_RETRY_COUNT=30 # How many times to retry before giving up if the pipeline is pending
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
"submodule-build")
|
|
|
|
cd "$2"
|
2024-04-29 20:30:06 +10:00
|
|
|
LDFLAGS="$LDFLAGS -X \"code.gitea.io/gitea/modules/setting.StaticRootPath=/usr/share/forgejo\""
|
|
|
|
LDFLAGS="$LDFLAGS -X \"code.gitea.io/gitea/modules/setting.AppWorkPath=/var/lib/forgejo\""
|
|
|
|
LDFLAGS="$LDFLAGS -X \"code.gitea.io/gitea/modules/setting.CustomConf=/etc/forgejo/app.ini\""
|
|
|
|
export LDFLAGS
|
2023-02-06 21:29:43 +11:00
|
|
|
make build
|
|
|
|
EXIT_STATUS=$?
|
|
|
|
mv gitea ../"$3"
|
|
|
|
exit $EXIT_STATUS
|
|
|
|
;;
|
|
|
|
"submodule-make")
|
|
|
|
cd "$2"
|
|
|
|
shift;shift
|
|
|
|
make "$@"
|
|
|
|
exit $?
|
|
|
|
;;
|
2024-04-28 10:55:53 +10:00
|
|
|
"actions-prep")
|
|
|
|
case "$2" in
|
|
|
|
"build-forgejo-deb")
|
|
|
|
APREP_APT_EXTRAS="debhelper devscripts sudo"
|
|
|
|
;;
|
|
|
|
"installtest")
|
|
|
|
APREP_APT_EXTRAS="sudo"
|
|
|
|
;;
|
|
|
|
"")
|
|
|
|
APREP_APT_EXTRAS=
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Invalid argument: $2"
|
|
|
|
exit 98
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
EXIT_TOTAL=0
|
|
|
|
apt update
|
|
|
|
EXIT_TOTAL=$(($EXIT_TOTAL+$?))
|
|
|
|
apt upgrade -y
|
|
|
|
EXIT_TOTAL=$(($EXIT_TOTAL+$?))
|
|
|
|
if [ "$APREP_APT_EXTRAS" ] ; then
|
|
|
|
apt install $APREP_APT_EXTRAS -y
|
|
|
|
EXIT_TOTAL=$(($EXIT_TOTAL+$?))
|
|
|
|
fi
|
|
|
|
ACTIONS_FORGEJOSHA="$(git rev-parse --short=10 HEAD)"
|
|
|
|
if [ "$GITHUB_REF_TYPE" = "tag" ] ; then
|
|
|
|
echo "::set-output name=artifactlabel::$GITHUB_REF_NAME-$ACTIONS_FORGEJOSHA"
|
|
|
|
else
|
|
|
|
echo "::set-output name=artifactlabel::$ACTIONS_FORGEJOSHA"
|
|
|
|
fi
|
|
|
|
echo "::set-output name=forgejosha::$ACTIONS_FORGEJOSHA"
|
|
|
|
exit $EXIT_TOTAL
|
|
|
|
;;
|
2023-02-06 21:29:43 +11:00
|
|
|
"ci-verify")
|
|
|
|
RETRY_LOOPS=0
|
|
|
|
while [ $RETRY_LOOPS -le $CI_VERIFY_RETRY_COUNT ] ; do
|
|
|
|
RETRY_LOOPS=$(($RETRY_LOOPS + 1))
|
|
|
|
CURRENT_COMMIT=$(git submodule status "$2/" | cut -d ' ' -f2)
|
|
|
|
CI_VERIFY=$(curl $CI_VERIFY_API/api/v1/repos/$CI_VERIFY_REPO/commits/$CURRENT_COMMIT/status | jq --jsonargs .state)
|
|
|
|
case "$CI_VERIFY" in
|
|
|
|
'"success"')
|
|
|
|
echo "CI pipeline passed!"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
'"pending"')
|
2023-07-05 16:42:02 +10:00
|
|
|
echo "CI pipeline still pending, checking again in $CI_VERIFY_RETRY_TIME seconds..."
|
|
|
|
sleep $CI_VERIFY_RETRY_TIME
|
2023-02-06 21:29:43 +11:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "ERROR: Bad pipeline status $CI_VERIFY"
|
2024-01-10 10:55:06 +11:00
|
|
|
exit 1
|
2023-02-06 21:29:43 +11:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
exit 255
|
|
|
|
;;
|
|
|
|
"download-binary")
|
2024-04-28 12:52:24 +10:00
|
|
|
if [ "$GITHUB_BASE_REF" ] ; then
|
|
|
|
echo "forgejo actions pull request mode"
|
|
|
|
echo "making sure you didn't break binary builds..."
|
|
|
|
PR_MODE=true
|
|
|
|
fi
|
2024-04-28 10:55:53 +10:00
|
|
|
if [ "$GITHUB_REF_TYPE" = "tag" ] ; then
|
|
|
|
echo "INFO: Forgejo Actions mode!"
|
|
|
|
CI_COMMIT_TAG="$GITHUB_REF_NAME"
|
2024-04-28 12:52:24 +10:00
|
|
|
elif [ "$GITHUB_REF_TYPE" = "branch" ] || [ $PR_MODE ] ; then
|
2024-04-28 10:55:53 +10:00
|
|
|
echo "WARNING: Not building a tag! Simulating it..."
|
|
|
|
echo "(forgejo actions mode)"
|
|
|
|
echo "(this will test the binary packaging without cutting a tag in the package)"
|
|
|
|
echo "Resolving tag..."
|
|
|
|
cd forgejo
|
|
|
|
CI_COMMIT_TAG_RESOLVE=$(git tag --points-at HEAD)
|
|
|
|
if [ ! $CI_COMMIT_TAG_RESOLVE ] ; then
|
|
|
|
echo "Failed to resolve exact tag! Getting as close as we can..."
|
|
|
|
git describe --tags HEAD
|
2024-05-02 11:57:10 +10:00
|
|
|
FORGEJO_CLOSEST_TAG=$(git describe --tags HEAD --abbrev=0)
|
|
|
|
echo "Looking for experimental tag..."
|
|
|
|
EXPERIMENTAL_REPO="forgejo-experimental/forgejo"
|
|
|
|
git remote add experimental $CI_VERIFY_API/$EXPERIMENTAL_REPO
|
|
|
|
git fetch experimental --tags
|
|
|
|
CI_COMMIT_TAG_RESOLVE=$(git tag --points-at HEAD)
|
|
|
|
if [ $CI_COMMIT_TAG_RESOLVE ] ; then
|
|
|
|
CI_VERIFY_REPO=$EXPERIMENTAL_REPO
|
|
|
|
FORGEJO_CLOSEST_TAG=$CI_COMMIT_TAG_RESOLVE
|
|
|
|
echo "Found it! Using experimental tag and downloading binary from $CI_VERIFY_REPO"
|
|
|
|
fi
|
|
|
|
CI_COMMIT_TAG_RESOLVE=$FORGEJO_CLOSEST_TAG
|
2024-04-28 10:55:53 +10:00
|
|
|
echo "Closest existing tag: $CI_COMMIT_TAG_RESOLVE"
|
2024-04-29 15:32:13 +10:00
|
|
|
if [ "$CI_COMMIT_TAG_RESOLVE" != "${CI_COMMIT_TAG_RESOLVE%"-dev"}" ] || [ ! "$CI_COMMIT_TAG_RESOLVE" ] ; then
|
2024-04-28 12:52:24 +10:00
|
|
|
if [ $PR_MODE ] ; then
|
|
|
|
echo "I can't figure out which release version of Forgejo to build your PR against."
|
|
|
|
echo "Whatever you're trying to do is not yet implemented."
|
|
|
|
exit 97
|
|
|
|
fi
|
2024-04-29 15:32:13 +10:00
|
|
|
echo "err! unable to resolve tag or building dev version- skipping binary dl"
|
2024-04-28 12:52:24 +10:00
|
|
|
CI_COMMIT_TAG_RESOLVE=
|
|
|
|
fi
|
2024-04-28 10:55:53 +10:00
|
|
|
fi
|
|
|
|
cd ..
|
|
|
|
echo "Proceeding with resolved tag: $CI_COMMIT_TAG_RESOLVE"
|
|
|
|
CI_COMMIT_TAG="$CI_COMMIT_TAG_RESOLVE"
|
|
|
|
fi
|
2023-02-06 21:29:43 +11:00
|
|
|
if [ $CI_COMMIT_TAG ] ; then
|
2024-06-15 11:52:44 +10:00
|
|
|
CI_RELEASE_ASSETS=$(curl $CI_VERIFY_API/api/v1/repos/$CI_VERIFY_REPO/releases/tags/$CI_COMMIT_TAG | jq -c '.assets[]' | grep linux-arm64)
|
|
|
|
CI_RELEASE_BINARY_URL=$(echo "$CI_RELEASE_ASSETS" | grep linux-arm64\" | jq -r --jsonargs .browser_download_url)
|
|
|
|
CI_RELEASE_SHA256=$(curl $(echo "$CI_RELEASE_ASSETS" | grep linux-arm64.sha256\" | jq -r --jsonargs .browser_download_url) | cut -d ' ' -f1)
|
2023-09-10 05:27:52 +10:00
|
|
|
wget -nv --content-disposition $CI_RELEASE_BINARY_URL
|
2024-06-15 11:52:44 +10:00
|
|
|
DOWNLOAD_SHA256=$(sha256sum forgejo-*-linux-arm64 | cut -d ' ' -f1)
|
2023-02-06 21:29:43 +11:00
|
|
|
if [ $CI_RELEASE_SHA256 != $DOWNLOAD_SHA256 ] ; then
|
|
|
|
echo "ERROR: Downloaded file didn't match expected SHA256 sum"
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-06-15 11:52:44 +10:00
|
|
|
mv forgejo-*-linux-arm64 $2
|
2023-02-06 21:29:43 +11:00
|
|
|
chmod +x $2
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo "not a tag, skipping download"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"package-prep")
|
|
|
|
mkdir deb/forgejo-bin
|
|
|
|
mkdir deb/forgejo-sqlite-bin
|
|
|
|
mv forgejo-bin deb/forgejo-bin/forgejo
|
|
|
|
mv forgejo-sqlite-bin deb/forgejo-sqlite-bin/forgejo
|
2024-04-29 20:30:06 +10:00
|
|
|
cp -r forgejo/public deb/public
|
|
|
|
cp -r forgejo/templates deb/templates
|
|
|
|
cp -r forgejo/options deb/options
|
2023-02-06 21:29:43 +11:00
|
|
|
if [ -x forgejo-bin-dl ] ; then
|
|
|
|
mkdir deb/forgejo-bin-dl
|
|
|
|
mv forgejo-bin-dl deb/forgejo-bin-dl/forgejo
|
|
|
|
mv deb/.forgejo-bin.install deb/debian/forgejo-bin.install
|
2024-04-29 20:30:06 +10:00
|
|
|
ln -s forgejo-common.preinst deb/debian/forgejo-bin.preinst
|
2023-02-06 21:29:43 +11:00
|
|
|
ln -s forgejo.postinst deb/debian/forgejo-bin.postinst
|
|
|
|
ln -s forgejo.prerm deb/debian/forgejo-bin.prerm
|
|
|
|
echo >> deb/debian/control
|
|
|
|
cat deb/.forgejo-bin.control >> deb/debian/control
|
|
|
|
fi
|
|
|
|
;;
|
2024-04-28 10:55:53 +10:00
|
|
|
"package-build-deps")
|
|
|
|
cd deb
|
|
|
|
mk-build-deps --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y" --remove
|
|
|
|
exit $?
|
|
|
|
;;
|
2023-02-06 21:29:43 +11:00
|
|
|
"package-build")
|
|
|
|
cd deb
|
2024-04-28 10:55:53 +10:00
|
|
|
if [ "$2" = "actions" ] ; then
|
|
|
|
PACKAGE_BUILD_EXTRA_ARGS="--no-sign"
|
|
|
|
fi
|
|
|
|
dpkg-buildpackage -b $PACKAGE_BUILD_EXTRA_ARGS
|
2023-02-06 21:29:43 +11:00
|
|
|
exit $?
|
|
|
|
;;
|
|
|
|
"package-clean")
|
|
|
|
rm *dbgsym*.deb || true
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
"pkg-gen-sha256")
|
|
|
|
for deb in *.deb ; do
|
|
|
|
sha256sum $deb > $deb.sha256
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
"preview-sha256")
|
|
|
|
for p in *.sha256 ; do
|
|
|
|
echo $p
|
|
|
|
cat $p
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
"test-userinst-prep")
|
|
|
|
cp ./etc/default/forgejo /etc/default/forgejo
|
|
|
|
mkdir -p /etc/systemd/system/forgejo.service.d
|
|
|
|
cp ./etc/systemd/system/forgejo.service.d/override.conf /etc/systemd/system/forgejo.service.d/override.conf
|
|
|
|
;;
|
|
|
|
"install-run-test")
|
2024-01-17 09:43:36 +11:00
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
2023-04-30 12:37:19 +10:00
|
|
|
apt update
|
2024-04-29 20:30:06 +10:00
|
|
|
if [ "$2" = "${2#"./forgejo-bin_"}" ] ; then
|
|
|
|
APT_FORGEJO_COMMON_RESOLVE="$(ls -1 ./forgejo-common_*_all.deb)"
|
|
|
|
if [ -f "$APT_FORGEJO_COMMON_RESOLVE" ] ; then
|
|
|
|
APT_FORGEJO_COMMON="./$APT_FORGEJO_COMMON_RESOLVE"
|
|
|
|
else
|
|
|
|
echo "ERR! Unable to find the necessary forgejo-common package!"
|
|
|
|
exit 96
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
apt install -y $APT_FORGEJO_COMMON ./"$2"
|
|
|
|
if [ -f "/etc/default/forgejo" ] || [ "$2" != "${2#"./forgejo-bin_"}" ] ; then
|
|
|
|
[ -f "/etc/default/forgejo" ] && . /etc/default/forgejo
|
|
|
|
[ -z "$FORGEJO_HOME" ] && FORGEJO_HOME=/var/lib/forgejo
|
|
|
|
[ -z "$FORGEJO_USER" ] && FORGEJO_USER=forgejo
|
|
|
|
sudo -u $FORGEJO_USER USER=$FORGEJO_USER \
|
|
|
|
HOME=$FORGEJO_HOME FORGEJO_WORK_DIR=$FORGEJO_HOME \
|
|
|
|
forgejo web -q --config /etc/forgejo/app.ini &
|
|
|
|
else
|
|
|
|
echo "No env setup! Run testing defaults using hardcoded vars..."
|
|
|
|
sudo -u forgejo USER=forgejo forgejo web -q &
|
|
|
|
fi
|
2023-02-06 21:29:43 +11:00
|
|
|
sleep 10
|
2023-09-10 05:27:52 +10:00
|
|
|
curl http://localhost:3000/ | grep -A 4 "Powered by Forgejo"
|
2023-02-06 21:29:43 +11:00
|
|
|
exit $?
|
|
|
|
;;
|
2023-07-03 07:46:48 +10:00
|
|
|
"install-repo-test")
|
2023-11-26 12:56:25 +11:00
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
apt update -qq
|
2024-01-17 09:24:20 +11:00
|
|
|
apt install -y apt-utils apt-listchanges
|
2023-07-03 07:46:48 +10:00
|
|
|
apt install -y ./"$2"
|
2023-11-26 12:56:25 +11:00
|
|
|
apt update -qq
|
2023-07-03 07:46:48 +10:00
|
|
|
apt upgrade -y
|
2023-11-26 12:56:25 +11:00
|
|
|
apt update -qq
|
2024-03-24 05:50:19 +11:00
|
|
|
apt install -y "$3"
|
2023-07-03 07:46:48 +10:00
|
|
|
sudo -u forgejo USER=forgejo \
|
2024-04-29 17:52:58 +10:00
|
|
|
HOME=/var/lib/forgejo FORGEJO_WORK_DIR=/var/lib/forgejo \
|
2023-09-10 05:55:59 +10:00
|
|
|
forgejo web -q --config /etc/fogejo/app.ini &
|
2023-07-03 07:46:48 +10:00
|
|
|
sleep 10
|
2023-09-10 05:55:59 +10:00
|
|
|
curl http://localhost:3000/ | grep -A 4 "Powered by Forgejo"
|
2023-07-03 07:46:48 +10:00
|
|
|
exit $?
|
|
|
|
;;
|
2023-11-26 11:12:14 +11:00
|
|
|
"verify-data-dir-chmod")
|
2023-11-26 12:36:45 +11:00
|
|
|
DATA_DIR_CHMOD="$(stat -c %a /var/lib/forgejo)"
|
2023-11-26 11:12:14 +11:00
|
|
|
if [ "$DATA_DIR_CHMOD" = "750" ]; then
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
exit 100
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"force-clean-forgejo")
|
2023-11-26 12:56:25 +11:00
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
2023-11-26 11:12:14 +11:00
|
|
|
apt install -y psmisc
|
|
|
|
killall forgejo
|
|
|
|
exit $?
|
|
|
|
;;
|
2023-11-26 11:37:24 +11:00
|
|
|
"forgejo-test-deps")
|
2023-11-26 12:00:32 +11:00
|
|
|
echo "deb http://deb.debian.org/debian/ bookworm-backports main contrib" > /etc/apt/sources.list.d/backports.list
|
2023-11-26 12:56:25 +11:00
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
apt update -qq
|
|
|
|
apt install -qq --no-install-recommends -y git-lfs
|
2024-01-10 12:27:35 +11:00
|
|
|
apt install -qq -y -t bookworm-backports golang-$DEP_GOLANG_VER
|
|
|
|
ln -sf /usr/lib/go-$DEP_GOLANG_VER/bin/go /usr/local/bin/go
|
2023-11-26 11:37:24 +11:00
|
|
|
adduser --quiet --comment forgejo --disabled-password forgejo
|
|
|
|
chown -R forgejo:forgejo .
|
2024-04-09 21:49:38 +10:00
|
|
|
if [ "$DEP_GOLANG_NODEB_REV" ];then
|
2024-04-09 22:57:35 +10:00
|
|
|
su forgejo -c "./.ci-make.sh forgejo-test-deps_upgrade-go $DEP_GOLANG_VER $DEP_GOLANG_NODEB_REV"
|
2024-04-09 21:49:38 +10:00
|
|
|
fi
|
2023-11-26 11:37:24 +11:00
|
|
|
;;
|
2024-04-09 22:57:35 +10:00
|
|
|
"forgejo-test-deps_upgrade-go")
|
|
|
|
go install golang.org/dl/go$2.$3@latest
|
|
|
|
ln -s ~/go/bin/go$2.$3 ~/go/bin/go
|
|
|
|
export PATH="$HOME/go/bin:$PATH"
|
|
|
|
go download
|
|
|
|
go version
|
|
|
|
;;
|
2023-02-06 21:29:43 +11:00
|
|
|
esac
|
|
|
|
|