This set of steps is the result of a weekend poking at how to get Travis-CI and GitHub configured to provide a CI pipeline for Swift packages. It is mostly for future reference for when I next start another Swift project.
Steps
- Create a new directory and navigate to it
 
mkdir Hello
cd Hello
- Every package must have a manifest file called 
Package.swiftin its root directory. You can create a minimal package namedHellousing: 
swift package init
- Build your library with:
 
swift build
- Run your tests with:
 
swift test
- Initialize your package as a git repo
 
git init
Create a new repository in your GitHub account
Commit your local changes
git add *
git add .gitignore
git commit -sm "Initial Commit"
- Add your GitHub repo as a remote repo
 
git remote add origin git@github.com:zachwick/SwiftHello.git
git push -u origin master
Navigate to https://travis-ci.org/ and connect it to your GitHub account
Activate your new repo in Travis-CI (https://travis-ci.org/zachwick/SwiftHello)
Create
.travis.ymland populate it as below:
if: tag IS blank
branches:
  only:
    - master
env:
  global:
    - SWIFT_BRANCH=swift-5.0.1-release
    - SWIFT_VERSION=swift-5.0.1-RELEASE
    - PACKAGE_VERSION=0.0.1
jobs:
  include:
    - stage: Linux test
      os: linux
      language: generic
      dist: xenial
      sudo: required
      install:
        - sudo apt-get install clang libcurl3 libcurl4-openssl-dev libpython2.7 libpython2.7-dev
          libicu-dev libstdc++6
        - curl https://swift.org/builds/$SWIFT_BRANCH/ubuntu1604/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu16.04.tar.gz
          > $SWIFT_VERSION-ubuntu16.04.tar.gz
        - tar xzf $SWIFT_VERSION-ubuntu16.04.tar.gz
        - export PATH="$(pwd)/$SWIFT_VERSION-ubuntu16.04/usr/bin:$PATH"
      script:
        - swift package update
        - swift test
    - stage: OSX test
      os: osx
      osx_image: xcode10.2
      language: swift
      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="/Library/Developer/Toolchains/$SWIFT_VERSION.xctoolchain/usr/bin:$PATH"
      script:
        - swift package update
        - swift test
    - stage: Set tag
      script:
        - git config --global user.email "builds@travis-ci.com"
        - git config --global user.name "Travis CI"
        - git tag $PACKAGE_VERSION
        - git push --quiet https://$GH_TOKEN@github.com/zachwick/SwiftHello --tag > /dev/null 2>&1
Commit
.travis.ymland push to GitHubCreate a Personal Access Token in your GitHub account
Install the Travis CLI tools by either
brew install travis
or
gem install travis -v 1.8.9 --no-rdoc --no-ri
- Set up and configure the travis CLI tool
 
travis login --auto
travis branches
The first command authenticates your CLI tool with your Travis-CI account using your local GitHub credentials. The second command ensures that the travis CLI tool is using your Swift project as its current project.
- Use the Travis CLI to add your GitHub Personal Access Token as an encrypted environment variable
 
echo GH_TOKEN=<YOUR TOKEN> | travis encrypt --add
- Add a Travis-CI build status badge to your project's README file by following the steps at https://docs.travis-ci.com/user/status-images/.
 
Now, everytime that you want to push a new version of your Swift project if all of your tests pass, you simply need to
bump the version defined as PACKAGE_VERSION, in .travis.yml and them commit and push your changes.
