From 0b9672021300857af3a8e109569ad2b7c7b7fad7 Mon Sep 17 00:00:00 2001 From: Gautier DI FOLCO Date: Tue, 29 Oct 2024 20:13:59 +0100 Subject: [PATCH] feat: add Nix CI --- .github/workflows/ci.yml | 21 +++++++++++++++++++++ Cargo.lock | 12 ++++++++++++ flake.nix | 25 ++++++++++++++++++++++++- git-cliff-core/Cargo.toml | 4 ++++ git-cliff-core/src/command.rs | 2 +- git-cliff-core/src/repo.rs | 9 +++++++++ 6 files changed, 71 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cd55987c1b..a3be4d3653 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -224,3 +224,24 @@ jobs: with: name: git-cliff.${{ github.run_id }}-profiler-report path: git-cliff.**.flamegraph.svg + + nix-flake: + name: Build Nix flake + runs-on: ubuntu-latest + steps: + - name: Checkout the repository + uses: actions/checkout@v4 + + - name: Install Nix + uses: nixbuild/nix-quick-install-action@v27 + + - name: Restore and cache Nix store + uses: nix-community/cache-nix-action@v5 + with: + primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix') }} + restore-prefixes-first-match: nix-${{ runner.os }}- + gc-max-store-size-linux: 1073741824 + purge: false + + - name: Check Nix flake + run: nix flake check --all-systems -Lv --show-trace diff --git a/Cargo.lock b/Cargo.lock index c72aefd92d..8568fa4502 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -915,6 +915,7 @@ dependencies = [ "serde_regex", "temp-dir", "tera", + "test-tag", "thiserror", "time", "tokio", @@ -2757,6 +2758,17 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "test-tag" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc50a89f334d0f92d8665e939ddf8e488c86b8b224a22074ae5895958f369eba" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "thiserror" version = "1.0.64" diff --git a/flake.nix b/flake.nix index dee23cd2b8..6a6c2bae7f 100644 --- a/flake.nix +++ b/flake.nix @@ -15,7 +15,28 @@ inherit system; overlays = [ inputs.rust-overlay.overlays.rust-overlay ]; }; - in { + base-git-cliff = { buildType }: pkgs.rustPlatform.buildRustPackage { + name = "git-cliff"; + src = ./.; + cargoLock = { + lockFile = ./Cargo.lock; + }; + checkType = "debug"; + inherit buildType; + RUSTFLAGS = "--cfg in_nix"; + meta = with pkgs.lib; { + description = "A highly customizable Changelog Generator that follows Conventional Commit specifications"; + homepage = "https://git-cliff.org/"; + license = [ licenses.mit licenses.asl20 ]; + }; + }; + in rec { + packages = rec { + git-cliff = base-git-cliff { buildType = "release"; }; + git-cliff-debug = base-git-cliff { buildType = "debug"; }; + default = git-cliff; + }; + devShell = pkgs.mkShell { CARGO_INSTALL_ROOT = "${toString ./.}/.cargo"; @@ -32,5 +53,7 @@ }) ]; }; + + checks.check = packages.git-cliff-debug; }); } diff --git a/git-cliff-core/Cargo.toml b/git-cliff-core/Cargo.toml index b11afa4757..38da8456c7 100644 --- a/git-cliff-core/Cargo.toml +++ b/git-cliff-core/Cargo.toml @@ -78,6 +78,7 @@ dyn-clone = "1.0.17" urlencoding = "2.1.3" cacache = { version = "13.0.0", features = ["mmap"], default-features = false } time = "0.3.36" +test-tag = "0.1.4" [dependencies.git2] version = "0.19.0" @@ -105,3 +106,6 @@ temp-dir = "0.1.13" [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] + +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(in_nix)'] } diff --git a/git-cliff-core/src/command.rs b/git-cliff-core/src/command.rs index 71a3c652a1..bfe722a91e 100644 --- a/git-cliff-core/src/command.rs +++ b/git-cliff-core/src/command.rs @@ -73,7 +73,7 @@ pub fn run( mod test { use super::*; #[test] - #[cfg(target_family = "unix")] + #[cfg(all(target_family = "unix", not(in_nix)))] fn run_os_command() -> Result<()> { assert_eq!( "eroc-ffilc-tig", diff --git a/git-cliff-core/src/repo.rs b/git-cliff-core/src/repo.rs index 81a930b996..d47844814a 100644 --- a/git-cliff-core/src/repo.rs +++ b/git-cliff-core/src/repo.rs @@ -572,6 +572,7 @@ mod test { } #[test] + #[cfg(not(in_nix))] fn get_latest_commit() -> Result<()> { let repository = get_repository()?; let commits = repository.commits(None, None, None)?; @@ -582,6 +583,7 @@ mod test { } #[test] + #[cfg(not(in_nix))] fn commit_search() -> Result<()> { let repository = get_repository()?; assert!(repository @@ -591,6 +593,7 @@ mod test { } #[test] + #[cfg(not(in_nix))] fn get_latest_tag() -> Result<()> { let repository = get_repository()?; let tags = repository.tags(&None, false, false)?; @@ -603,6 +606,7 @@ mod test { } #[test] + #[cfg(not(in_nix))] fn git_tags() -> Result<()> { let repository = get_repository()?; let tags = repository.tags(&None, true, false)?; @@ -644,6 +648,7 @@ mod test { } #[test] + #[cfg(not(in_nix))] fn git_upstream_remote() -> Result<()> { let repository = get_repository()?; let remote = repository.upstream_remote()?; @@ -660,6 +665,7 @@ mod test { } #[test] + #[cfg(not(in_nix))] fn resolves_existing_tag_with_name_and_message() -> Result<()> { let repository = get_repository()?; let tag = repository.resolve_tag("v0.2.3"); @@ -677,6 +683,7 @@ mod test { } #[test] + #[cfg(not(in_nix))] fn resolves_tag_when_no_tags_exist() -> Result<()> { let repository = get_repository()?; let tag = repository.resolve_tag("nonexistent-tag"); @@ -686,6 +693,7 @@ mod test { } #[test] + #[cfg(not(in_nix))] fn includes_root_commit() -> Result<()> { let repository = get_repository()?; // a close descendant of the root commit @@ -771,6 +779,7 @@ mod test { } #[test] + #[cfg(not(in_nix))] fn test_should_retain_commit() { let (repo, _temp_dir) = create_temp_repo();