Skip to content
Snippets Groups Projects
Commit 60238ff6 authored by Jakub Jirutka's avatar Jakub Jirutka :flag_ua: Committed by Natanael Copa
Browse files

Set up Travis to build modified packages

parent 3962c0d9
No related branches found
No related tags found
No related merge requests found
sudo: required
install:
- sudo .travis/install-alpine
- sudo .travis/setup-alpine
script: |
source .travis/common.sh
alpine_run $ALPINE_USER .travis/build-pkgs
#!/bin/sh
exec /usr/bin/abuild-apk --no-progress $@
#!/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
# 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"
}
#!/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
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
#!/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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment