Skip to content

Commit

Permalink
chore: add some tests
Browse files Browse the repository at this point in the history
Also, wrap `nix-buildkite` so that `nix-instantiate` is in the path
when it runs. (Previously, `nix-buildkite` assumed that `nix` was
installed and in the user's path.)

Signed-off-by: Drew Hess <[email protected]>
  • Loading branch information
dhess committed Oct 11, 2023
1 parent 95df048 commit a5f2d2a
Show file tree
Hide file tree
Showing 15 changed files with 569 additions and 4 deletions.
40 changes: 36 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,15 @@
};

packages = {
inherit (pkgs) nix-buildkite;
inherit (pkgs) nix-buildkite nix-buildkite-unwrapped;
} // (pkgs.lib.optionalAttrs (system == "x86_64-linux") {
inherit (pkgs) nix-buildkite-docker-image;
})
// haskellNixFlake.packages;

checks = haskellNixFlake.checks;
checks = {
inherit (pkgs) nix-buildkite-tests;
} // haskellNixFlake.checks;

apps =
let
Expand Down Expand Up @@ -246,6 +248,7 @@
nodejs-18_x

nixpkgs-fmt
goldplate
]);

shellHook = ''
Expand Down Expand Up @@ -297,12 +300,41 @@
};
};

nix-buildkite-unwrapped = nixBuildkiteFlake.packages."nix-buildkite-plugin:exe:nix-buildkite";

nix-buildkite = final.stdenv.mkDerivation {
name = "nix-buildkite";
src = ./.;
nativeBuildInputs = [
final.makeWrapper
];
installPhase = ''
mkdir -p $out/bin
makeWrapper ${nix-buildkite-unwrapped}/bin/nix-buildkite $out/bin/nix-buildkite \
--suffix PATH : ${final.lib.makeBinPath [final.nix]}
'';

meta = with final.lib; {
description = "Create Buildkite pipelines from Nix attributes.";
homepage = "https://github.com/hackworthltd/nix-buildkite-plugin";
license = licenses.bsd3;
platforms = platforms.all;
mainProgram = "nix-buildkite";
};
};

nix-buildkite-tests = final.callPackage ./nix/pkgs/nix-buildkite-tests {
src = ./tests;
};
in
{
inherit nix-buildkite-unwrapped;
inherit nix-buildkite;
inherit nix-buildkite-plugin;

nix-buildkite = nixBuildkiteFlake.packages."nix-buildkite-plugin:exe:nix-buildkite";
inherit nix-buildkite-docker-image;

inherit (final.haskellPackages) goldplate;
inherit nix-buildkite-tests;
}
);

Expand Down
18 changes: 18 additions & 0 deletions nix/pkgs/nix-buildkite-tests/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{ goldplate
, nix-buildkite
, runCommand
, src
}:
runCommand "nix-buildkite-tests"
{
inherit src;
nativeBuildInputs = [
goldplate
nix-buildkite
];
} ''
set -e
cd $src
goldplate -j2 --pretty-diff .
touch $out
''
1 change: 1 addition & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(import ./flake-compat.nix).defaultNix
9 changes: 9 additions & 0 deletions tests/flake-compat.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
inherit (lock.nodes.flake-compat.locked) owner repo rev narHash;
flake-compat = builtins.fetchTarball {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = narHash;
};
in
import flake-compat { src = ./.; }
Loading

0 comments on commit a5f2d2a

Please sign in to comment.