From a5b97b53ebcd74bbab2f174ef26f96dd0ce2d9a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Klitzing?= Date: Fri, 29 Sep 2017 14:29:35 +0200 Subject: [PATCH] Add initial support for Travis CI --- .travis.yml | 16 ++++++++++++ resources/travis/build.sh | 44 +++++++++++++++++++++++++++++++ resources/travis/common.sh | 12 +++++++++ resources/travis/setup.sh | 53 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 .travis.yml create mode 100755 resources/travis/build.sh create mode 100644 resources/travis/common.sh create mode 100755 resources/travis/setup.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b7fb89d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,16 @@ +language: shell +sudo: required + +env: + matrix: + - CHECK=format + - CHECK=docs + +install: + - sudo resources/travis/setup.sh $CHECK + +script: + - sudo resources/travis/build.sh $CHECK + +notifications: + email: false diff --git a/resources/travis/build.sh b/resources/travis/build.sh new file mode 100755 index 0000000..e32154c --- /dev/null +++ b/resources/travis/build.sh @@ -0,0 +1,44 @@ +#!/bin/sh +set -e + +. "$(dirname "$0")"/common.sh + +for arg in "$@" +do + case "$arg" in + format) ENABLE_FORMAT=true;; + docs) ENABLE_DOCS=true;; + *) echo "Unknown command: $1" && exit 1 + esac +done + +alpine_run prepare <<-EOF + mkdir -p /tmp/build/format + mkdir -p /tmp/build/docs +EOF + + + +if [ "$ENABLE_FORMAT" = true ]; then +alpine_run format <<-EOF + cd /tmp/build/format + + cmake -Dtools.only=ON ~ + make format + cd ~ + git add . + git --no-pager diff --staged + git diff-index --quiet HEAD +EOF +fi + + +if [ "$ENABLE_DOCS" = true ]; then +alpine_run docs <<-EOF + cd /tmp/build/docs + + cmake -Dtools.only=ON ~ + make sdk + make notes +EOF +fi diff --git a/resources/travis/common.sh b/resources/travis/common.sh new file mode 100644 index 0000000..f929f64 --- /dev/null +++ b/resources/travis/common.sh @@ -0,0 +1,12 @@ +readonly ALPINE_ROOT='/mnt/alpine' +readonly ALPINE_USER='governikus' + +alpine_run() { + local folding="${1:-chroot}" + local user="${2:-${ALPINE_USER}}" + local cmd="${3:-sh}" + + echo -e "travis_fold:start:$folding" + chroot "$ALPINE_ROOT" /usr/bin/env -i su -l $user sh -c "cd; $cmd" + echo -e "travis_fold:end:$folding" +} diff --git a/resources/travis/setup.sh b/resources/travis/setup.sh new file mode 100755 index 0000000..85676b3 --- /dev/null +++ b/resources/travis/setup.sh @@ -0,0 +1,53 @@ +#!/bin/sh +set -eu + +. "$(dirname "$0")"/common.sh + +readonly CLONE_DIR="${CLONE_DIR:-$(pwd)}" + +MINIROOTFS_VERSION="3.6.2" +MINIROOTFS_SHA="df4bf81fdafdc72b32ad455c23901935fdfe5815993612ba7a2df4bae79d97ca" + +MINIROOTFS="alpine-minirootfs-${MINIROOTFS_VERSION}-x86_64.tar.gz" +MINIROOTFS_URI="http://dl-cdn.alpinelinux.org/alpine/v${MINIROOTFS_VERSION%.*}/releases/x86_64/$MINIROOTFS" + +cd /tmp +wget "$MINIROOTFS_URI" +echo "$MINIROOTFS_SHA $MINIROOTFS" | sha256sum -c + +mkdir -p "${ALPINE_ROOT}" +tar xf "$MINIROOTFS" -C "${ALPINE_ROOT}" + +chmod 755 "$ALPINE_ROOT" +cd "$ALPINE_ROOT" + +cp /etc/resolv.conf etc/resolv.conf +mount -t proc none proc +mount --rbind /sys sys +mount --rbind /dev dev +mount --rbind /run run +ln -sf /run/shm dev/shm + + +PACKAGES="cmake make ninja git" +for arg in "$@" +do + case "$arg" in + format) PACKAGES="$PACKAGES uncrustify";; + docs) PACKAGES="$PACKAGES py2-sphinx py2-setuptools";; + *) echo "Unknown command: $1" && exit 1 + esac +done + + +alpine_run packages root <<-EOF + adduser $ALPINE_USER -G users -s /bin/sh -D + apk upgrade -U -a + apk add $PACKAGES +EOF + +mount --bind "$CLONE_DIR" "${ALPINE_ROOT}/home/${ALPINE_USER}" + +alpine_run chown root <<-EOF + chown -R $ALPINE_USER: /home/${ALPINE_USER} +EOF