diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..6186e58 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,29 @@ +matrix: + include: + - os: osx + language: generic + # Xcode version implicitly defines the Swift version to be used on macOS. + osx_image: xcode8.2 + + - os: linux + language: generic + sudo: required + services: + - docker + env: + # The Docker image to use on Linux in Docker notation, + # e.g. "swift" or "myusername/myswift" or "swift:3.0.2". + # The image must have Swift installed so that the `swift` + # command is in the `$PATH`. + # + # I recommend Docker Hub's "official" (not maintained by Apple) + # Swift image at https://hub.docker.com/r/_/swift/. Its name + # is simply "swift". + # + # You can use tags to select a specific Swift version if the + # image supports it, e.g. "swift:3.0.2" or "swift:latest". + DOCKER_IMAGE="swift:3.0.2" + +script: + - chmod ugo+x ./scripts/travis-build-script.sh + - ./scripts/travis-build-script.sh diff --git a/README.md b/README.md index 464505c..7305b47 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ Written by Ole Begemann, February 2017. For more info, see my accompanying [blog article](https://oleb.net/blog/2017/02/sorted-array/). +## Status + +[![Build Status](https://travis-ci.org/ole/SortedArray.svg?branch=master)](https://travis-ci.org/ole/SortedArray) + ## Usage Clone the repository and add or copy `SortedArray.swift` to your project. It has no dependencies. diff --git a/scripts/travis-build-script.sh b/scripts/travis-build-script.sh new file mode 100644 index 0000000..fda6007 --- /dev/null +++ b/scripts/travis-build-script.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# The build script used for continuous integration builds on Travis CI +# . Supports testing Swift Package Manager +# packages on macOS and Linux. + +echo "Running on OS: ${TRAVIS_OS_NAME}" + +if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then + # macOS + swift build --clean + swift build + swift test +elif [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then + # Linux + echo "Using Docker image: ${DOCKER_IMAGE}" + # Download the Docker container. This is not strictly necessary since + # docker run would automatically download a missing container. + docker pull ${DOCKER_IMAGE} + # Share the current directory (where Travis checked out the repository) + # with the Docker container. + # Then, in the container, cd into that directory and run the tests. + docker run --volume "$(pwd):/root/repo" ${DOCKER_IMAGE} /bin/bash -c "cd /root/repo; swift build --clean; swift build; swift test" +fi