From b44e42b4a62c71fa2c0d49df599f23539a6d8571 Mon Sep 17 00:00:00 2001 From: Chris Reeder Date: Fri, 26 Jul 2024 18:57:59 +0000 Subject: [PATCH] fixes lint errors --- ci/src/docker.rs | 26 ++++++++++++++++++++------ ci/src/lib.rs | 6 +++--- ci/src/shell.rs | 4 +--- ci/src/stages/dev_e2e.rs | 6 +++--- ci/src/stages/nodejs_checks.rs | 2 +- ci/src/stages/prepare_contexts.rs | 2 +- ci/src/stages/rust_checks.rs | 2 +- wiki/src/error.rs | 1 + 8 files changed, 31 insertions(+), 18 deletions(-) diff --git a/ci/src/docker.rs b/ci/src/docker.rs index af4ff85..37b9c5d 100644 --- a/ci/src/docker.rs +++ b/ci/src/docker.rs @@ -2,7 +2,7 @@ use std::process::Command; use crate::*; -// Latest postgres image: https://hub.docker.com/_/postgres/tags +// Latest postgres version: https://hub.docker.com/_/postgres/tags const POSTGRES_IMAGE: &str = "postgres:16-alpine"; pub struct Docker { @@ -43,11 +43,13 @@ impl Docker { ExecutionContext::Postgres => args.push(POSTGRES_IMAGE.into()), } - args.extend([ - "sh", - "-c", - script, - ].into_iter().map(|a| a.to_string()).collect::>()); + if !script.is_empty() { + args.extend([ + "sh", + "-c", + script, + ].into_iter().map(|a| a.to_string()).collect::>()); + } args } @@ -95,6 +97,12 @@ impl Runner for Docker { &format!("wiki-ci:build-{}", build_context.id), &format!("{}/images/build.Dockerfile", build_context.cwd), &build_context.cwd, + )?; + self.run( + ExecutionContext::Build, + vec![], + true, + "ln -s /ci/ui/node_modules ui/node_modules || true", ) }, ExecutionContext::E2E => { @@ -102,6 +110,12 @@ impl Runner for Docker { &format!("wiki-ci:e2e-{}", build_context.id), &format!("{}/images/e2e.Dockerfile", build_context.cwd), &build_context.cwd, + )?; + self.run( + ExecutionContext::Build, + vec![], + true, + "ln -s /ci/ui/node_modules ui/node_modules || true", ) }, ExecutionContext::Postgres => self.pull_postgres_image(POSTGRES_IMAGE), diff --git a/ci/src/lib.rs b/ci/src/lib.rs index 1d6a9f9..d20bae0 100644 --- a/ci/src/lib.rs +++ b/ci/src/lib.rs @@ -70,7 +70,7 @@ pub fn cmd(args: Cli) { verbose: args.verbose, }); - let mut runner: Box = match args.runner.as_str() { + let runner: Box = match args.runner.as_str() { "docker" => Box::new(docker::Docker{ context: context.clone(), }), @@ -98,7 +98,7 @@ pub fn cmd(args: Cli) { println!("::group::Stage: {}", s.name()); } - if let Err(e) = s.run(&context, &mut runner) { + if let Err(e) = s.run(&context, runner.as_ref()) { println!("Stage error: {:?}", e); stages_failed += 1; if args.fail_fast { @@ -161,5 +161,5 @@ pub enum ExecutionContext { pub trait Stage { fn name(&self) -> &'static str; - fn run(&self, context: &Context, runner: &Box) -> Result<(), Error>; + fn run(&self, context: &Context, runner: &dyn Runner) -> Result<(), Error>; } diff --git a/ci/src/shell.rs b/ci/src/shell.rs index f522407..7f5a366 100644 --- a/ci/src/shell.rs +++ b/ci/src/shell.rs @@ -126,9 +126,7 @@ impl Shell { finished_print = Some(print_command(cmd, true)); } - if let Err(err) = spawn_result_to_result(cmd.spawn(), finished_print) { - return Err(err); - } + spawn_result_to_result(cmd.spawn(), finished_print)?; let mut prog = Command::new("pg_ctl"); let cmd = prog diff --git a/ci/src/stages/dev_e2e.rs b/ci/src/stages/dev_e2e.rs index 3b99d98..fcf7451 100644 --- a/ci/src/stages/dev_e2e.rs +++ b/ci/src/stages/dev_e2e.rs @@ -13,7 +13,7 @@ impl Stage for DevE2E { } // run e2e tests against dev servers - fn run(&self, _context: &Context, runner: &Box) -> Result<(), Error> { + fn run(&self, _context: &Context, runner: &dyn Runner) -> Result<(), Error> { let expiration = 3000; node_dev_e2e(expiration, runner)?; @@ -22,7 +22,7 @@ impl Stage for DevE2E { } } -fn node_dev_e2e(expiration: u32, runner: &Box) -> Result<(), Error> { +fn node_dev_e2e(expiration: u32, runner: &dyn Runner) -> Result<(), Error> { let server = runner.run_background( ExecutionContext::Build, vec![], @@ -42,7 +42,7 @@ fn node_dev_e2e(expiration: u32, runner: &Box) -> Result<(), Error> ) } -fn rust_dev_e2e(expiration: u32, runner: &Box) -> Result<(), Error> { +fn rust_dev_e2e(expiration: u32, runner: &dyn Runner) -> Result<(), Error> { runner.run( ExecutionContext::Build, vec![&format!( diff --git a/ci/src/stages/nodejs_checks.rs b/ci/src/stages/nodejs_checks.rs index 2a25655..9fd7e7f 100644 --- a/ci/src/stages/nodejs_checks.rs +++ b/ci/src/stages/nodejs_checks.rs @@ -8,7 +8,7 @@ impl Stage for NodeJSChecks { } // run runs unit tests and linters for Node.js source - fn run(&self, _context: &Context, runner: &Box) -> Result<(), Error> { + fn run(&self, _context: &Context, runner: &dyn Runner) -> Result<(), Error> { runner.run( ExecutionContext::Build, vec![], diff --git a/ci/src/stages/prepare_contexts.rs b/ci/src/stages/prepare_contexts.rs index f4c0a81..54d57e9 100644 --- a/ci/src/stages/prepare_contexts.rs +++ b/ci/src/stages/prepare_contexts.rs @@ -8,7 +8,7 @@ impl Stage for PrepareContexts { } // run builds test and build images - fn run(&self, context: &Context, runner: &Box) -> Result<(), Error> { + fn run(&self, context: &Context, runner: &dyn Runner) -> Result<(), Error> { let exec_contexts: [ExecutionContext; 3] = [ ExecutionContext::Build, ExecutionContext::E2E, diff --git a/ci/src/stages/rust_checks.rs b/ci/src/stages/rust_checks.rs index 4fd9c40..199eaf3 100644 --- a/ci/src/stages/rust_checks.rs +++ b/ci/src/stages/rust_checks.rs @@ -8,7 +8,7 @@ impl Stage for RustChecks { } // run runs unit tests and linters for Rust - fn run(&self, _context: &Context, runner: &Box) -> Result<(), Error> { + fn run(&self, _context: &Context, runner: &dyn Runner) -> Result<(), Error> { let db = runner.run_background( ExecutionContext::Postgres, vec!["POSTGRES_HOST_AUTH_METHOD=trust"], diff --git a/wiki/src/error.rs b/wiki/src/error.rs index 1ff932e..2c5b356 100644 --- a/wiki/src/error.rs +++ b/wiki/src/error.rs @@ -1,6 +1,7 @@ #[derive(Debug, Clone)] pub enum Error { Internal(String), + #[allow(dead_code)] NotFound(String), BadRequest(String), Unauthorized(String),