Skip to content

Commit

Permalink
attempt to use nix to run tests in github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
akshaykarle committed Oct 11, 2024
1 parent c793c05 commit 81c15a8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,4 @@ jobs:
- name: Run `nix build`
run: nix build .
- name: Run tests
run: |
nix develop .#poetry
poetry install
poetry run pytest
run: nix run .#tests
49 changes: 37 additions & 12 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,35 @@
};
};

outputs = { self, nixpkgs, flake-utils, poetry2nix }:
flake-utils.lib.eachDefaultSystem (system:
outputs =
{
self,
nixpkgs,
flake-utils,
poetry2nix,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
# see https://github.com/nix-community/poetry2nix/tree/master#api for more functions and examples.
myapp = { poetry2nix, lib }:
myapp =
{ poetry2nix, lib }:
poetry2nix.mkPoetryApplication {
projectDir = self;
overrides = poetry2nix.overrides.withDefaults (final: super:
lib.mapAttrs (attr: systems:
super.${attr}.overridePythonAttrs (old: {
nativeBuildInputs = (old.nativeBuildInputs or [ ])
++ map (a: final.${a}) systems;
})) {
overrides = poetry2nix.overrides.withDefaults (
final: super:
lib.mapAttrs
(
attr: systems:
super.${attr}.overridePythonAttrs (old: {
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ map (a: final.${a}) systems;
})
)
{
# https://github.com/nix-community/poetry2nix/blob/master/docs/edgecases.md#modulenotfounderror-no-module-named-packagename
# package = [ "setuptools" ];
});
}
);
};
pkgs = import nixpkgs {
inherit system;
Expand All @@ -35,7 +48,8 @@
(final: _: { myapp = final.callPackage myapp { }; })
];
};
in {
in
{
packages.default = pkgs.myapp;
devShells = {
# Shell for app dependencies.
Expand All @@ -53,5 +67,16 @@
poetry = pkgs.mkShell { packages = [ pkgs.poetry ]; };
};
legacyPackages = pkgs;
});
tests = {
type = "app";
program = ''
export POETRY_HOME=${pkgs.poetry}
export POETRY_BINARY=${pkgs.poetry}/bin/poetry
export POETRY_VIRTUALENVS_IN_PROJECT=true
echo "[nix][test] Run presidio-vault tests."
poetry run pytest
'';
};
}
);
}

0 comments on commit 81c15a8

Please sign in to comment.