summaryrefslogtreecommitdiff
blob: 5efdf312b467fdde696b5884e858d7b5459d3a12 (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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/bash

# curl -q -s -F "content=$( bugz -q --key "${APIKEY}" search ""${PACKAGE}" fails test" )" http://dpaste.com/api/v2/ ).txt"

die() {
	echo "${1}"
	exit 1
}

env_update() {
	env-update > /dev/null 2>&1
	source /etc/profile > /dev/null 2>&1
}

update_world() {
	echo -ne "" > /etc/portage/package.use/test
	echo -ne "" > /etc/portage/package.env
	FEATURES="-collision-protect" emerge -DuNq world > /dev/null 2>&1 || die "emerge -DuNq world failed"
	emerge -cq > /dev/null 2>&1 || die "depclean failed"

	if [ -n "$( portageq list_preserved_libs / )" ]
	then
		emerge -q1 @preserved-rebuild > /dev/null 2>&1 || die "preserved-rebuild failed"
	fi

	rm -fr /var/log/emerge.log
}

native-symlinks() {
	echo "sys-devel/gcc-config -native-symlinks" >> /etc/portage/package.use/test
	echo "sys-devel/binutils-config -native-symlinks" >> /etc/portage/package.use/test
	echo "dev-lang/python-exec -native-symlinks" >> /etc/portage/package.use/test
	emerge -q1 sys-devel/gcc-config sys-devel/binutils-config dev-lang/python-exec > /dev/null 2>&1 || die "native-symlinks failed"
	env_update
}

common_merge() {
	SLOTS="$( V='{slotfirst}<slot>\n{}' eix --format '<availableversions::V>' -e "${PACKAGE}" )"
	unset STATUS

	if [ "${SLOTS}" = "No matches found" ]
	then
		SLOTS="0"
	fi

	for SLOT in ${SLOTS}
	do
		rm -fr /var/tmp/portage /root/.packages/"${PACKAGE}"* /root/.packages/dev-python/pandas*

		START_MERGE="$( date +%s )"
		echo "$( date '+%d-%m-%Y %H:%M' ) START ${PACKAGE}:${SLOT} ${MERGETYPE}"
		emerge "${PACKAGE}":"${SLOT}" ${EOPTS} > /dev/null 2>&1
		if [ "${?}" != "0" ] && [ -n "$( find /var/tmp/portage -type l -name "build.log" 2>/dev/null )" ]
		then
			STATUS="fail"
			SHUF="$( shuf -i0000000000000000000-9999999999999999999 -n1 )"
			mkdir -p /root/.failures

			if [ "$( find /var/tmp/portage -type l -name "build.log" | wc -l )" -gt "1" ]
			then
				for FILE in $( find /var/tmp/portage -type l -name "build.log" )
				do
					SHUF="$( shuf -i0000000000000000000-9999999999999999999 -n1 )"
					cp "${FILE}" /root/.failures/"${SHUF}"_main
				done
			elif [ "$( find /var/tmp/portage -type l -name "build.log" | wc -l )" = "1" ]
			then
				cp "$( find /var/tmp/portage -type l -name "build.log" )" /root/.failures/"${SHUF}"_main

				for LOG in ${COMMON_ERROR_LOGS}
				do
					COUNT="1"
					for FULLNAME in $( find /var/tmp/portage -type f -name "${LOG}" )
					do
						FILE="$( basename "${FULLNAME}" )"

						if [ -n "$( grep "${FILE}" /root/.failures/"${SHUF}"_main )" ]
						then
							cp "${FULLNAME}" /root/.failures/"${SHUF}"_"${COUNT}"-"${LOG}"
						fi

						let COUNT++
					done
				done
			fi
		fi
		END_MERGE="$( date +%s )"
		TIME_MERGE="$( date -d@"$( expr "${END_MERGE}" - "${START_MERGE}" )" -u +%H:%M:%S )"

		if [ "$( date -d@"$( expr "${END_MERGE}" - "${START_MERGE}" )" -u +%H%M%S )" -lt "5" ]
		then
			echo ""${PACKAGE}":"${SLOT}"" >> /root/check
			emerge "${PACKAGE}":"${SLOT}" ${EOPTS} >> /root/check 2>&1
			echo -ne "\n\n\n\n" >> /root/check
		fi

		echo "$( date '+%d-%m-%Y %H:%M' ) END   ${PACKAGE}:${SLOT} (${TIME_MERGE})          ${STATUS}"
	done
}

if [ -n "${1}" ]
then
	echo "${1}" > /root/.lastcommit
fi

rm -fr /usr/portage/distfiles/*

while true
do
	env_update
	which -a git > /dev/null 2>&1 || die "Missing git"

	if [ -f /usr/portage/header.txt ]
	then
		cd "${TREE}"
		echo "Running git pull"
		git pull > /dev/null 2>&1 || die "git pull failed"
	else
		git clone https://anongit.gentoo.org/git/repo/gentoo.git "${TREE}" || die "git clone failed"
	fi

	test -f /root/.lastcommit || die "missing lastcommit file"

	echo "Running egencache"
	egencache --jobs="$( nproc )" --update --repo gentoo || die "egencache failed"

	echo "Running eix-update"
	eix-update > /dev/null 2>&1 || die "eix-update failed"

	echo "Update world"
	update_world

	INTERACTIVES="$( eix --properties-interactive --only-names )"

	cd "${TREE}"

	LAST_COMMIT="$( cat /root/.lastcommit )"
	echo "Running git rev-list"
	git rev-list "${LAST_COMMIT}"..HEAD --pretty=format:'%H %s' . | grep -v "^commit " | tac > /root/.commits
	P_TOTAL="$( cat /root/.commits | wc -l )"
	P_COUNT="0"

	unset DONE

	if [ -n "$( cat /root/.commits )" ]
	then
		echo "Running ci"
		while read LINE
		do
			cd "${TREE}"
			COMMIT="$( echo "${LINE}" | awk '{print $1}' )"
			PACKAGE="$( echo "${LINE}" | awk '{print $2}' | sed "s:\:::" )"
			TIMESTAMP="$( git show --no-patch --no-notes --pretty='%ct' "${COMMIT}" )"
			STABILIZATION="$( echo "${LINE}" | grep -iE '(stable|stabilize)' )"

			let P_COUNT++

			if [ "$( eix --only-names -e "${PACKAGE}" | wc -l )" = "1" ] && [ -d /usr/portage/"${PACKAGE}" ] && [ -z "$( echo "${INTERACTIVES}" | grep -o "${PACKAGE}" )" ] && [ -z "$( echo "${DONE}" | grep -o ""${PACKAGE}" " )" ] && [ -z "$( echo "${CI_EXCLUDE}" | grep -o ""${PACKAGE}" " )" ] && [ -z "$( echo "${PACKAGE}" | grep -E '(kde\-|\-sources|\-kernel)' )" ] && [ -z "${STABILIZATION}" ]
			then
				echo ""${P_COUNT}"/"${P_TOTAL}" PACKAGE: "${PACKAGE}"   COMMIT: "${COMMIT}"   TIMESTAMP: "$( date -d @"${TIMESTAMP}" )""
				MERGETYPE="simply"
				common_merge

				# TESTS
				if [ "${STATUS}" != "fail" ] && [ -z "$( echo "${CI_NOTEST}" | grep "${PACKAGE} " )" ] && [ -z "$( bugz -q --key "${APIKEY}" search ""${PACKAGE}" fails test" )" ] && [ "$( grep -Ro "RESTRICT=\"test\"" /usr/portage/"${PACKAGE}"/*.ebuild | wc -l )" != "$( ls /usr/portage/"${PACKAGE}"/*.ebuild | wc -l )" ]
				then
					echo ""${PACKAGE}" test" > /etc/portage/package.env
					MERGETYPE="test"
					common_merge
				fi

				# -bin packages does not need qa/symlink
#				if [[ "${PACKAGE}" != *-bin ]] && [ -z "$( bugz -q --key "${APIKEY}" search ""${PACKAGE}" calls directly" )" ]
#				then
					native-symlinks
					echo ""${PACKAGE}" qa" > /etc/portage/package.env
					MERGETYPE="qa/native-symlink"
					common_merge
#				fi

				DONE+="${PACKAGE} "

				test -f /root/ci && rm /root/ci && exit 0

				update_world
			fi

			echo "${COMMIT}" > /root/.lastcommit
		done < /root/.commits

		test -f /root/ci-end && rm /root/ci-end && exit 0
		test -f /root/ci_end && rm /root/ci_end && exit 0
	else
		/usr/local/bin/qa auto > /dev/null 2>&1

		echo "Sleeping"
		SLEEPING="yes"
		while [ "${SLEEPING}" = "yes" ]
		do
			if [ "$( git pull 2> /dev/null )" = "Already up to date." ]
			then
				sleep 120
			else
				SLEEPING="no"
			fi
		done
		echo
	fi
done