Commit 60238ff6 authored by Jakub Jirutka's avatar Jakub Jirutka Committed by Natanael Copa
Browse files

Set up Travis to build modified packages

parent 3962c0d9
sudo: required
- sudo .travis/install-alpine
- sudo .travis/setup-alpine
script: |
source .travis/
alpine_run $ALPINE_USER .travis/build-pkgs
exec /usr/bin/abuild-apk --no-progress $@
# vim: set ts=4:
set -eu
. "$(dirname "$0")"/
# 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 %
# 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"
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
fold_start "$pkgname" "Building package $qname"
if APKBUILD="$qname/APKBUILD" abuild -fr; then
successful_pkgs="$successful_pkgs $qname"
failed_pkgs="$failed_pkgs $qname"
fold_end "$pkgname"
printf '\n----\n'
if [ -n "$successful_pkgs" ]; then
print -s1 -c2 "Successfully build packages:$successful_pkgs\n"
if [ -n "$failed_pkgs" ]; then
die "Failed to build packages:$failed_pkgs"
elif [ -z "$successful_pkgs" ]; then
die 'No packages found to be build.'
# 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";;
shift $(( OPTIND - 1 ))
local text="$@"
printf "\033[${style};3${fcolor}m$text\033[0m"
title() {
printf '\n'
print -s1 -c6 "==> $@\n"
# vim: set ts=4:
set -eu
. "$(dirname "$0")"/
title 'Downloading apk-tools-static'
cd /tmp
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
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
# vim: set ts=4:
set -eu
. "$(dirname "$0")"/
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
# This key will not be used anywhere, just to make abuild happy...
alpine_run $ALPINE_USER <<-EOF
abuild-keygen -ain
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment