From 1ccf95380c6a7a57a19d01c9594be61355ff5581 Mon Sep 17 00:00:00 2001 From: Test User Date: Thu, 30 Jan 2025 20:47:49 -0700 Subject: [PATCH] ci: optimize CI/CD workflow - Add specific Clippy lints to match local development - Pin Rust toolchain version to 1.70.0 - Enhance caching strategy for faster builds - Fix target specification in toolchain installation - Add RUSTFLAGS for consistent linting across environments --- .github/workflows/build.yml | 30 ++++++++++++++++++++++-------- src/cli/mod.rs | 8 ++++---- tests/basic_template_test.rs | 3 ++- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 53eaffb..4738d6e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,6 +15,8 @@ env: CARGO_TERM_COLOR: always RUST_BACKTRACE: 1 CARGO_NET_RETRY: 2 + RUSTFLAGS: "-D warnings -D clippy::redundant-pattern-matching -D clippy::needless-borrows-for-generic-args" + RUST_VERSION: "1.70.0" permissions: contents: read @@ -30,6 +32,7 @@ jobs: uses: dtolnay/rust-toolchain@stable with: components: rustfmt, clippy + toolchain: ${{ env.RUST_VERSION }} - name: Cache cargo registry uses: actions/cache@v3 @@ -38,13 +41,20 @@ jobs: ~/.cargo/registry ~/.cargo/git target - key: ${{ runner.os }}-cargo-lint-${{ hashFiles('**/Cargo.lock') }} + ~/.rustup + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml', 'rust-toolchain.toml') }} + restore-keys: | + ${{ runner.os }}-cargo- - name: Check formatting run: cargo fmt --all -- --check - name: Run clippy - run: cargo clippy --all-targets --all-features -- -D warnings + run: | + cargo clippy --all-targets --all-features -- \ + -D warnings \ + -D clippy::redundant-pattern-matching \ + -D clippy::needless-borrows-for-generic-args - name: Install cargo-deny run: cargo install --locked cargo-deny @@ -107,6 +117,12 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + target: ${{ matrix.target }} + toolchain: ${{ env.RUST_VERSION }} + - name: Cache cargo registry uses: actions/cache@v3 with: @@ -114,7 +130,10 @@ jobs: ~/.cargo/registry ~/.cargo/git target - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + ~/.rustup + key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml', 'rust-toolchain.toml') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.target }}-cargo- - name: Cache cargo bin uses: actions/cache@v3 @@ -137,11 +156,6 @@ jobs: # Set environment variable for tests to use the template echo "GIT_CONFIG_GLOBAL=/tmp/git-template/config" >> $GITHUB_ENV - - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@stable - with: - targets: ${{ matrix.target }} - - name: Install cross (if needed) if: matrix.use_cross run: cargo install cross diff --git a/src/cli/mod.rs b/src/cli/mod.rs index b6c547c..8ebd993 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -145,13 +145,13 @@ mod tests { #[test] fn test_list_command_parsing() { - let cli = Cli::try_parse_from(&["essex", "list"]).unwrap(); + let cli = Cli::try_parse_from(["essex", "list"]).unwrap(); assert!(matches!(cli.command, Commands::List)); } #[test] fn test_new_command_parsing() { - let cli = Cli::try_parse_from(&[ + let cli = Cli::try_parse_from([ "essex", "new", "basic", @@ -181,7 +181,7 @@ mod tests { #[test] fn test_completion_command_parsing() { - let cli = Cli::try_parse_from(&["essex", "completion", "bash"]).unwrap(); + let cli = Cli::try_parse_from(["essex", "completion", "bash"]).unwrap(); match cli.command { Commands::Completion { shell, output } => { assert!(matches!(shell, Shell::Bash)); @@ -193,7 +193,7 @@ mod tests { #[test] fn test_validate_template() { - let cli = Cli::try_parse_from(&["essex", "new", "basic", "test/project"]).unwrap(); + let cli = Cli::try_parse_from(["essex", "new", "basic", "test/project"]).unwrap(); match cli.command { Commands::New { template, project, .. diff --git a/tests/basic_template_test.rs b/tests/basic_template_test.rs index c71f462..4e0a520 100644 --- a/tests/basic_template_test.rs +++ b/tests/basic_template_test.rs @@ -6,10 +6,11 @@ use tempfile::TempDir; fn setup_git_config(project_dir: &PathBuf) { // Try local config first - if let Err(_) = StdCommand::new("git") + if StdCommand::new("git") .args(["config", "--local", "user.email", "test@example.com"]) .current_dir(project_dir) .output() + .is_err() { // Fallback to global config if local fails StdCommand::new("git")