From f56595b5e8813a8b2ed7890644fba9aad77ba9aa Mon Sep 17 00:00:00 2001 From: Chris Reeder Date: Wed, 3 Apr 2024 17:57:55 +0000 Subject: [PATCH] adds rust checks --- .github/workflows/ci.yaml | 5 ++++- ci/src/lib.rs | 6 +++++- ci/src/stages.rs | 1 + ci/src/stages/nodejs_checks.rs | 2 ++ ci/src/stages/rust_checks.rs | 17 +++++++++++++++++ images/build.Dockerfile | 2 +- 6 files changed, 30 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index df60281..8d1d0aa 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -63,10 +63,12 @@ jobs: container: image: rust:1.77.0 + user: 1000:1000 volumes: - /var/run/docker.sock env: BUILD_ID: ${{ github.job }}-${{ github.run_id }} + HOST_WORKDIR: ${{ github.workspace }} steps: - uses: actions/checkout@v4 @@ -88,4 +90,5 @@ jobs: apt-get install -y docker-ce-cli - name: Run CI - run: cargo run --bin ci -- --all + run: + cargo run --bin ci -- --all; diff --git a/ci/src/lib.rs b/ci/src/lib.rs index 6061233..42d5395 100644 --- a/ci/src/lib.rs +++ b/ci/src/lib.rs @@ -31,6 +31,7 @@ pub fn cmd(args: Cli) { let all_stages: Vec> = vec![ Box::new(stages::build_images::BuildImages{}), Box::new(stages::nodejs_checks::NodeJSChecks{}), + Box::new(stages::rust_checks::RustChecks{}), ]; if args.list { @@ -42,7 +43,9 @@ pub fn cmd(args: Cli) { let context = Rc::new(Context { id: std::env::var("BUILD_ID").unwrap_or(String::from("local")), - cwd: String::from(std::env::current_dir().unwrap().to_str().unwrap()), + cwd: std::env::var("HOST_WORKDIR").unwrap_or( + String::from(std::env::current_dir().unwrap().to_str().unwrap()) + ), }); let docker = Rc::new(Docker{ context: context.clone(), @@ -131,6 +134,7 @@ impl Runner for Docker { let cmd = Command::new("docker") .args([ "run", + "--rm", "-v", &format!("{}:{}", self.context.cwd, self.context.cwd), "-w", diff --git a/ci/src/stages.rs b/ci/src/stages.rs index c62a179..08581b0 100644 --- a/ci/src/stages.rs +++ b/ci/src/stages.rs @@ -1,2 +1,3 @@ pub mod build_images; pub mod nodejs_checks; +pub mod rust_checks; diff --git a/ci/src/stages/nodejs_checks.rs b/ci/src/stages/nodejs_checks.rs index 4dd054a..041b6a8 100644 --- a/ci/src/stages/nodejs_checks.rs +++ b/ci/src/stages/nodejs_checks.rs @@ -10,6 +10,8 @@ impl Stage for NodeJSChecks { // run runs unit tests and linters for Node.js source fn run(&self, _context: &Context, config: &Config) -> Error { config.runner.run("build", r" + id + ls -lh ln -s /ci/node_modules ./ui/node_modules || true cd ui npm run lint diff --git a/ci/src/stages/rust_checks.rs b/ci/src/stages/rust_checks.rs index e69de29..bf1e56b 100644 --- a/ci/src/stages/rust_checks.rs +++ b/ci/src/stages/rust_checks.rs @@ -0,0 +1,17 @@ +use crate::*; + +pub struct RustChecks {} + +impl Stage for RustChecks { + fn name(&self) -> String { + String::from("rust_checks") + } + + // run runs unit tests and linters for Rust + fn run(&self, _context: &Context, config: &Config) -> Error { + config.runner.run("build", r" + cargo clippy --all-targets --all-features + cargo test --all-targets --all-features + ") + } +} diff --git a/images/build.Dockerfile b/images/build.Dockerfile index 4887a57..ab4dd5f 100644 --- a/images/build.Dockerfile +++ b/images/build.Dockerfile @@ -5,7 +5,7 @@ FROM node:${NODE_VERSION} ARG NPM_VERSION="10.5.0" ARG RUST_VERSION="1.77.0" -RUN npm install -g npm@${NPM_VERSION} +RUN npm install --verbose -g npm@${NPM_VERSION} USER 1000:1000