diff --git a/.github/workflows/build-push-release.yaml b/.github/workflows/build-push-release.yaml index 57efbe0..f939f05 100644 --- a/.github/workflows/build-push-release.yaml +++ b/.github/workflows/build-push-release.yaml @@ -189,7 +189,7 @@ jobs: with: context: . file: ./Containerfile - platforms: linux/amd64, linux/arm64 + platforms: linux/amd64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d212b4c..e4f45bd 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,3 +1,5 @@ +# Reference from here: +# https://github.com/dtolnay/syn/blob/master/.github/workflows/ci.yml name: ci on: pull_request: @@ -5,7 +7,7 @@ on: branches: - master schedule: - - cron: '00 01 * * *' + - cron: '0 1 * * *' permissions: contents: read @@ -15,8 +17,21 @@ env: RUSTFLAGS: -Dwarnings jobs: + check-pass: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + components: rustc-dev + - name: Run cargo check tool + run: cargo check --all-targets --all-features --tests --benches --release --verbose test: runs-on: ${{ matrix.os }} + needs: + - check-pass env: CARGO: cargo TARGET_FLAGS: "" @@ -71,6 +86,7 @@ jobs: uses: dtolnay/rust-toolchain@master with: toolchain: ${{ matrix.rust }} + components: llvm-tools, rustc-dev - name: Use cross compiler if: matrix.os == 'ubuntu-latest' && matrix.target != '' run: | @@ -107,3 +123,19 @@ jobs: components: rustfmt - name: Check formatting run: cargo fmt --all --check + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + components: clippy, rustc-dev + - run: cargo clippy --all-features --all-targets --tests --benches -- -Dclippy::all + # outdated: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v4 + # - uses: dtolnay/install@cargo-outdated + # - run: cargo outdated --exit-code 1 diff --git a/Cargo.lock b/Cargo.lock index df58e2c..fae3c35 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -460,7 +460,7 @@ checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" [[package]] name = "midas" -version = "0.5.17" +version = "0.5.19" dependencies = [ "clap", "dotenv", diff --git a/Cargo.toml b/Cargo.toml index c1c9c48..1edf75a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "midas" -version = "0.5.18" +version = "0.5.19" authors = ["Edward Fitz Abucay gh:@ffimnsr"] edition = "2021" readme = "README.md" diff --git a/README.md b/README.md index b245348..1139ccc 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ For more info see `--help`. If you're into **Rust** then you can use `cargo` to install. -* The minimum supported version of Rust is 1.37.0. +* The minimum supported version of Rust is `1.37.0`. ```shellbash cargo install midas diff --git a/src/cli.rs b/src/cli.rs index 6ddacff..1091c4e 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -6,8 +6,8 @@ use std::time::Instant; use clap::{App, AppSettings, Arg, SubCommand}; -const PKG_VERSION: &'static str = env!("CARGO_PKG_VERSION"); -const PKG_DESCRIPTION: &'static str = env!("CARGO_PKG_DESCRIPTION"); +const PKG_VERSION: &str = env!("CARGO_PKG_VERSION"); +const PKG_DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION"); use super::commander::Migrator; use super::sequel::postgres::Postgres; @@ -101,10 +101,9 @@ pub(crate) fn midas_entry( internal_matches .subcommand_matches(command_name) .ok_or(format!( - "cargo-{} not invoked via cargo command", - command_name + "cargo-{command_name} not invoked via cargo command", ))? - .to_owned() + .clone() } else { cli_app.get_matches() }; @@ -137,7 +136,7 @@ pub(crate) fn midas_entry( .value_of("name") .ok_or("Slug is either malformed or undecipherable")?; - migrator.create(source_path, slug)? + migrator.create(source_path, slug)?; } Some("status") => migrator.status()?, Some("up") => migrator.up()?, diff --git a/src/commander.rs b/src/commander.rs index 13ca6e0..46b6423 100644 --- a/src/commander.rs +++ b/src/commander.rs @@ -6,7 +6,7 @@ use std::path::Path; use log::trace; use crate::lookup::{self, MigrationFiles, VecStr}; -use crate::sequel::{SequelDriver, VecSerial}; +use crate::sequel::{Driver as SequelDriver, VecSerial}; macro_rules! get_content_string { ($content: ident) => { @@ -34,8 +34,8 @@ impl Migrator { path: &Path, slug: &str, ) -> Result<(), super::GenericError> { - let fixed_slug = slug.to_ascii_lowercase().replace(" ", "_"); - let _ = lookup::create_migration_file(path, &fixed_slug)?; + let fixed_slug = slug.to_ascii_lowercase().replace(' ', "_"); + lookup::create_migration_file(path, &fixed_slug)?; Ok(()) } @@ -43,7 +43,7 @@ impl Migrator { pub fn status(&mut self) -> Result<(), super::GenericError> { let completed_migrations = self.executor.get_completed_migrations()?; let available_migrations = - self.migrations.keys().cloned().collect::(); + self.migrations.keys().copied().collect::(); if available_migrations.is_empty() { println!("There are no available migration files."); @@ -52,19 +52,20 @@ impl Migrator { println!("Building active migrations list..."); if completed_migrations.is_empty() { - for it in available_migrations.iter() { - println!("{:013} = Inactive", it); + for it in &available_migrations { + println!("{it:013} = Inactive"); } return Ok(()); } - for it in available_migrations.iter() { - let does_have = match completed_migrations.contains(it) { - true => "Active", - _ => "Inactive", + for it in &available_migrations { + let does_have = if completed_migrations.contains(it) { + "Active" + } else { + "Inactive" }; - println!("{:013} = {}", it, does_have); + println!("{it:013} = {does_have}"); } Ok(()) @@ -73,7 +74,7 @@ impl Migrator { pub fn up(&mut self) -> Result<(), super::GenericError> { let completed_migrations = self.executor.get_completed_migrations()?; let available_migrations = - self.migrations.keys().cloned().collect::(); + self.migrations.keys().copied().collect::(); if available_migrations.is_empty() { println!("There are no available migration files."); @@ -82,8 +83,8 @@ impl Migrator { let filtered = available_migrations .iter() - .filter(|s| completed_migrations.contains(s) == false) - .map(|s| s.to_owned()) + .filter(|s| !completed_migrations.contains(s)) + .map(std::borrow::ToOwned::to_owned) .collect::(); if filtered.is_empty() { @@ -91,9 +92,9 @@ impl Migrator { return Ok(()); } - for it in filtered.iter() { - println!("[{:013}] Applying migration in the database.", it); - let migration = self.migrations.get(&it).unwrap(); + for it in &filtered { + println!("[{it:013}] Applying migration in the database."); + let migration = self.migrations.get(it).unwrap(); let content_up = migration.content_up.as_ref().unwrap(); let content_up = get_content_string!(content_up); @@ -116,8 +117,8 @@ impl Migrator { } for it in completed_migrations.iter().rev() { - println!("[{:013}] Undo migration from database.", it); - let migration = self.migrations.get(&it).unwrap(); + println!("[{it:013}] Undo migration from database."); + let migration = self.migrations.get(it).unwrap(); let content_down = migration.content_down.as_ref().unwrap(); let content_down = get_content_string!(content_down); @@ -125,7 +126,7 @@ impl Migrator { self.executor.migrate(&content_down)?; - if !std::env::var("MIGRATIONS_SKIP_LAST").is_err() { + if std::env::var("MIGRATIONS_SKIP_LAST").is_ok() { if !completed_migrations.first().eq(&Some(it)) { self.executor.delete_completed_migration(it.to_owned())?; } @@ -149,8 +150,7 @@ impl Migrator { if current_state != -1 { println!( - "[{:013}] Clearing recent migration from database.", - current + "[{current:013}] Clearing recent migration from database." ); let content_down = migration.content_down.as_ref().unwrap(); let content_down = get_content_string!(content_down); @@ -161,10 +161,7 @@ impl Migrator { trace!("Running the method `redo` {:?}", migration); - println!( - "[{:013}] Applying recent migration in the database.", - current - ); + println!("[{current:013}] Applying recent migration in the database."); let content_up = migration.content_up.as_ref().unwrap(); let content_up = get_content_string!(content_up); @@ -184,14 +181,14 @@ impl Migrator { return Ok(()); } - println!("[{:013}] Reverting actions from last migration.", current); + println!("[{current:013}] Reverting actions from last migration."); let migration = self.migrations.get(¤t).unwrap(); let content_down = migration.content_down.as_ref().unwrap(); let content_down = get_content_string!(content_down); self.executor.migrate(&content_down)?; - if !std::env::var("MIGRATIONS_SKIP_LAST").is_err() { + if std::env::var("MIGRATIONS_SKIP_LAST").is_ok() { if migrations_count > 1 { self.executor.delete_last_completed_migration()?; } diff --git a/src/lookup.rs b/src/lookup.rs index b7e3d38..dfffd93 100644 --- a/src/lookup.rs +++ b/src/lookup.rs @@ -37,9 +37,7 @@ fn parse_file(filename: &str) -> Result { let res = match re.captures(filename) { None => { - return Err( - format!("Invalid filename found on {}", filename).into() - ) + return Err(format!("Invalid filename found on {filename}").into()) } Some(c) => c, }; @@ -61,11 +59,10 @@ pub fn build_migration_list( for entry in read_dir(path)? { let entry = entry?; let filename = entry.file_name(); - let info = match parse_file( - filename.to_str().ok_or("Filename is invalid")?, - ) { - Ok(info) => info, - Err(_) => continue, + let Ok(info) = + parse_file(filename.to_str().ok_or("Filename is invalid")?) + else { + continue; }; let file = File::open(entry.path())?; @@ -73,8 +70,10 @@ pub fn build_migration_list( let mut content = String::new(); buf_reader.read_to_string(&mut content)?; - let split_vec: Vec = - content.split("\n").map(|s| s.to_string()).collect(); + let split_vec: Vec = content + .split('\n') + .map(std::string::ToString::to_string) + .collect(); let pos_up = split_vec .iter() diff --git a/src/midas.rs b/src/midas.rs index 3738357..057b0cc 100644 --- a/src/midas.rs +++ b/src/midas.rs @@ -5,7 +5,7 @@ mod sequel; pub(crate) use cli::GenericError; -const PKG_NAME: &'static str = env!("CARGO_PKG_NAME"); +const PKG_NAME: &str = env!("CARGO_PKG_NAME"); fn main() -> Result<(), GenericError> { cli::midas_entry(PKG_NAME, false)?; diff --git a/src/sequel.rs b/src/sequel.rs index bc6b782..c232725 100644 --- a/src/sequel.rs +++ b/src/sequel.rs @@ -3,7 +3,7 @@ pub mod postgres; pub type VecSerial = Vec; -pub trait SequelDriver { +pub trait Driver { fn ensure_migration_schema_exists(&mut self) -> Result<(), Error>; fn ensure_migration_table_exists(&mut self) -> Result<(), Error>; fn drop_migration_table(&mut self) -> Result<(), Error>; diff --git a/src/sequel/postgres.rs b/src/sequel/postgres.rs index 55b5df0..94c06c5 100644 --- a/src/sequel/postgres.rs +++ b/src/sequel/postgres.rs @@ -1,7 +1,7 @@ use log::trace; use postgres::{Client, NoTls}; -use super::{Error, SequelDriver, VecSerial}; +use super::{Driver as SequelDriver, Error, VecSerial}; pub struct Postgres { client: Client, @@ -98,7 +98,7 @@ impl SequelDriver for Postgres { } fn migrate(&mut self, query: &str) -> Result<(), Error> { - self.client.simple_query(&query)?; + self.client.simple_query(query)?; Ok(()) } }