summaryrefslogtreecommitdiff
path: root/.ci-make.sh
blob: 03192ef5c9e8c871a7f6f28595a3fa6c0bd5d5c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/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"
		make build
		EXIT_STATUS=$?
		mv gitea ../"$3"
		exit $EXIT_STATUS
		;;
	"submodule-make")
		cd "$2"
		shift;shift
		make "$@"
		exit $?
		;;
	"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"')
					echo "CI pipeline still pending, checking again in $CI_VERIFY_RETRY_TIME seconds..."
					sleep $CI_VERIFY_RETRY_TIME
					;;
				*)
					echo "ERROR: Bad pipeline status $CI_VERIFY"
					exit 1
					;;
			esac
		done
		exit 255
		;;
	"download-binary")
		if [ $CI_COMMIT_TAG ] ; then
			CI_RELEASE_ASSETS=$(curl $CI_VERIFY_API/api/v1/repos/$CI_VERIFY_REPO/releases/tags/$CI_COMMIT_TAG | jq -c '.assets[]' | grep linux-amd64)
			CI_RELEASE_BINARY_URL=$(echo "$CI_RELEASE_ASSETS" | grep linux-amd64\" | jq -r --jsonargs .browser_download_url)
			CI_RELEASE_SHA256=$(curl $(echo "$CI_RELEASE_ASSETS" | grep linux-amd64.sha256\" | jq -r --jsonargs .browser_download_url) | cut -d ' ' -f1)
			wget -nv --content-disposition $CI_RELEASE_BINARY_URL
			DOWNLOAD_SHA256=$(sha256sum forgejo-*-linux-amd64 | cut -d ' ' -f1)
			if [ $CI_RELEASE_SHA256 != $DOWNLOAD_SHA256 ] ; then
				echo "ERROR: Downloaded file didn't match expected SHA256 sum"
				exit 1
			fi
			mv forgejo-*-linux-amd64 $2
			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
		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
			ln -s forgejo.preinst deb/debian/forgejo-bin.preinst
			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
		;;
	"package-build")
		cd deb
		dpkg-buildpackage -b
		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")
		apt update
		apt install -y ./"$2"
		[ -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 GITEA_WORK_DIR=$FORGEJO_HOME \
			forgejo web -q --config /etc/forgejo/app.ini &
		sleep 10
		curl http://localhost:3000/ | grep -A 4 "Powered by Forgejo"
		exit $?
		;;
	"install-repo-test")
		apt update
		apt install -y ./"$2"
		apt update
		apt upgrade -y
		apt update
		apt install "$3"
		sudo -u forgejo USER=forgejo \
			HOME=/var/lib/forgejo GITEA_WORK_DIR=/var/lib/forgejo \
			forgejo web -q --config /etc/fogejo/app.ini &
		sleep 10
		curl http://localhost:3000/ | grep -A 4 "Powered by Forgejo"
		exit $?
		;;
	"verify-data-dir-chmod")
		$DATA_DIR_CHMOD="$(stat -c %a /var/lib/forgejo)"
		if [ "$DATA_DIR_CHMOD" = "750" ]; then
			exit 0
		else
			exit 100
		fi
		;;
	"force-clean-forgejo")
		apt install -y psmisc
		killall forgejo
		exit $?
		;;
	"forgejo-test-deps")
		echo "deb http://deb.debian.org/debian/ bookworm-backports main contrib" > /etc/apt/sources.list.d/backports.list
		apt update
		apt install --no-install-recommends -y git-lfs
		apt install -y -t bookworm-backports golang-1.20
		adduser --quiet --comment forgejo --disabled-password forgejo
		chown -R forgejo:forgejo .
		;;
esac