TravisCI

TravisCI is the most popular CI service for open source projects, because it provides a free plan for such projects and is integrated well with GitHub. To use it, all you have to do is add the .travis.yml file to the root of repository of your project. It supports Rust out of the box.

With TravisCI, you can build your projects in either Linux or macOS environments. Let's write a simple example of a .travis.yml file. The first part of this file is a building matrix declaration:

language: rust
cache: cargo
matrix:
include:
- os: linux
rust: stable
env: TARGET=x86_64-unknown-linux-gnu
- os: linux
rust: nightly
env: TARGET=x86_64-unknown-linux-gnu
- os: osx
rust: stable
env: TARGET=x86_64-apple-darwin
- os: osx
rust: nightly
env: TARGET=x86_64-apple-darwin

We chose the Rust language with caching for cargo to speed up building updates. Also, we declared a matrix of environments. TravisCI automatically prepared the Rust environment for us with four variants: linux with a stable compiler, linux with a nightly compiler, and a pair of stable and nightly compiler versions for osx. For microservices, you often need linux builds only. Also, we specified targets, but you can use musl instead of gnu, for example.

The following code installs extra packages:

addons:
apt:
packages:
- build-essential
- libcurl4-openssl-dev
- libssl-dev

Also, you can add environment variables that you can use in building and test running:

env:
global:
- APPNAME="myapp"

Finally, you have to add a script that will be used as the CI script. You can put the script section with a command directly into .travis.yml as items to that section, or add a jobs section that can contain concurrent jobs to run:

jobs:
include:
- name: rustfmt
install:
- rustup component add rustfmt
script:
- cargo fmt -- --check
- name: clippy
install:
- rustup component add clippy
script:
- cargo clippy
- name: test
script:
- cargo build --target $TARGET --verbose
- cargo test --target $TARGET --verbose

The jobs section can also contain an install subsection to provide a list of commands to install extra dependencies for a job.

Now you can put this .travis.yml file into the root of the repository of your project to allow Travis CI to check the pull requests of your project. But remember that you have to pay for private repositories with the TravisCI service, while GitHub allows you to have private repositories for free. You can test your Rust application for Linux and macOS, but there is another service that provides another set of operating systems.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.152.139