Skip to content

Commit

Permalink
fixes lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
reederc42 committed Jul 26, 2024
1 parent e6eaf5d commit b44e42b
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 18 deletions.
26 changes: 20 additions & 6 deletions ci/src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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::<Vec<String>>());
if !script.is_empty() {
args.extend([
"sh",
"-c",
script,
].into_iter().map(|a| a.to_string()).collect::<Vec<String>>());
}

args
}
Expand Down Expand Up @@ -95,13 +97,25 @@ 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 => {
self.build_docker_image(
&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),
Expand Down
6 changes: 3 additions & 3 deletions ci/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn cmd(args: Cli) {
verbose: args.verbose,
});

let mut runner: Box<dyn Runner> = match args.runner.as_str() {
let runner: Box<dyn Runner> = match args.runner.as_str() {
"docker" => Box::new(docker::Docker{
context: context.clone(),
}),
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -161,5 +161,5 @@ pub enum ExecutionContext {

pub trait Stage {
fn name(&self) -> &'static str;
fn run(&self, context: &Context, runner: &Box<dyn Runner>) -> Result<(), Error>;
fn run(&self, context: &Context, runner: &dyn Runner) -> Result<(), Error>;
}
4 changes: 1 addition & 3 deletions ci/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions ci/src/stages/dev_e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl Stage for DevE2E {
}

// run e2e tests against dev servers
fn run(&self, _context: &Context, runner: &Box<dyn Runner>) -> Result<(), Error> {
fn run(&self, _context: &Context, runner: &dyn Runner) -> Result<(), Error> {
let expiration = 3000;

node_dev_e2e(expiration, runner)?;
Expand All @@ -22,7 +22,7 @@ impl Stage for DevE2E {
}
}

fn node_dev_e2e(expiration: u32, runner: &Box<dyn Runner>) -> Result<(), Error> {
fn node_dev_e2e(expiration: u32, runner: &dyn Runner) -> Result<(), Error> {
let server = runner.run_background(
ExecutionContext::Build,
vec![],
Expand All @@ -42,7 +42,7 @@ fn node_dev_e2e(expiration: u32, runner: &Box<dyn Runner>) -> Result<(), Error>
)
}

fn rust_dev_e2e(expiration: u32, runner: &Box<dyn Runner>) -> Result<(), Error> {
fn rust_dev_e2e(expiration: u32, runner: &dyn Runner) -> Result<(), Error> {
runner.run(
ExecutionContext::Build,
vec![&format!(
Expand Down
2 changes: 1 addition & 1 deletion ci/src/stages/nodejs_checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Runner>) -> Result<(), Error> {
fn run(&self, _context: &Context, runner: &dyn Runner) -> Result<(), Error> {
runner.run(
ExecutionContext::Build,
vec![],
Expand Down
2 changes: 1 addition & 1 deletion ci/src/stages/prepare_contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ impl Stage for PrepareContexts {
}

// run builds test and build images
fn run(&self, context: &Context, runner: &Box<dyn Runner>) -> Result<(), Error> {
fn run(&self, context: &Context, runner: &dyn Runner) -> Result<(), Error> {
let exec_contexts: [ExecutionContext; 3] = [
ExecutionContext::Build,
ExecutionContext::E2E,
Expand Down
2 changes: 1 addition & 1 deletion ci/src/stages/rust_checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ impl Stage for RustChecks {
}

// run runs unit tests and linters for Rust
fn run(&self, _context: &Context, runner: &Box<dyn Runner>) -> 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"],
Expand Down
1 change: 1 addition & 0 deletions wiki/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[derive(Debug, Clone)]
pub enum Error {
Internal(String),
#[allow(dead_code)]
NotFound(String),
BadRequest(String),
Unauthorized(String),
Expand Down

0 comments on commit b44e42b

Please sign in to comment.