Skip to content

Commit

Permalink
Merge pull request #5 from sraesch/feature/github-improve-workflow
Browse files Browse the repository at this point in the history
Improved GitHub workflows
  • Loading branch information
sraesch authored Aug 21, 2023
2 parents 36f8f17 + 9c2d732 commit 94e417a
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 103 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/react.yml

This file was deleted.

35 changes: 35 additions & 0 deletions .github/workflows/react_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: "ReactTest"

on:
pull_request:

env:
working-directory: "./movies-db-ui"

jobs:
build:
name: "Build React"
runs-on: ubuntu-latest

steps:
- name: "Check out the repo"
uses: actions/checkout@v3

- name: Install Node.js
uses: actions/setup-node@v1
with:
node-version: "12.x"

- name: Install dependencies
run: npm install
working-directory: ${{ env.working-directory }}

# Deactivate tests for now as there seems to be an issue with jest and css-tools
# - name: Run the tests
# run: npm test
# working-directory: ${{ env.working-directory }}

- name: Build React App
run: npm run build
working-directory: ${{ env.working-directory }}

21 changes: 0 additions & 21 deletions .github/workflows/rust.yml

This file was deleted.

84 changes: 84 additions & 0 deletions .github/workflows/rust_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: "RustTest"

on:
pull_request:

env:
working-directory: "./movies-db-service"

jobs:
check:
name: "Cargo check"
runs-on: "ubuntu-latest"
steps:
- name: "Check out the repo"
uses: actions/checkout@v3

- uses: "actions-rs/toolchain@v1"
with:
profile: "minimal"
toolchain: "stable"
override: true

- uses: "actions-rs/cargo@v1"
with:
command: "check"
args: "--manifest-path movies-db-service/Cargo.toml"

test:
name: "Cargo test"
runs-on: "ubuntu-latest"
steps:
- name: "Check out the repo"
uses: actions/checkout@v3

- uses: "actions-rs/toolchain@v1"
with:
profile: "minimal"
toolchain: "stable"
override: true

- uses: "actions-rs/cargo@v1"
with:
command: "test"
args: "--manifest-path movies-db-service/Cargo.toml"

fmt:
name: "Cargo format"
runs-on: "ubuntu-latest"
steps:
- name: "Check out the repo"
uses: actions/checkout@v3

- uses: "actions-rs/toolchain@v1"
with:
profile: "minimal"
toolchain: "stable"
override: true

- run: "rustup component add rustfmt"

- uses: "actions-rs/cargo@v1"
with:
command: "fmt"
args: "--all --manifest-path movies-db-service/Cargo.toml -- --check"

clippy:
name: "Cargo clippy"
runs-on: "ubuntu-latest"
steps:
- name: "Check out the repo"
uses: actions/checkout@v3

- uses: "actions-rs/toolchain@v1"
with:
profile: "minimal"
toolchain: "stable"
override: true

- run: "rustup component add clippy"

- uses: "actions-rs/cargo@v1"
with:
command: "clippy"
args: "--manifest-path movies-db-service/Cargo.toml -- -D warnings"
8 changes: 4 additions & 4 deletions movies-db-service/movies-db-cli/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ pub struct Options {
pub root_dir: PathBuf,
}

impl Into<ServiceOptions> for Options {
fn into(self) -> ServiceOptions {
impl From<Options> for ServiceOptions {
fn from(options: Options) -> Self {
ServiceOptions {
root_dir: self.root_dir,
http_address: self.address.parse().unwrap(),
root_dir: options.root_dir,
http_address: options.address.parse().unwrap(),
}
}
}
2 changes: 1 addition & 1 deletion movies-db-service/movies-db/src/db/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ pub type MovieId = String;
/// Generates and returns a new movie random ID
pub fn generate_movie_id() -> MovieId {
Uuid::new_v4().to_string()
}
}
23 changes: 10 additions & 13 deletions movies-db-service/movies-db/src/db/simple_movies_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl SimpleMoviesIndex {
///
/// # Arguments
/// `tags` - The tags to process.
fn process_tags(tags: &mut Vec<String>) {
fn process_tags(tags: &mut [String]) {
tags.iter_mut().for_each(|tag| *tag = tag.to_lowercase());
tags.sort();
}
Expand All @@ -42,9 +42,9 @@ impl MoviesIndex for SimpleMoviesIndex {
// check if movie has title
if movie.title.is_empty() {
error!("Movie has no title");
return Err(Error::InvalidArgument(format!(
"Movie title must not be empty"
)));
return Err(Error::InvalidArgument(
"Movie title must not be empty".to_string(),
));
}

assert!(
Expand Down Expand Up @@ -138,13 +138,10 @@ impl MoviesIndex for SimpleMoviesIndex {
let movie = &movie_with_date.movie;

// if a title query is available and the movie title does not match, skip
match title_query {
Some(ref title_query) => {
if !title_query.matches(&movie.title) {
continue;
}
if let Some(ref title_query) = title_query {
if !title_query.matches(&movie.title) {
continue;
}
None => {}
}

// check that all tags match
Expand Down Expand Up @@ -194,7 +191,7 @@ impl SimpleMoviesIndex {
.map(|(id, movie)| (id.clone(), movie.movie.title.clone()))
.collect();

movies.sort_unstable_by(|(_, lhs), (_, rhs)| lhs.cmp(&rhs));
movies.sort_unstable_by(|(_, lhs), (_, rhs)| lhs.cmp(rhs));

if order == SortingOrder::Ascending {
movies.iter().map(|(id, _)| id.clone()).collect()
Expand All @@ -207,10 +204,10 @@ impl SimpleMoviesIndex {
let mut movies: Vec<(MovieId, DateTime<_>)> = self
.movies
.iter()
.map(|(id, movie)| (id.clone(), movie.date.clone()))
.map(|(id, movie)| (id.clone(), movie.date))
.collect();

movies.sort_unstable_by(|(_, lhs), (_, rhs)| lhs.cmp(&rhs));
movies.sort_unstable_by(|(_, lhs), (_, rhs)| lhs.cmp(rhs));

if order == SortingOrder::Ascending {
movies.iter().map(|(id, _)| id.clone()).collect()
Expand Down
50 changes: 19 additions & 31 deletions movies-db-service/movies-db/src/db/sqlite_movies_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl SqliteMoviesIndex {

query_string.push_str(" WHERE m.title LIKE '");
query_string.push_str(&title);
query_string.push_str("'");
query_string.push('\'');
}
None => {}
}
Expand Down Expand Up @@ -123,7 +123,7 @@ impl SqliteMoviesIndex {

query_string.push_str(" AND m.title LIKE '");
query_string.push_str(&title);
query_string.push_str("'");
query_string.push('\'');
}
None => {}
}
Expand Down Expand Up @@ -158,19 +158,13 @@ impl SqliteMoviesIndex {
order_and_limit.push_str(&format!(" ORDER BY {} {} ", field, order));

// limit
match query.num_results {
Some(num_results) => {
order_and_limit.push_str(&format!(" LIMIT {} ", num_results));
}
None => {}
if let Some(limit) = query.num_results {
order_and_limit.push_str(&format!(" LIMIT {} ", limit));
}

// offset
match query.start_index {
Some(offset) => {
order_and_limit.push_str(&format!(" OFFSET {} ", offset));
}
None => {}
if let Some(offset) = query.start_index {
order_and_limit.push_str(&format!(" OFFSET {} ", offset));
}

order_and_limit
Expand All @@ -183,12 +177,9 @@ impl MoviesIndex for SqliteMoviesIndex {
where
Self: Sized,
{
match create_dir_all(&options.root_dir) {
Err(err) => {
error!("Failed to create the root directory: {}", err);
return Err(err.into());
}
Ok(()) => {}
if let Err(err) = create_dir_all(&options.root_dir) {
error!("Failed to create the root directory: {}", err);
return Err(err.into());
}

let mut sqlite_path = options.root_dir.clone();
Expand All @@ -201,18 +192,15 @@ impl MoviesIndex for SqliteMoviesIndex {
match Connection::open(sqlite_path) {
Err(err) => {
error!("Failed to open the SQLite database: {}", err);
return Err(Error::IO(format!("Failed to open SQLite DB{}", err)));
Err(Error::IO(format!("Failed to open SQLite DB{}", err)))
}
Ok(connection) => {
match Self::create_tables(&connection) {
Err(err) => {
error!("Failed to create the tables: {}", err);
return Err(Error::Internal(format!(
"Failed to create the tables: {}",
err
)));
}
Ok(()) => {}
if let Err(err) = Self::create_tables(&connection) {
error!("Failed to create the tables: {}", err);
return Err(Error::Internal(format!(
"Failed to create the tables: {}",
err
)));
}

let connection = Mutex::new(connection);
Expand All @@ -229,9 +217,9 @@ impl MoviesIndex for SqliteMoviesIndex {
// check if movie has title
if movie.title.is_empty() {
error!("Movie has no title");
return Err(Error::InvalidArgument(format!(
"Movie title must not be empty"
)));
return Err(Error::InvalidArgument(
"Movie title must not be empty".to_string(),
));
}

let date = chrono::Utc::now().to_rfc3339();
Expand Down
4 changes: 2 additions & 2 deletions movies-db-service/movies-db/src/service/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod service;
mod service_handler;
mod service_impl;

pub use service::*;
pub use service_impl::*;
Loading

0 comments on commit 94e417a

Please sign in to comment.