feat: indexers: add build-all app

This commit is contained in:
DavHau 2022-09-07 14:02:24 +02:00
parent 12267818db
commit 05578072bf

View File

@ -80,6 +80,7 @@ in rec {
''; '';
in in
mkApp script; mkApp script;
mkTranslateApp = name: mkTranslateApp = name:
mkApp ( mkApp (
pkgs.writers.writeBash "translate-${name}" '' pkgs.writers.writeBash "translate-${name}" ''
@ -88,7 +89,8 @@ in rec {
${name}/index.json ${name}/locks ${name}/index.json ${name}/locks
'' ''
); );
mkCiJobApp = name: input:
mkCiAppWith = commands:
mkApp ( mkApp (
utils.writePureShellScript utils.writePureShellScript
(with pkgs; [ (with pkgs; [
@ -109,12 +111,19 @@ in rec {
rm -rf ./* rm -rf ./*
echo "$flake" > flake.nix echo "$flake" > flake.nix
echo "$flakeLock" > flake.lock echo "$flakeLock" > flake.lock
${(mkIndexApp name input).program} ${commands}
${(mkTranslateApp name).program}
git add . git add .
git commit -m "automatic update - $(date --rfc-3339=seconds)" git commit -m "automatic update - $(date --rfc-3339=seconds)"
'' ''
); );
mkCiJobApp = name: input:
mkCiAppWith
''
${(mkIndexApp name input).program}
${(mkTranslateApp name).program}
'';
translateApps = l.listToAttrs ( translateApps = l.listToAttrs (
l.map l.map
( (
@ -125,6 +134,7 @@ in rec {
) )
indexNames indexNames
); );
indexApps = l.listToAttrs ( indexApps = l.listToAttrs (
l.mapAttrsToList l.mapAttrsToList
( (
@ -135,6 +145,7 @@ in rec {
) )
indexes indexes
); );
ciJobApps = l.listToAttrs ( ciJobApps = l.listToAttrs (
l.mapAttrsToList l.mapAttrsToList
( (
@ -145,30 +156,63 @@ in rec {
) )
indexes indexes
); );
ciJobAllApp = mkApp (
ciJobAllApp =
mkCiAppWith
''
${lib.concatStringsSep "\n" (l.mapAttrsToList (_: app: app.program) indexApps)}
${lib.concatStringsSep "\n" (l.mapAttrsToList (_: app: app.program) translateApps)}
'';
buildAllApp = let
buildScript =
pkgs.writers.writePython3 "build-job" {}
''
import sys
import subprocess as sp
from pathlib import path
input = json.load(open(sys.argv[1]))
attr = input['attr']
attrPath = '.'.join(input['attrPath'])
if "error" in input:
print(
f"Evaluation failed. attr: {attr} attrPath: {attrPath}\nError:\n{error}",
file=sys.stderr
)
else:
name = input['name']
drvPath = input['drvPath']
print(
f"Building {name}. attr: {attr} attrPath: {attrPath}\nError:\n{error}",
file=sys.stderr
)
try:
proc = sp.run(
['nix', 'build', drvPath],
capture_output = true,
check=True,
)
except sp.CalledProcessError as error:
Path('errors').mkdir(exist_ok=True)
with open(f'errors/{name}') as f:
f.write(error.stderr)
'';
in
mkApp (
utils.writePureShellScript utils.writePureShellScript
(with pkgs; [ (with pkgs; [
coreutils coreutils
git git
gnugrep parallel
openssh nix
nix-eval-jobs
]) ])
'' ''
flake=$(cat flake.nix) JOBS=''${JOBS:-$(nproc)}
flakeLock=$(cat flake.lock) parallel --halt now,fail=1 -j$JOBS --link \
set -x -a <(nix-eval-jobs --gc-roots-dir $(pwd)/gcroot --flake $(realpath .)#packages.x86_64-linux --workers $JOBS) \
git fetch origin data || : ${buildScript}
git checkout origin/data || :
git branch -D data || :
git checkout -b data
# the flake should always be the one from the current main branch
rm -rf ./*
echo "$flake" > flake.nix
echo "$flakeLock" > flake.lock
${lib.concatStringsSep "\n" (l.mapAttrsToList (_: app: app.program) indexApps)}
${lib.concatStringsSep "\n" (l.mapAttrsToList (_: app: app.program) translateApps)}
git add .
git commit -m "automatic update - $(date --rfc-3339=seconds)"
'' ''
); );
@ -200,6 +244,7 @@ in rec {
packages = allPackages; packages = allPackages;
apps = apps =
{ci-job-all = ciJobAllApp;} {ci-job-all = ciJobAllApp;}
// {build-all = buildAllApp;}
// indexApps // indexApps
// translateApps // translateApps
// ciJobApps; // ciJobApps;