Skip to content

Instantly share code, notes, and snippets.

@lovesegfault
Created March 12, 2020 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lovesegfault/bf4b90d1144c9cf1f7a660154e361f74 to your computer and use it in GitHub Desktop.
Save lovesegfault/bf4b90d1144c9cf1f7a660154e361f74 to your computer and use it in GitHub Desktop.
{ lib ? import <nixpkgs/lib>
, pkgs ? import <nixpkgs>
}:
with builtins; with lib;
let
ciPath = "./.github/workflows/ci.yml";
checkout = {
name = "Checkout";
uses = "actions/checkout@v2";
};
nix = {
name = "Nix";
uses = "cachix/install-nix-action@v7";
};
mkJob = extraSteps: {
runs-on = "ubuntu-latest";
steps = [ checkout nix ] ++ extraSteps;
};
ci = {
on.push.branches = [ "*" ];
name = "CI";
jobs = {
parsing = mkJob [{
name = "Parsing";
run = "find . -name \"*.nix\" -exec nix-instantiate --parse --quiet {} >/dev/null +";
}];
mypy = mkJob [{
name = "MyPy";
run = "nix-shell --run \"mypy nixos\"";
}];
black = [{
name = "Black";
run = "nix-shell --run \"black . --check --diff\"";
}];
coverage = [{
name = "Coverage";
run = "nix-shell --exclude tarball --run \"./coverage-tests.py -a '!libvirtd,!gce,!ec2,!azure' -v\"";
}];
build = [{
name = "Build";
run = "nix-build --quiet release.nix -A build.x86_64-linux -I nixpkgs=channel:19.09";
}];
ciCheck = [{
name = "Check CI";
run = ''
cp ${ciPath} /tmp/ci.reference.yml
nix-build ci.nix | bash
diff ${ciPath} /tmp/ci.reference.yml || exit 1
'';
}];
};
};
generated = pkgs.writeText "ci.yml" (builtins.toJSON ci);
in
pkgs.writeShellScript "gen_ci" ''
mkdir -p "$(dirname ${ciPath})"
cat ${generated} > ${ciPath}
''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment