add hydra, update ruff, format files
Signed-off-by: ahuston-0 <aliceghuston@gmail.com>
This commit is contained in:
19
hydra/jobs.nix
Normal file
19
hydra/jobs.nix
Normal file
@ -0,0 +1,19 @@
|
||||
{ inputs, outputs }:
|
||||
let
|
||||
inherit (inputs.nixpkgs) lib;
|
||||
|
||||
notBroken = pkg: !(pkg.meta.broken or false);
|
||||
isDistributable = pkg: (pkg.meta.license or { redistributable = true; }).redistributable;
|
||||
hasPlatform = sys: pkg: lib.elem sys (pkg.meta.platforms or [ sys ]);
|
||||
filterValidPkgs =
|
||||
sys: pkgs:
|
||||
lib.filterAttrs (
|
||||
_: pkg: lib.isDerivation pkg && hasPlatform sys pkg && notBroken pkg && isDistributable pkg
|
||||
) pkgs;
|
||||
in
|
||||
# getCfg = _: cfg: cfg.config.system.build.toplevel;
|
||||
{
|
||||
# hosts = lib.mapAttrs getCfg outputs.nixosConfigurations;
|
||||
inherit (outputs) devShells checks formatter;
|
||||
packages = lib.mapAttrs filterValidPkgs outputs.packages;
|
||||
}
|
87
hydra/jobsets.nix
Normal file
87
hydra/jobsets.nix
Normal file
@ -0,0 +1,87 @@
|
||||
{ pulls, branches, ... }:
|
||||
let
|
||||
# create the json spec for the jobset
|
||||
makeSpec =
|
||||
contents:
|
||||
builtins.derivation {
|
||||
name = "spec.json";
|
||||
system = "x86_64-linux";
|
||||
preferLocalBuild = true;
|
||||
allowSubstitutes = false;
|
||||
builder = "/bin/sh";
|
||||
args = [
|
||||
(builtins.toFile "builder.sh" ''
|
||||
echo "$contents" > $out
|
||||
'')
|
||||
];
|
||||
contents = builtins.toJSON contents;
|
||||
};
|
||||
|
||||
prs = readJSONFile pulls;
|
||||
refs = readJSONFile branches;
|
||||
repo = "ahuston-0/canvas_grit_automation";
|
||||
|
||||
# template for creating a job
|
||||
makeJob =
|
||||
{
|
||||
schedulingshares ? 10,
|
||||
keepnr ? 3,
|
||||
description,
|
||||
flake,
|
||||
}:
|
||||
{
|
||||
inherit
|
||||
description
|
||||
flake
|
||||
schedulingshares
|
||||
keepnr
|
||||
;
|
||||
enabled = 1;
|
||||
type = 1;
|
||||
hidden = false;
|
||||
checkinterval = 300; # every 6 months
|
||||
enableemail = false;
|
||||
emailoverride = "";
|
||||
};
|
||||
|
||||
# Create a hydra job for a branch
|
||||
jobOfRef =
|
||||
name:
|
||||
{ ref, ... }:
|
||||
if (builtins.match "^refs/heads/(.*)$" ref) == null then
|
||||
null
|
||||
else
|
||||
{
|
||||
name = builtins.replaceStrings [ "/" ] [ "-" ] "branch-${name}";
|
||||
value = makeJob {
|
||||
description = "Branch ${name}";
|
||||
flake = "git+ssh://git@github.com/${repo}?ref=${ref}";
|
||||
};
|
||||
};
|
||||
|
||||
# Create a hydra job for a PR
|
||||
jobOfPR = id: info: {
|
||||
name = "pr-${id}";
|
||||
value = makeJob {
|
||||
description = "PR ${id}: ${info.title}";
|
||||
flake = "git+ssh://git@github.com/${info.head.repo.full_name}?ref=${info.head.ref}";
|
||||
};
|
||||
};
|
||||
|
||||
# some utility functions
|
||||
# converts json to name/value dicts
|
||||
attrsToList = l: builtins.attrValues (builtins.mapAttrs (name: value: { inherit name value; }) l);
|
||||
# wrapper function for reading json from file
|
||||
readJSONFile = f: builtins.fromJSON (builtins.readFile f);
|
||||
# remove null values from a set, in-case of branches that don't exist
|
||||
mapFilter = f: l: builtins.filter (x: x != null) (map f l);
|
||||
|
||||
# Create job set from PRs and branches
|
||||
jobs = makeSpec (
|
||||
builtins.listToAttrs (map ({ name, value }: jobOfPR name value) (attrsToList prs))
|
||||
// builtins.listToAttrs (mapFilter ({ name, value }: jobOfRef name value) (attrsToList refs))
|
||||
);
|
||||
in
|
||||
{
|
||||
jobsets = jobs;
|
||||
}
|
35
hydra/spec.json
Normal file
35
hydra/spec.json
Normal file
@ -0,0 +1,35 @@
|
||||
{
|
||||
"enabled": 1,
|
||||
"hidden": false,
|
||||
"description": "Canvas grit automation",
|
||||
"nixexprinput": "nixexpr",
|
||||
"nixexprpath": "hydra/jobsets.nix",
|
||||
"checkinterval": 60,
|
||||
"schedulingshares": 100,
|
||||
"enableemail": false,
|
||||
"emailoverride": "",
|
||||
"keepnr": 3,
|
||||
"type": 0,
|
||||
"inputs": {
|
||||
"nixexpr": {
|
||||
"value": "https://github.com/ahuston-0/canvas_grit_automation master",
|
||||
"type": "git",
|
||||
"emailresponsible": false
|
||||
},
|
||||
"nixpkgs": {
|
||||
"value": "https://github.com/NixOS/nixpkgs nixos-unstable-small",
|
||||
"type": "git",
|
||||
"emailresponsible": false
|
||||
},
|
||||
"pulls": {
|
||||
"type": "githubpulls",
|
||||
"value": "ahuston-0 canvas_grit_automation",
|
||||
"emailresponsible": false
|
||||
},
|
||||
"branches": {
|
||||
"type": "github_refs",
|
||||
"value": "ahuston-0 canvas_grit_automation heads -",
|
||||
"emailresponsible": false
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user