diff options
author | Jakub Jirutka <jakub@jirutka.cz> | 2016-03-30 21:28:23 +0200 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2016-04-05 13:15:19 +0000 |
commit | 60238ff6aad2e14870bab1c7adee633976571423 (patch) | |
tree | 42859a242fbc96f17abe26b8daedf00f7eaf52e4 /.travis | |
parent | 3962c0d948aa2ba5cc3820aea8cf685794a42e5b (diff) | |
download | alpine_aports-60238ff6aad2e14870bab1c7adee633976571423.tar.bz2 alpine_aports-60238ff6aad2e14870bab1c7adee633976571423.tar.xz alpine_aports-60238ff6aad2e14870bab1c7adee633976571423.zip |
Set up Travis to build modified packages
Diffstat (limited to '.travis')
-rw-r--r-- | .travis/abuild-apk | 3 | ||||
-rwxr-xr-x | .travis/build-pkgs | 75 | ||||
-rw-r--r-- | .travis/common.sh | 61 | ||||
-rwxr-xr-x | .travis/install-alpine | 33 | ||||
-rw-r--r-- | .travis/repositories | 3 | ||||
-rwxr-xr-x | .travis/setup-alpine | 33 |
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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | # vim: set ts=4: | ||
3 | set -eu | ||
4 | |||
5 | . "$(dirname "$0")"/common.sh | ||
6 | |||
7 | # Prints names of top-level directories (i.e. repositories) that has been | ||
8 | # changed/created in the specified revisions. | ||
9 | changed_repos() { | ||
10 | local commit_ish="$1" | ||
11 | |||
12 | git diff-tree --name-only "$commit_ish" | grep -v '^\..*' || echo '' | ||
13 | } | ||
14 | |||
15 | # Prints names of repo's subdirs (i.e. abuilds) that contains APKBUILDs which | ||
16 | # has been changed/created in the specified revisions. The abuild names are | ||
17 | # printed in a build order. | ||
18 | changed_abuilds() { | ||
19 | local repo="$1" | ||
20 | local commit_ish="$2" | ||
21 | |||
22 | # Get names of repo's subdirectories with modified APKBUILD. | ||
23 | local aports="$(git diff-tree -r --relative="$repo" --name-only "$commit_ish" -- '*APKBUILD' \ | ||
24 | | xargs -I% dirname % | xargs)" | ||
25 | |||
26 | # Sort abuilds by build order. | ||
27 | ap builddirs -d "$(pwd)/$repo" $aports 2>/dev/null | xargs -I% basename % | ||
28 | } | ||
29 | |||
30 | |||
31 | cd "$CLONE_DIR" | ||
32 | |||
33 | # Workarounds for oddities of TRAVIS_COMMIT_RANGE that: | ||
34 | # - may be empty when pushing single commit, | ||
35 | # - uses triple-dot range instead of double-dot that we need, | ||
36 | # - contains SHA of old (unreachable) commit when rebasing. | ||
37 | commit_range="$(echo "${TRAVIS_COMMIT_RANGE:-}" | sed -E 's/\.{3}/../')" | ||
38 | if ! git rev-parse "$commit_range" >/dev/null 2>&1; then | ||
39 | commit_range="$(git rev-parse HEAD^1)..HEAD" | ||
40 | fi | ||
41 | |||
42 | failed_pkgs='' | ||
43 | successful_pkgs='' | ||
44 | |||
45 | |||
46 | title "Building abuilds that has been modified/added between $commit_range\n" | ||
47 | |||
48 | echo 'Diffstat:' | ||
49 | git --no-pager diff --color --stat "$commit_range" | ||
50 | |||
51 | for repo in $(changed_repos "$commit_range"); do | ||
52 | for pkgname in $(changed_abuilds "$repo" "$commit_range"); do | ||
53 | qname="$repo/$pkgname" | ||
54 | |||
55 | fold_start "$pkgname" "Building package $qname" | ||
56 | |||
57 | if APKBUILD="$qname/APKBUILD" abuild -fr; then | ||
58 | successful_pkgs="$successful_pkgs $qname" | ||
59 | else | ||
60 | failed_pkgs="$failed_pkgs $qname" | ||
61 | fi | ||
62 | fold_end "$pkgname" | ||
63 | done | ||
64 | done | ||
65 | |||
66 | printf '\n----\n' | ||
67 | if [ -n "$successful_pkgs" ]; then | ||
68 | print -s1 -c2 "Successfully build packages:$successful_pkgs\n" | ||
69 | fi | ||
70 | if [ -n "$failed_pkgs" ]; then | ||
71 | die "Failed to build packages:$failed_pkgs" | ||
72 | |||
73 | elif [ -z "$successful_pkgs" ]; then | ||
74 | die 'No packages found to be build.' | ||
75 | 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 @@ | |||
1 | # vim: set ts=4: | ||
2 | |||
3 | readonly ALPINE_ROOT='/mnt/alpine' | ||
4 | readonly ALPINE_USER='alpine' | ||
5 | readonly CLONE_DIR="${CLONE_DIR:-$(pwd)}" | ||
6 | |||
7 | # Runs commands inside the Alpine chroot. | ||
8 | alpine_run() { | ||
9 | local user="${1:-root}" | ||
10 | local cmd="${2:-sh}" | ||
11 | |||
12 | local _sudo= | ||
13 | [ "$(id -u)" -eq 0 ] || _sudo='sudo' | ||
14 | |||
15 | $_sudo chroot "$ALPINE_ROOT" /usr/bin/env -i su -l $user \ | ||
16 | sh -c "cd $CLONE_DIR; $cmd" | ||
17 | } | ||
18 | |||
19 | die() { | ||
20 | print -s1 -c1 "$@\n" 1>&2 | ||
21 | exit 1 | ||
22 | } | ||
23 | |||
24 | # Marks start of named folding section for Travis and prints title. | ||
25 | fold_start() { | ||
26 | local name="$1" | ||
27 | local title="$2" | ||
28 | |||
29 | printf "\ntravis_fold:start:$name " | ||
30 | print -s1 -c6 "> $title\n" | ||
31 | } | ||
32 | |||
33 | # Marks end of the named folding section. | ||
34 | fold_end() { | ||
35 | local name="$1" | ||
36 | |||
37 | printf "travis_fold:end:$name\n" | ||
38 | } | ||
39 | |||
40 | # Prints formatted and colored text. | ||
41 | print() { | ||
42 | local style=0 | ||
43 | local fcolor=9 | ||
44 | |||
45 | local opt; while getopts 's:c:' opt; do | ||
46 | case "$opt" in | ||
47 | s) style="$OPTARG";; | ||
48 | c) fcolor="$OPTARG";; | ||
49 | esac | ||
50 | done | ||
51 | |||
52 | shift $(( OPTIND - 1 )) | ||
53 | local text="$@" | ||
54 | |||
55 | printf "\033[${style};3${fcolor}m$text\033[0m" | ||
56 | } | ||
57 | |||
58 | title() { | ||
59 | printf '\n' | ||
60 | print -s1 -c6 "==> $@\n" | ||
61 | } | ||
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 @@ | |||
1 | #!/bin/sh | ||
2 | # vim: set ts=4: | ||
3 | set -eu | ||
4 | |||
5 | . "$(dirname "$0")"/common.sh | ||
6 | |||
7 | APK_TOOLS_URI='https://repository.fit.cvut.cz/mirrors/alpine/v3.3/main/x86_64/apk-tools-static-2.6.5-r1.apk' | ||
8 | APK_TOOLS_SHA256='03162d70e6d42eea77624a8da76d69e665ca19aa834361c3652414f111884636' | ||
9 | |||
10 | |||
11 | title 'Downloading apk-tools-static' | ||
12 | |||
13 | cd /tmp | ||
14 | wget "$APK_TOOLS_URI" | ||
15 | echo "$APK_TOOLS_SHA256 $(basename "$APK_TOOLS_URI")" | sha256sum -c | ||
16 | tar -xzf $(basename "$APK_TOOLS_URI") | ||
17 | |||
18 | |||
19 | title 'Installing Alpine Linux' | ||
20 | |||
21 | mkdir -p "$ALPINE_ROOT"/etc/apk | ||
22 | cd "$ALPINE_ROOT" | ||
23 | |||
24 | cp "$CLONE_DIR"/.travis/repositories etc/apk/repositories | ||
25 | cp /etc/resolv.conf etc/resolv.conf | ||
26 | |||
27 | /tmp/sbin/apk.static \ | ||
28 | --root . --allow-untrusted --update-cache --initdb --no-progress \ | ||
29 | add alpine-base | ||
30 | |||
31 | mount -t proc none proc | ||
32 | mount --rbind /sys sys | ||
33 | 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 @@ | |||
1 | https://repository.fit.cvut.cz/mirrors/alpine/edge/main | ||
2 | https://repository.fit.cvut.cz/mirrors/alpine/edge/community | ||
3 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | # vim: set ts=4: | ||
3 | set -eu | ||
4 | |||
5 | . "$(dirname "$0")"/common.sh | ||
6 | |||
7 | title 'Setting up Alpine Linux' | ||
8 | |||
9 | mkdir -p "${ALPINE_ROOT}${CLONE_DIR}" | ||
10 | mount --bind "$CLONE_DIR" "${ALPINE_ROOT}${CLONE_DIR}" | ||
11 | |||
12 | alpine_run <<-EOF | ||
13 | apk add alpine-sdk lua-aports | ||
14 | |||
15 | adduser -G users -s /bin/sh -D $ALPINE_USER | ||
16 | addgroup $ALPINE_USER abuild | ||
17 | addgroup $ALPINE_USER wheel | ||
18 | |||
19 | echo '%wheel ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/wheel | ||
20 | |||
21 | sed -i 's/JOBS=[0-9]*/JOBS=$(nproc)/' /etc/abuild.conf | ||
22 | |||
23 | mkdir -p /var/cache/distfiles | ||
24 | chmod a+w /var/cache/distfiles | ||
25 | |||
26 | # Hack to disable apk's progress bar. | ||
27 | install -m755 -D .travis/abuild-apk /usr/local/bin/abuild-apk | ||
28 | EOF | ||
29 | |||
30 | # This key will not be used anywhere, just to make abuild happy... | ||
31 | alpine_run $ALPINE_USER <<-EOF | ||
32 | abuild-keygen -ain | ||
33 | EOF | ||