Rust is supported on Travis CI, there are three main channels of Rust you can use: stable, beta and nightly. You can just follow their instruction to get your Rust project build smoothly.
But when it come to diesel.rs, it will be a bit tricky.
The reason is, in order to build a diesel-based project, you will need to have:
- A database on your build machine
.envfile with a configuration to connect to that database
- diesel-cli installed to run migration
So, it will require some more configuration.
Let's create a
.travis.yml file in your project's root folder.
You can select any version of Rust in your Travis CI, put this to your config file:
language: rust rust: - nightly // or - 1.22.0 // or - stable
Next, we need to add PostgreSQL as an extra service:
services: - postgresql
If you're using a different database, just change it. For the complete list of supported database, please take a look at this document.
Now we need to do a lot of things, create a databse, install diesel-cli, create a database and run migration, let create a
before_script: - psql -c 'create database build_db;' -U postgres - echo "DATABASE_URL=postgres://postgres@localhost/build_db" > .env - cargo install diesel_cli --no-default-features --features=postgres - diesel migration run
Finally, build and test your project with
script: - cargo build --verbose --all - cargo test --verbose --all
That's all you need!
If you are too lazy to follow the four steps, this is a gist for you.
P/S: It's worth to mention that due to a lot of
cargo run, the build time is so freaking slow, with the above gist, my project took approximately 8 to 9 mins per build.
You might want to add some caching for
cargo in your
See more about dependencies caching here.