From d3ba8a0e4b4fb9f563f7d8128f9df5e07fdd7034 Mon Sep 17 00:00:00 2001 From: Alex Ameen Date: Wed, 26 Jul 2023 09:54:52 -0500 Subject: [PATCH] v0.1.2: add smoke test to derivation (#6) * test: add smoke test in derivation. bump version to 0.1.2 * change workflow trigger * aggregate matrix jobs results * indent * fix conditional for cancelled jobs --- .github/workflows/test.yml | 19 ++++++++++++----- flake.lock | 6 +++--- main.cc | 42 ++++++++++++++++++++------------------ pkg-fun.nix | 34 ++++++++++++++++-------------- 4 files changed, 58 insertions(+), 43 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 68caef9..1e45254 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,6 @@ name: Test on: + workflow_dispatch: push: branches: - main @@ -7,13 +8,8 @@ on: - '**' - '!**/README*' - '!**/CONTRIBUTING*' - pull_request: types: [opened, synchronize, reopened] - paths: - - '**' - - '!**/README*' - - '!**/CONTRIBUTING*' concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -60,3 +56,16 @@ jobs: - name: Run Tests run: nix develop --no-update-lock-file --command make check -j4 + + all-tests-success: + if: ${{ always() }} + runs-on: ubuntu-latest + name: Tests ( All Systems ) + needs: all-tests + steps: + - if: >- + ${{ + contains( needs.*.result, 'failure' ) || + contains( needs.*.result, 'cancelled' ) + }} + run: exit 1 diff --git a/flake.lock b/flake.lock index 41496d4..8d081f3 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1686178082, - "narHash": "sha256-ll289AxpC7tomi516m5w8yG/U81k3IR68VGui19pRyw=", + "lastModified": 1690378156, + "narHash": "sha256-rWRkHrW/ixoXXDiu5Z6NJ9QodUzufAxT6veTSELEFNA=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "b9e05544c9b0a382d3416d602791a63ec2e63217", + "rev": "fb4debd73182c203a69060cb84e63c9e779c3a49", "type": "github" }, "original": { diff --git a/main.cc b/main.cc index faaf4ec..e3509cf 100644 --- a/main.cc +++ b/main.cc @@ -253,13 +253,6 @@ static const char usageMsg[] = int main( int argc, char * argv[], char ** envp ) { - nix::initNix(); - nix::initGC(); - - nix::evalSettings.pureEval = false; - - nix::EvalState state( {}, nix::openStore() ); - char cmd = '\0'; char * arg = nullptr; @@ -313,24 +306,34 @@ main( int argc, char * argv[], char ** envp ) } } + /* Handle early to avoid initializing `nix' globals. */ + if ( cmd == 'h' ) + { + std::cout << usageMsg << std::endl << std::endl + << "Options:" << std::endl + << " -r parseAndResolveRef" << std::endl + << " -l lockFlake" << std::endl + << " -i INSTALLABLE-URI parseAndResolveRef" << std::endl + << " -u URI parseURI" << std::endl + << " --usage show usage message" << std::endl + << " -h,--help show this message" << std::endl; + return EXIT_SUCCESS; + } + + /* Initialize `nix' globals. */ + nix::initNix(); + nix::initGC(); + + nix::evalSettings.pureEval = false; + + nix::EvalState state( {}, nix::openStore() ); + switch ( cmd ) { case 'r': j = parseAndResolveRef( state, arg ); break; case 'l': j = lockFlake( state, arg ); break; case 'i': j = parseInstallable( state, arg ); break; case 'u': j = parseURI( arg ); break; - case 'h': - std::cout << usageMsg << std::endl << std::endl - << "Options:" << std::endl - << " -r parseAndResolveRef" << std::endl - << " -l lockFlake" << std::endl - << " -i INSTALLABLE-URI parseAndResolveRef" << std::endl - << " -u URI parseURI" << std::endl - << " --usage show usage message" << std::endl - << " -h,--help show this message" << std::endl; - return EXIT_SUCCESS; - break; - default: std::cerr << "Unrecognized command flag: " << argv[1] << std::endl << usageMsg << std::endl; @@ -339,7 +342,6 @@ main( int argc, char * argv[], char ** envp ) break; } - std::cout << j.dump() << std::endl; return EXIT_SUCCESS; diff --git a/pkg-fun.nix b/pkg-fun.nix index 1b2c9a7..36466bd 100644 --- a/pkg-fun.nix +++ b/pkg-fun.nix @@ -14,18 +14,12 @@ , jq }: let - boost_CFLAGS = "-I" + boost + "/include"; - libExt = stdenv.hostPlatform.extensions.sharedLibrary; - nix_INCDIR = nix.dev + "/include"; - batsWith = bats.withLibraries ( p: [ - p.bats-assert - p.bats-file - p.bats-support - ] ); + batsWith = + bats.withLibraries ( p: [p.bats-assert p.bats-file p.bats-support] ); in stdenv.mkDerivation { pname = "parser-util"; - version = "0.1.1"; + version = "0.1.2"; src = builtins.path { path = ./.; filter = name: type: let @@ -48,7 +42,9 @@ in stdenv.mkDerivation { notResult = ( builtins.match "result(-*)?" bname ) == null; in notIgnored && notObject && notResult; }; - inherit boost_CFLAGS nix_INCDIR libExt; + boost_CFLAGS = "-I" + boost + "/include"; + libExt = stdenv.hostPlatform.extensions.sharedLibrary; + nix_INCDIR = nix.dev + "/include"; nativeBuildInputs = [ # required for builds: pkg-config @@ -58,11 +54,6 @@ in stdenv.mkDerivation { jq ]; buildInputs = [nlohmann_json nix.dev boost]; - makeFlags = [ - "libExt='${libExt}'" - "boost_CFLAGS='${boost_CFLAGS}'" - "nix_INCDIR='${nix_INCDIR}'" - ]; configurePhase = '' runHook preConfigure; export PREFIX="$out"; @@ -71,7 +62,20 @@ in stdenv.mkDerivation { fi runHook postConfigure; ''; + + # Real tests require internet connection and cannot be run in a sandbox. + # Still we do a smoke test running `parser-util --help' to catch low hanging + # issues like dynamic library resolution and init processes. doInstallCheck = false; + doCheck = true; + checkPhase = '' + runHook preCheck; + if ! ./bin/parser-util --help >/dev/null; then + echo "FAIL: parser-util --help" >&2; + exit 1; + fi + runHook postCheck; + ''; }