aboutsummaryrefslogtreecommitdiffstats
path: root/.travis
diff options
context:
space:
mode:
authorJakub Jirutka <jakub@jirutka.cz>2016-03-30 21:28:23 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2016-04-05 13:15:19 +0000
commit60238ff6aad2e14870bab1c7adee633976571423 (patch)
tree42859a242fbc96f17abe26b8daedf00f7eaf52e4 /.travis
parent3962c0d948aa2ba5cc3820aea8cf685794a42e5b (diff)
downloadaports-60238ff6aad2e14870bab1c7adee633976571423.tar.bz2
aports-60238ff6aad2e14870bab1c7adee633976571423.tar.xz
Set up Travis to build modified packages
Diffstat (limited to '.travis')
-rw-r--r--.travis/abuild-apk3
-rwxr-xr-x.travis/build-pkgs75
-rw-r--r--.travis/common.sh61
-rwxr-xr-x.travis/install-alpine33
-rw-r--r--.travis/repositories3
-rwxr-xr-x.travis/setup-alpine33
6 files changed, 208 insertions, 0 deletions
diff --git a/.travis/abuild-apk b/.travis/abuild-apk
new file mode 100644
index 0000000000..a7ef73057d
--- /dev/null
+++ b/.travis/abuild-apk
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec /usr/bin/abuild-apk --no-progress $@
diff --git a/.travis/build-pkgs b/.travis/build-pkgs
new file mode 100755
index 0000000000..6c65407041
--- /dev/null
+++ b/.travis/build-pkgs
@@ -0,0 +1,75 @@
+#!/bin/sh
+# vim: set ts=4:
+set -eu
+
+. "$(dirname "$0")"/common.sh
+
+# Prints names of top-level directories (i.e. repositories) that has been
+# changed/created in the specified revisions.
+changed_repos() {
+ local commit_ish="$1"
+
+ git diff-tree --name-only "$commit_ish" | grep -v '^\..*' || echo ''
+}
+
+# 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.
+ local aports="$(git diff-tree -r --relative="$repo" --name-only "$commit_ish" -- '*APKBUILD' \
+ | xargs -I% dirname % | xargs)"
+
+ # Sort abuilds by build order.
+ ap builddirs -d "$(pwd)/$repo" $aports 2>/dev/null | xargs -I% basename %
+}
+
+
+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
+ for pkgname in $(changed_abuilds "$repo" "$commit_range"); do
+ qname="$repo/$pkgname"
+
+ fold_start "$pkgname" "Building package $qname"
+
+ if APKBUILD="$qname/APKBUILD" abuild -fr; then
+ successful_pkgs="$successful_pkgs $qname"
+ else
+ failed_pkgs="$failed_pkgs $qname"
+ fi
+ fold_end "$pkgname"
+ done
+done
+
+printf '\n----\n'
+if [ -n "$successful_pkgs" ]; then
+ print -s1 -c2 "Successfully build packages:$successful_pkgs\n"
+fi
+if [ -n "$failed_pkgs" ]; then
+ die "Failed to build packages:$failed_pkgs"
+
+elif [ -z "$successful_pkgs" ]; then
+ die 'No packages found to be build.'
+fi
diff --git a/.travis/common.sh b/.travis/common.sh
new file mode 100644
index 0000000000..bf4b2ff945
--- /dev/null
+++ b/.travis/common.sh
@@ -0,0 +1,61 @@
+# vim: set ts=4:
+
+readonly ALPINE_ROOT='/mnt/alpine'
+readonly ALPINE_USER='alpine'
+readonly CLONE_DIR="${CLONE_DIR:-$(pwd)}"
+
+# Runs commands inside the Alpine chroot.
+alpine_run() {
+ local user="${1:-root}"
+ local cmd="${2:-sh}"
+
+ local _sudo=
+ [ "$(id -u)" -eq 0 ] || _sudo='sudo'
+
+ $_sudo chroot "$ALPINE_ROOT" /usr/bin/env -i su -l $user \
+ sh -c "cd $CLONE_DIR; $cmd"
+}
+
+die() {
+ print -s1 -c1 "$@\n" 1>&2
+ exit 1
+}
+
+# Marks start of named folding section for Travis and prints title.
+fold_start() {
+ local name="$1"
+ local title="$2"
+
+ printf "\ntravis_fold:start:$name "
+ print -s1 -c6 "> $title\n"
+}
+
+# Marks end of the named folding section.
+fold_end() {
+ local name="$1"
+
+ printf "travis_fold:end:$name\n"
+}
+
+# Prints formatted and colored text.
+print() {
+ local style=0
+ local fcolor=9
+
+ local opt; while getopts 's:c:' opt; do
+ case "$opt" in
+ s) style="$OPTARG";;
+ c) fcolor="$OPTARG";;
+ esac
+ done
+
+ shift $(( OPTIND - 1 ))
+ local text="$@"
+
+ printf "\033[${style};3${fcolor}m$text\033[0m"
+}
+
+title() {
+ printf '\n'
+ print -s1 -c6 "==> $@\n"
+}
diff --git a/.travis/install-alpine b/.travis/install-alpine
new file mode 100755
index 0000000000..fac726c2f8
--- /dev/null
+++ b/.travis/install-alpine
@@ -0,0 +1,33 @@
+#!/bin/sh
+# vim: set ts=4:
+set -eu
+
+. "$(dirname "$0")"/common.sh
+
+APK_TOOLS_URI='https://repository.fit.cvut.cz/mirrors/alpine/v3.3/main/x86_64/apk-tools-static-2.6.5-r1.apk'
+APK_TOOLS_SHA256='03162d70e6d42eea77624a8da76d69e665ca19aa834361c3652414f111884636'
+
+
+title 'Downloading apk-tools-static'
+
+cd /tmp
+wget "$APK_TOOLS_URI"
+echo "$APK_TOOLS_SHA256 $(basename "$APK_TOOLS_URI")" | sha256sum -c
+tar -xzf $(basename "$APK_TOOLS_URI")
+
+
+title 'Installing Alpine Linux'
+
+mkdir -p "$ALPINE_ROOT"/etc/apk
+cd "$ALPINE_ROOT"
+
+cp "$CLONE_DIR"/.travis/repositories etc/apk/repositories
+cp /etc/resolv.conf etc/resolv.conf
+
+/tmp/sbin/apk.static \
+ --root . --allow-untrusted --update-cache --initdb --no-progress \
+ add alpine-base
+
+mount -t proc none proc
+mount --rbind /sys sys
+mount --rbind /dev dev
diff --git a/.travis/repositories b/.travis/repositories
new file mode 100644
index 0000000000..b6f1e761eb
--- /dev/null
+++ b/.travis/repositories
@@ -0,0 +1,3 @@
+https://repository.fit.cvut.cz/mirrors/alpine/edge/main
+https://repository.fit.cvut.cz/mirrors/alpine/edge/community
+https://repository.fit.cvut.cz/mirrors/alpine/edge/testing
diff --git a/.travis/setup-alpine b/.travis/setup-alpine
new file mode 100755
index 0000000000..a922dff671
--- /dev/null
+++ b/.travis/setup-alpine
@@ -0,0 +1,33 @@
+#!/bin/sh
+# vim: set ts=4:
+set -eu
+
+. "$(dirname "$0")"/common.sh
+
+title 'Setting up Alpine Linux'
+
+mkdir -p "${ALPINE_ROOT}${CLONE_DIR}"
+mount --bind "$CLONE_DIR" "${ALPINE_ROOT}${CLONE_DIR}"
+
+alpine_run <<-EOF
+ apk add alpine-sdk lua-aports
+
+ adduser -G users -s /bin/sh -D $ALPINE_USER
+ addgroup $ALPINE_USER abuild
+ addgroup $ALPINE_USER wheel
+
+ echo '%wheel ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/wheel
+
+ sed -i 's/JOBS=[0-9]*/JOBS=$(nproc)/' /etc/abuild.conf
+
+ mkdir -p /var/cache/distfiles
+ chmod a+w /var/cache/distfiles
+
+ # Hack to disable apk's progress bar.
+ install -m755 -D .travis/abuild-apk /usr/local/bin/abuild-apk
+EOF
+
+# This key will not be used anywhere, just to make abuild happy...
+alpine_run $ALPINE_USER <<-EOF
+ abuild-keygen -ain
+EOF