Skip to content

Commit

Permalink
ci: optimize CI/CD workflow
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Test User committed Jan 31, 2025
1 parent 51034d8 commit 1ccf953
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
30 changes: 22 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -107,14 +117,23 @@ 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:
path: |
~/.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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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));
Expand All @@ -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, ..
Expand Down
3 changes: 2 additions & 1 deletion tests/basic_template_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 1ccf953

Please sign in to comment.