Speed up CI

This commit is contained in:
Ajeet D'Souza 2022-04-25 14:45:46 +05:30
parent bf54e7f0cd
commit 3620189582
6 changed files with 41 additions and 14 deletions

View File

@ -4,6 +4,11 @@ on:
branches: [main]
pull_request:
workflow_dispatch:
env:
CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }}
CARGO_INCREMENTAL: 0
jobs:
ci:
name: ${{ matrix.os }}
@ -24,10 +29,20 @@ jobs:
components: rustfmt, clippy
profile: minimal
override: true
- uses: cachix/install-nix-action@v15
- uses: cachix/install-nix-action@v16
if: ${{ matrix.os != 'windows-latest' }}
with:
nix_path: nixpkgs=channel:nixpkgs-unstable
nix_path: nixpkgs=channel:nixos-unstable
- uses: cachix/cachix-action@v10
if: ${{ matrix.os != 'windows-latest' && env.CACHIX_AUTH_TOKEN != '' }}
with:
authToken: ${{ env.CACHIX_AUTH_TOKEN }}
name: zoxide
- name: Setup cache
uses: Swatinem/rust-cache@v1
if:
${{ matrix.os == 'windows-latest' }}
- run: cargo xtask ci
if: ${{ matrix.os == 'windows-latest' }}

View File

@ -6,6 +6,9 @@ on:
pull_request:
workflow_dispatch:
env:
CARGO_INCREMENTAL: 0
jobs:
release:
name: ${{ matrix.target }}
@ -58,6 +61,9 @@ jobs:
override: true
target: ${{ matrix.target }}
- name: Setup cache
uses: Swatinem/rust-cache@v1
- name: Build binary
uses: actions-rs/cargo@v1
with:

View File

@ -29,7 +29,10 @@ ordered-float = "2.0.0"
serde = { version = "1.0.116", features = ["derive"] }
[target.'cfg(unix)'.dependencies]
nix = { version = "0.24.1", default-features = false, features = ["fs", "user"] }
nix = { version = "0.24.1", default-features = false, features = [
"fs",
"user",
] }
[build-dependencies]
clap = { version = "3.1.0", features = ["derive"] }
@ -46,7 +49,11 @@ tempfile = "3.1.0"
default = []
nix-dev = []
[profile.dev]
debug = 0
[profile.release]
codegen-units = 1
debug = 0
lto = true
strip = true

2
Cross.toml Normal file
View File

@ -0,0 +1,2 @@
[build.env]
passthrough = ["CARGO_INCREMENTAL"]

View File

@ -38,5 +38,6 @@ in pkgs.mkShell {
pkgs.libiconv
];
RUST_BACKTRACE = 1;
CARGO_INCREMENTAL = builtins.getEnv "CI" != "";
CARGO_TARGET_DIR = "target_nix";
}

View File

@ -54,8 +54,13 @@ impl CommandExt for &mut Command {
}
fn run_ci(nix_enabled: bool) -> Result<()> {
// Run cargo-clippy.
let color: &[&str] = if is_ci() { &["--color=always"] } else { &[] };
Command::new("cargo").args(&["check", "--all-features"]).args(color)._run()?;
Command::new("cargo")
.args(&["clippy", "--all-features", "--all-targets"])
.args(color)
.args(&["--", "-Dwarnings"])
._run()?;
run_fmt(nix_enabled, true)?;
run_lint(nix_enabled)?;
@ -84,14 +89,6 @@ fn run_fmt(nix_enabled: bool, check: bool) -> Result<()> {
}
fn run_lint(nix_enabled: bool) -> Result<()> {
// Run cargo-clippy.
let color: &[&str] = if is_ci() { &["--color=always"] } else { &[] };
Command::new("cargo")
.args(&["clippy", "--all-features", "--all-targets"])
.args(color)
.args(&["--", "-Dwarnings"])
._run()?;
if nix_enabled {
// Run cargo-audit.
let color: &[&str] = if is_ci() { &["--color=always"] } else { &[] };
@ -136,7 +133,6 @@ fn enable_nix() -> bool {
}
let nix_enabled = env::var_os("IN_NIX_SHELL").unwrap_or_default() == "pure";
if nix_enabled {
env::set_var("CARGO_TARGET_DIR", "target_nix");
return true;
}
let nix_detected = Command::new("nix-shell").arg("--version").status().map(|s| s.success()).unwrap_or(false);