From 7928e953fa544dfa6a345757b0ef8b6c55b72038 Mon Sep 17 00:00:00 2001 From: DavHau Date: Sun, 27 Aug 2023 00:18:17 +0200 Subject: [PATCH] checks-integration: init --- .gitea/workflows/checks-integration.yaml | 11 +++++ .gitea/workflows/{check.yaml => checks.yaml} | 2 +- checks/flake-module.nix | 3 ++ checks/integration/flake-module.nix | 50 ++++++++++++++++++++ pkgs/clan-cli/clan_cli/admin.py | 17 +------ templates/new-clan/flake.nix | 1 + 6 files changed, 67 insertions(+), 17 deletions(-) create mode 100644 .gitea/workflows/checks-integration.yaml rename .gitea/workflows/{check.yaml => checks.yaml} (92%) create mode 100644 checks/integration/flake-module.nix diff --git a/.gitea/workflows/checks-integration.yaml b/.gitea/workflows/checks-integration.yaml new file mode 100644 index 00000000..a750e738 --- /dev/null +++ b/.gitea/workflows/checks-integration.yaml @@ -0,0 +1,11 @@ +name: checks-integration +on: + pull_request: + push: + branches: main +jobs: + test: + runs-on: nix + steps: + - uses: actions/checkout@v3 + - run: nix run .#checks-integration diff --git a/.gitea/workflows/check.yaml b/.gitea/workflows/checks.yaml similarity index 92% rename from .gitea/workflows/check.yaml rename to .gitea/workflows/checks.yaml index 47dae993..ca84d435 100644 --- a/.gitea/workflows/check.yaml +++ b/.gitea/workflows/checks.yaml @@ -1,4 +1,4 @@ -name: build +name: checks on: pull_request: push: diff --git a/checks/flake-module.nix b/checks/flake-module.nix index c5e92ac5..631aef66 100644 --- a/checks/flake-module.nix +++ b/checks/flake-module.nix @@ -1,4 +1,7 @@ { self, ... }: { + imports = [ + ./integration/flake-module.nix + ]; perSystem = { pkgs, lib, self', ... }: { checks = let diff --git a/checks/integration/flake-module.nix b/checks/integration/flake-module.nix new file mode 100644 index 00000000..3f51a34e --- /dev/null +++ b/checks/integration/flake-module.nix @@ -0,0 +1,50 @@ +{ self, ... }: { + perSystem = { pkgs, lib, self', ... }: + let + integrationTests = { + check-clan-create = pkgs.writeShellScriptBin "check-clan-init" '' + #!${pkgs.bash}/bin/bash + set -euo pipefail + export TMPDIR=$(${pkgs.coreutils}/bin/mktemp -d) + trap "${pkgs.coreutils}/bin/chmod -R +w '$TMPDIR'; ${pkgs.coreutils}/bin/rm -rf '$TMPDIR'" EXIT + export PATH="${lib.makeBinPath [ + pkgs.git + pkgs.gnugrep + pkgs.nix + self'.packages.clan-cli + ]}" + + cd $TMPDIR + + echo initialize new clan + nix flake init -t ${self}#new-clan + + echo ensure flake outputs can be listed + nix flake show + + echo create a machine + clan machines create machine1 + + echo check machine1 exists + clan machines list | grep -q machine1 + + echo check machine1 appears in flake output + nix flake show | grep -q machine1 + ''; + }; + in + { + packages = + integrationTests // { + # a script that executes all other checks + checks-integration = pkgs.writeShellScriptBin "checks-integration" '' + #!${pkgs.bash}/bin/bash + set -euo pipefail + ${lib.concatMapStringsSep "\n" (name: '' + echo -e "\n\nrunning check ${name}\n" + ${integrationTests.${name}}/bin/* + '') (lib.attrNames integrationTests)} + ''; + }; + }; +} diff --git a/pkgs/clan-cli/clan_cli/admin.py b/pkgs/clan-cli/clan_cli/admin.py index 3a42dc36..2efe0816 100644 --- a/pkgs/clan-cli/clan_cli/admin.py +++ b/pkgs/clan-cli/clan_cli/admin.py @@ -7,7 +7,7 @@ import subprocess def create(args: argparse.Namespace) -> None: os.makedirs(args.folder, exist_ok=True) # TODO create clan template in flake - subprocess.Popen( + subprocess.run( [ "nix", "flake", @@ -18,17 +18,6 @@ def create(args: argparse.Namespace) -> None: ) -def git(args: argparse.Namespace) -> None: - subprocess.Popen( - [ - "git", - "-C", - args.folder, - ] - + args.git_args - ) - - # takes a (sub)parser and configures it def register_parser(parser: argparse.ArgumentParser) -> None: parser.add_argument( @@ -46,7 +35,3 @@ def register_parser(parser: argparse.ArgumentParser) -> None: parser_create = subparser.add_parser("create", help="create a new clan") parser_create.set_defaults(func=create) - - parser_git = subparser.add_parser("git", help="control the clan repo via git") - parser_git.add_argument("git_args", nargs="*") - parser_git.set_defaults(func=git) diff --git a/templates/new-clan/flake.nix b/templates/new-clan/flake.nix index ca463ed0..c9fa8272 100644 --- a/templates/new-clan/flake.nix +++ b/templates/new-clan/flake.nix @@ -8,6 +8,7 @@ outputs = inputs @ { flake-parts, ... }: flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ "x86_64-linux" ]; imports = [ ./clan-flake-module.nix ];