Skip to content

Commit

Permalink
Speed up CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ajeetdsouza committed Apr 25, 2022
1 parent bf54e7f commit 3620189
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 14 deletions.
19 changes: 17 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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' }}
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
pull_request:
workflow_dispatch:

env:
CARGO_INCREMENTAL: 0

jobs:
release:
name: ${{ matrix.target }}
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand All @@ -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 changes: 2 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build.env]
passthrough = ["CARGO_INCREMENTAL"]
3 changes: 2 additions & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ in pkgs.mkShell {
pkgs.libiconv
];

RUST_BACKTRACE = 1;
CARGO_INCREMENTAL = builtins.getEnv "CI" != "";
CARGO_TARGET_DIR = "target_nix";
}
16 changes: 6 additions & 10 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -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 { &[] };
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3620189

Please sign in to comment.