Add ci file

This commit is contained in:
Rohan Sircar 2021-04-21 13:24:44 +05:30
parent 5378124bf4
commit 0fd1137361
8 changed files with 104 additions and 23 deletions

98
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,98 @@
# Based on https://github.com/actions-rs/meta/blob/master/recipes/quickstart.md
#
# While our "example" application has the platform-specific code,
# for simplicity we are compiling and testing everything on the Ubuntu environment only.
# For multi-OS testing see the `cross.yml` workflow.
on: [push, pull_request]
name: Continuous Integration
jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check
test:
name: Test Suite
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Run cargo test
uses: actions-rs/cargo@v1
with:
command: test
lints:
name: Lints
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt, clippy
- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
build:
name: Build Application
runs-on: ubuntu-latest
needs: [check, test, lints]
strategy:
matrix:
target:
- x86_64-unknown-linux-gnu
- aarch64-unknown-linux-gnu
- powerpc64-unknown-linux-gnu
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.target }}
override: true
- uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --release --target=${{ matrix.target }}

View File

@ -3,7 +3,6 @@ use diesel::prelude::*;
use crate::errors; use crate::errors;
use crate::models; use crate::models;
use bcrypt::{hash, verify, DEFAULT_COST}; use bcrypt::{hash, verify, DEFAULT_COST};
use std::rc::Rc;
pub fn find_user_by_uid( pub fn find_user_by_uid(
uid: i32, uid: i32,

View File

@ -53,12 +53,12 @@ impl ResponseError for DomainError {
reason: format!("{} {}", err.to_string(), source).as_str(), reason: format!("{} {}", err.to_string(), source).as_str(),
}) })
} }
DomainError::PasswordError { cause: _ } => HttpResponse::BadRequest() DomainError::PasswordError { cause: _ } => {
.json(ErrorModel { HttpResponse::BadRequest().json(ErrorModel {
error_code: 400, error_code: 400,
reason: format!("{}", err.to_string()) reason: format!("{}", err.to_string()).as_str(),
.as_str(), })
}), }
DomainError::GenericError { cause } => HttpResponse::BadRequest() DomainError::GenericError { cause } => HttpResponse::BadRequest()
.json(ErrorModel { .json(ErrorModel {
error_code: 400, error_code: 400,

View File

@ -9,12 +9,9 @@ extern crate validator;
use actix_web::{cookie::SameSite, middleware, web, App, HttpServer}; use actix_web::{cookie::SameSite, middleware, web, App, HttpServer};
use actix_web_httpauth::middleware::HttpAuthentication;
use actix_files as fs; use actix_files as fs;
use actix_identity::{CookieIdentityPolicy, IdentityService}; use actix_identity::{CookieIdentityPolicy, IdentityService};
use rand::Rng; use rand::Rng;
use services::UserServiceImpl;
use diesel::prelude::*; use diesel::prelude::*;
use diesel::r2d2::{self, ConnectionManager}; use diesel::r2d2::{self, ConnectionManager};

View File

@ -2,7 +2,6 @@ use serde::{Deserialize, Serialize};
use crate::schema::users; use crate::schema::users;
use crate::utils::regexs; use crate::utils::regexs;
use validator::Validate;
use validator_derive::*; use validator_derive::*;
#[derive(Debug, Clone, Queryable, Identifiable, Deserialize)] #[derive(Debug, Clone, Queryable, Identifiable, Deserialize)]
@ -26,4 +25,3 @@ pub struct UserDTO {
pub name: String, pub name: String,
pub registration_date: chrono::NaiveDateTime, pub registration_date: chrono::NaiveDateTime,
} }

View File

@ -21,7 +21,7 @@ pub async fn get_user(
actions::find_user_by_uid(u_id, &conn) actions::find_user_by_uid(u_id, &conn)
}) })
.await .await
.map_err(|err| { .map_err(|_err| {
let res = DomainError::new_generic_error(format!( let res = DomainError::new_generic_error(format!(
"No user found with uid: {}", "No user found with uid: {}",
u_id u_id

View File

@ -1,7 +1,3 @@
use std::rc::Rc;
use diesel::SqliteConnection;
use crate::{actions, errors, models, types::DbPool}; use crate::{actions, errors, models, types::DbPool};
pub trait UserService { pub trait UserService {

View File

@ -1,10 +1,3 @@
use actix_web_httpauth::extractors::basic::BasicAuth;
use crate::routes::validate_basic_auth;
use crate::AppConfig;
use actix_web::{dev::ServiceRequest, web, Error};
// pub async fn validator( // pub async fn validator(
// req: ServiceRequest, // req: ServiceRequest,
// credentials: BasicAuth, // credentials: BasicAuth,