Skip to content

Commit

Permalink
Add Dockerfile checks for cargo clippy and cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
JamyGolden committed Feb 15, 2024
1 parent c815d30 commit 168c2f1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ jobs:
run:
runs-on: ubuntu-latest
steps:
# Checkout repo
- name: Fetch the repository code
uses: actions/checkout@v4

- name: Deny banned crates and licenses
uses: EmbarkStudios/cargo-deny-action@v1

- name: Build Docker image
run: docker build . -t tinty
- name: Build clippy Stage
run: docker build --target clippy -t tinty-clippy .

- name: Run Docker container
run: docker run tinty
- name: Build fmt stage
run: docker build --target fmt -t tinty-fmt .

- name: Build Test Stage
run: docker build --target test -t tinty-test .
28 changes: 16 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# Use an official Rust runtime as a parent image
FROM rust:latest

# Set the working directory in the container
WORKDIR /usr/src/myapp

# Copy the current directory contents into the container at /usr/src/myapp
# Stage 1: Build Environment
FROM rust:latest AS base
WORKDIR /usr/src/tinty
COPY . .

# Compile the application
RUN cargo build --release

ENV RUST_TEST_THREADS=1
# Stage 2: Run cargo clippy
FROM base AS clippy
RUN rustup component add clippy && \
cargo clippy -- -D warnings

# Stage 3: Run cargo fmt
FROM base as fmt
RUN rustup component add rustfmt && \
cargo fmt --all -- --check

# Run tests
CMD ["cargo", "test"]
# Stage 4: Run tests
FROM base as test
ENV RUST_TEST_THREADS=1
RUN cargo test --release
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ test_docker: setup_tests
@echo "-------------------"
@echo "Running test_docker"
@echo "-------------------"
docker build -t tinty . && docker run tinty
docker build --target clippy -t tinty-clippy .
docker build --target fmt -t tinty-fmt .
docker build --target test -t tinty-test .

test: setup_tests
@echo "------------"
Expand Down
4 changes: 3 additions & 1 deletion src/operations/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ pub fn set(config_path: &Path, data_path: &Path, full_scheme_name: &str) -> Resu

// Collect config items that match the provided system
let system_items = items.iter().filter(|item| match &item.supported_systems {
Some(supported_systems) => supported_systems.contains(&SupportedSchemeSystems::from_str(scheme_system)),
Some(supported_systems) => {
supported_systems.contains(&SupportedSchemeSystems::from_str(scheme_system))
}
None => false,
});

Expand Down
2 changes: 1 addition & 1 deletion tests/cli_set_subcommand_tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod common;

use crate::common::{cleanup, COMMAND_NAME, REPO_NAME};
use anyhow::{Result, anyhow};
use anyhow::{anyhow, Result};
use std::fs;
use std::path::{Path, PathBuf};

Expand Down

0 comments on commit 168c2f1

Please sign in to comment.