Skip to content

Commit

Permalink
feat: add Nix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
blackheaven committed Nov 4, 2024
1 parent 0fabf22 commit 0b96720
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 2 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 24 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -32,5 +53,7 @@
})
];
};

checks.check = packages.git-cliff-debug;
});
}
4 changes: 4 additions & 0 deletions git-cliff-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)'] }
2 changes: 1 addition & 1 deletion git-cliff-core/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions git-cliff-core/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand All @@ -582,6 +583,7 @@ mod test {
}

#[test]
#[cfg(not(in_nix))]
fn commit_search() -> Result<()> {
let repository = get_repository()?;
assert!(repository
Expand All @@ -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)?;
Expand All @@ -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)?;
Expand Down Expand Up @@ -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()?;
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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
Expand Down Expand Up @@ -771,6 +779,7 @@ mod test {
}

#[test]
#[cfg(not(in_nix))]
fn test_should_retain_commit() {
let (repo, _temp_dir) = create_temp_repo();

Expand Down

0 comments on commit 0b96720

Please sign in to comment.