DEV Community

Werner Echezuría
Werner Echezuría

Posted on

 

Practical Rust Web Development - CI Travis

Tools like Travis can be really helpful to figure it out the stability of our software, specially when we have a huge codebase that requires a lot of time to compile and test.

In this post I'll show how to integrate the Travis CI for our project, because it's open source we can use the Travis free account.

We need to perform a couple of things, first we need to enable our project for Travis CI in the repositories page. Then we add a .travis.yml file in the root with the next configuration:

.travis.yml

language: rust
rust:
  - stable
  - beta
  - nightly
matrix:
  allow_failures:
    - rust: nightly
  fast_finish: true
cache: cargo
services:
  - postgresql
addons:
  postgresql: "10"
  apt:
    packages:
      - postgresql-10
      - postgresql-client-10
env:
  global:
    - PGPORT: 5433
before_script:
  - sudo sed -i -e '/local.*peer/s/postgres/all/' -e 's/peer\|md5/trust/g' /etc/postgresql/*/main/pg_hba.conf
  - sudo service postgresql restart
  - sleep 1
  - sudo apt-get update
  - sudo apt-get install -y postgresql-10-rum
  - psql -c 'create database mystore_test;' -U postgres
  - psql -c 'CREATE EXTENSION rum;' -d mystore_test -U postgres
script:
  - cargo install diesel_cli --quiet || true
  - cargo build --verbose --all
  - DATABASE_URL=postgres://postgres:@localhost/mystore_test diesel setup
  - cargo test --verbose --all

Although we are targeting stable, we might want to test it against all the compiler targets and see if our code does not break some new functionality.

We enable postgres v10 and write the scripts we're gonna need previous the test.

One last thing is add badge to the README, so people can see if our software is stable.

README.md:

# practical-rust-web
[![Build Status](https://travis-ci.org/practical-rust-web-development/mystore.svg?branch=master)](https://travis-ci.org/practical-rust-web-development/mystore)

You can take a look at the source code here

Top comments (12)

Collapse
 
laynath242 profile image
LayNath242 • • Edited

Hello. I do this and got all data. but i only need only username and title. How to do this.Thank you.

[derive(Serialize, Deserialize)]

pub struct UserRoleList(pub Vec<(Role, User)>);

impl UserRoleList {
pub fn list(connection: &PgConnection) -> Self {
use crate::schema::{roles,users};
use diesel::RunQueryDsl;
use diesel::QueryDsl;

    let result = roles::table.inner_join(users::table)
                .load::<(Role, User)>(connection)
                .expect("Error loading ");
        UserRoleList(result)
}

}

Collapse
 
werner profile image
Werner Echezuría •