Convert ci tests to nix flake app test-runner

This commit is contained in:
Eric Wolf 2022-04-03 11:20:01 +02:00
parent 7c41549bd4
commit 76eba564f7
4 changed files with 32 additions and 23 deletions

View file

@ -21,4 +21,4 @@ jobs:
keep-derivations = true
experimental-features = nix-command flakes
- run:
nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixpkgs-unstable.tar.gz ci.nix --run 'true'
"nix run .#test-runner"

21
ci.nix
View file

@ -1,21 +0,0 @@
with import <nixpkgs> {};
mkShell {
nativeBuildInputs = [
shellcheck direnv mypy python3.pkgs.black python3.pkgs.flake8
];
shellHook = ''
set -e
echo -e "\x1b[32m## run shellcheck\x1b[0m"
shellcheck direnvrc
echo -e "\x1b[32m## run black\x1b[0m"
LC_ALL=en_US.utf-8 black --check .
echo -e "\x1b[32m## run flake8\x1b[0m"
flake8 --ignore E501 tests
echo -e "\x1b[32m## run mypy\x1b[0m"
mypy tests
echo -e "\x1b[32m## run unittest\x1b[0m"
${pkgs.python3.interpreter} -m unittest discover tests
'';
}

View file

@ -7,8 +7,16 @@
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
defaultPackage = pkgs.callPackage ./default.nix { };
packages = {
default = pkgs.callPackage ./default.nix { };
test-runner = pkgs.callPackage ./run-tests.nix {};
};
defaultPackage = self.packages.${system}.default;
devShell = pkgs.callPackage ./shell.nix { };
apps.test-runner = {
type = "app";
program = "${self.packages.${system}.test-runner}";
};
}) // {
overlay = final: prev: {
nix-direnv = final.callPackage ./default.nix { };

22
run-tests.nix Normal file
View file

@ -0,0 +1,22 @@
{
writeScript,
shellcheck,
direnv,
mypy,
python3,
}:
writeScript "run-tests" ''
set -e
PATH="''${PATH}''${PATH:+":"}${direnv}/bin"
echo -e "\x1b[32m## run shellcheck\x1b[0m"
${shellcheck}/bin/shellcheck direnvrc
echo -e "\x1b[32m## run black\x1b[0m"
LC_ALL=en_US.utf-8 ${python3.pkgs.black}/bin/black --check .
echo -e "\x1b[32m## run flake8\x1b[0m"
${python3.pkgs.flake8}/bin/flake8 --ignore E501 tests
echo -e "\x1b[32m## run mypy\x1b[0m"
${mypy}/bin/mypy tests
echo -e "\x1b[32m## run unittest\x1b[0m"
${python3.interpreter} -m unittest discover tests
''