Configuring pure Swift projects

As you know, pure Swift projects are meant to run on any platform. The Swift team is maintaining development snapshots as well as downloadable builds of the Swift toolchain.

We can use this in order to install Swift on Linux and macOS.

Travis offers great configuration capabilities through its build matrix and stages. A build matrix is defined by multiple environment variables, and each environment variable defines a different configuration for your continuous integration scripts. A build stage defines a step in your continuous integration process. If a stage fails, any subsequent stage will be cancelled. Mixing matrices and stages allows your builds to run multiple commands in parallel while minimizing the amount of resources you will consume if any stage fails.

env: 
- SWIFT_BRANCH=swift-4.2.1-release
- SWIFT_VERSION=swift-4.2.1-RELEASE
jobs:
include:
- stage: OSX
os: osx
osx_image: xcode10.1
language: objective-c
sudo: required
install:
- wget https://swift.org/builds/$SWIFT_BRANCH/xcode/$SWIFT_VERSION/$SWIFT_VERSION-osx.pkg
- sudo installer -pkg $SWIFT_VERSION-osx.pkg -target /
- export PATH="$PATH:/Library/Developer/Toolchains/$SWIFT_VERSION.xctoolchain/usr/bin"
script:
- swift package update
- swift test

- stage: Linux test
os: linux
language: generic
dist: trusty
sudo: required
install:
- sudo apt-get install clang libicu-dev
- mkdir swift
- curl https://swift.org/builds/$SWIFT_BRANCH/ubuntu1804/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu18.04.tar.gz -s | tar xz -C swift &> /dev/null
- export PATH="$(pwd)/swift/$SWIFT_VERSION-ubuntu18.04/usr/bin:$PATH"
script:
- swift package update
- swift test

In this section, we covered usage of Travis to test and build your projects hosted on GitHub. In the next section, we will explore how we can use gitlab.com in order to build, test, and lint your projects.