aboutsummaryrefslogtreecommitdiffstats
path: root/.travis/build-pkgs
blob: a8ed4bd27cbe8eba1694033247db4b3807e4e200 (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
#!/bin/sh
# vim: set ts=4:
set -eu

. "$(dirname "$0")"/common.sh

# Prints names of repositories (top-level directories), in defined order,
# that has been changed/created in the specified revisions.
changed_repos() {
	local commit_ish="$1"

	local repo; for repo in main community testing non-free unmaintained; do
		git diff-tree --exit-code "$commit_ish" -- $repo >/dev/null \
			|| echo "$repo"
	done
}

# Prints names of repo's subdirs (i.e. abuilds) that contains APKBUILDs which
# has been changed/created in the specified revisions. The abuild names are
# printed in a build order.
changed_abuilds() {
	local repo="$1"
	local commit_ish="$2"

	# Get names of repo's subdirectories with modified APKBUILD,
	# but ignore deleted ones.
	local aports="$(git diff-tree -r --relative="$repo" --name-only --diff-filter=ACMR \
					"$commit_ish" -- '*APKBUILD' | xargs -I% dirname % | xargs)"

	# Sort abuilds by build order.
	ap builddirs -d "$(pwd)/$repo" $aports 2>/dev/null | xargs -I% basename %
}

# Replaces /etc/apk/repositories with repositories at $MIRROR_URI that are on
# the same or higher level than the given repo (main > community > testing)
# and after that runs `apk update`.
#
# $1: the target repository; main, community, or testing
set_repositories_for() {
	local target_repo="$1"
	local repos=''

	local repo; for repo in main community testing; do
		repos="$repos $MIRROR_URI/$repo"
		[ "$repo" = "$target_repo" ] && break
	done

	sudo sh -c "printf '%s\n' $repos > /etc/apk/repositories"
	sudo apk update
}


cd "$CLONE_DIR"

# Workarounds for oddities of TRAVIS_COMMIT_RANGE that:
#   - may be empty when pushing single commit,
#   - uses triple-dot range instead of double-dot that we need,
#   - contains SHA of old (unreachable) commit when rebasing.
commit_range="$(echo "${TRAVIS_COMMIT_RANGE:-}" | sed -E 's/\.{3}/../')"
if ! git rev-parse "$commit_range" >/dev/null 2>&1; then
	commit_range="$(git rev-parse HEAD^1)..HEAD"
fi

failed_pkgs=''
successful_pkgs=''


title "Building abuilds that has been modified/added between $commit_range\n"

echo 'Diffstat:'
git --no-pager diff --color --stat "$commit_range"

for repo in $(changed_repos "$commit_range"); do
	set_repositories_for "$repo"

	for pkgname in $(changed_abuilds "$repo" "$commit_range"); do
		qname="$repo/$pkgname"

		fold_start "$pkgname" "Building package $qname"
		cd $qname

		if abuild -r; then
			checkapk || :
			successful_pkgs="$successful_pkgs $qname"
		else
			failed_pkgs="$failed_pkgs $qname"
		fi

		cd - >/dev/null
		fold_end "$pkgname"
	done
done

printf '\n----\n'
if [ -n "$successful_pkgs" ]; then
	print -s1 -c2 "Successfully built packages:$successful_pkgs\n"
fi
if [ -n "$failed_pkgs" ]; then
	die "Failed to build packages:$failed_pkgs"

elif [ -z "$successful_pkgs" ]; then
	print -s1 -c3 'No packages found to be built.'
fi