From cf83b63f55aace9e65a633bf53d15b052ce884de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Zimmermann?= Date: Tue, 28 Dec 2021 12:26:35 +0100 Subject: [PATCH] Introduce genCrossPlatformNixActions command. This command generates GitHub workflows on Ubuntu and macOS. --- .nix/shellHook.sh | 11 +++++++++++ README.md | 9 +++++---- action.nix | 14 +++++++------- config-parser-1.0.0/default.nix | 2 ++ default.nix | 2 ++ 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/.nix/shellHook.sh b/.nix/shellHook.sh index aa73afed..a48174c9 100644 --- a/.nix/shellHook.sh +++ b/.nix/shellHook.sh @@ -165,6 +165,17 @@ genNixActions (){ } addNixCommand genNixActions +genCrossPlatformNixActions (){ + mkdir -p $currentDir/.github/workflows/ + for t in $bundles; do + for p in "ubuntu" "macos"; do + echo "generating $currentDir/.github/workflows/nix-action-$t-$p.yml" + nix-shell --arg do-nothing true --argstr bundle $t --argstr ci-platform "$p-latest" --run "ppNixAction > $currentDir/.github/workflows/nix-action-$t-$p.yml" + done + done +} +addNixCommand genCrossPlatformNixActions + initNixConfig (){ Orig=$toolboxDir/template-config.nix F=$configDir/config.nix; diff --git a/README.md b/README.md index cf2142d2..e2bba233 100644 --- a/README.md +++ b/README.md @@ -90,14 +90,15 @@ When you run `nix-shell`, you get an environment with a few available commands: - `nixEnv`: displays the list of Nix store locations for all the available packages. - `fetchCoqOverlay`: fetch a derivation file from nixpkgs that you may then edit locally to override a package. - `cachedMake`: compile the project by reusing build outputs cached (generally thanks to Cachix). -- `genNixActions`: generates GitHub one actions file per bundle, for testing dependencies and reverse depndencies. +- `genNixActions`: generates GitHub one actions file per bundle, for testing dependencies and reverse dependencies. +- `genCrossPlatformNixActions`: duplicate generated workflows to run on both Ubuntu and macOS (useful when macOS users want to get cached artifacts as well). These three commands update the nixpkgs version to use (will create or override `.nix/nixpkgs.nix`): - `updateNixpkgsUnstable`: update to the latest nixpkgs-unstable. - `updateNixpkgsMaster`: update to the head of `master` of nixpkgs. - `updateNixpkgs`: update to the specified owner and ref. -After one of these three commands, you should leave and re-enter `nix-shell` if you want the update to be taken into account (e.g., before calling `genNixActions`). +After one of these three commands, you should leave and re-enter `nix-shell` if you want the update to be taken into account. ## Arguments accepted by `nix-shell` @@ -114,7 +115,7 @@ To test a PR on nixpkgs that modifies the `coqPackages` set, clone this reposito ``` nix-shell --arg do-nothing true --run "updateNixpkgs " -nix-shell --arg do-nothing true --run "genNixActions" +nix-shell --arg do-nothing true --run "genCrossPlatformNixActions" ``` Then, open a draft PR with the generated changes here. @@ -123,5 +124,5 @@ Once the PR on nixpkgs has been merged, you can transform the draft PR into one ``` nix-shell --arg do-nothing true --run "updateNixpkgsMaster" -nix-shell --arg do-nothing true --run "genNixActions" +nix-shell --arg do-nothing true --run "genCrossPlatformNixActions" ``` diff --git a/action.nix b/action.nix index aa8b6baa..c763b213 100644 --- a/action.nix +++ b/action.nix @@ -78,13 +78,13 @@ with builtins; with lib; let run = "NIXPKGS_ALLOW_UNFREE=1 nix-build --no-out-link --argstr bundle \"${bundlestr}\" --argstr job \"${job}\""; }; - mkJob = { job, jobs ? [], bundles ? [], deps ? {}, cachix ? {}, suffix ? false }: + mkJob = { job, jobs ? [], bundles ? [], deps ? {}, cachix ? {}, ci-platform, suffix ? false }: let suffixStr = optionalString (suffix && isString bundles) "-${bundles}"; jdeps = deps.${job} or []; in { "${job}${suffixStr}" = rec { - runs-on = "ubuntu-latest"; + runs-on = if ci-platform == null then "ubuntu-latest" else ci-platform; needs = map (j: "${j}${suffixStr}") (filter (j: elem j jobs) jdeps); steps = [ stepCommitToTest stepCheckout stepCachixInstall ] ++ (stepCachixUseAll cachix) @@ -94,11 +94,11 @@ with builtins; with lib; let } // (optionalAttrs (isList bundles) {strategy.matrix.bundle = bundles;}); }; - mkJobs = { jobs ? [], bundles ? [], deps ? {}, cachix ? {}, suffix ? false }@args: + mkJobs = { jobs ? [], bundles ? [], deps ? {}, cachix ? {}, ci-platform, suffix ? false }@args: foldl (action: job: action // (mkJob ({ inherit job; } // args))) {} jobs; - mkActionFromJobs = { actionJobs, bundles ? [] }: { - name = "Nix CI for bundle ${toString bundles}"; + mkActionFromJobs = { actionJobs, bundles ? [], ci-platform }: { + name = "Nix CI for bundle ${toString bundles}${if ci-platform == null then "" else " on platform ${ci-platform}"}"; on = { push.branches = [ "master" ]; pull_request.paths = [ ".github/workflows/**" ]; @@ -107,7 +107,7 @@ with builtins; with lib; let jobs = actionJobs; }; - mkAction = { jobs ? [], bundles ? [], deps ? {}, cachix ? {} }@args: - mkActionFromJobs {inherit bundles; actionJobs = mkJobs args; }; + mkAction = { jobs ? [], bundles ? [], deps ? {}, cachix ? {}, ci-platform ? null }@args: + mkActionFromJobs {inherit bundles ci-platform; actionJobs = mkJobs args; }; in { inherit mkJob mkJobs mkAction; } diff --git a/config-parser-1.0.0/default.nix b/config-parser-1.0.0/default.nix index 0b9e0b85..159ec4d7 100644 --- a/config-parser-1.0.0/default.nix +++ b/config-parser-1.0.0/default.nix @@ -11,6 +11,7 @@ with builtins; override ? {}, ocaml-override ? {}, global-override ? {}, + ci-platform, lib, }@initial: with lib; @@ -59,6 +60,7 @@ in with config; let inherit (import ../action.nix { inherit lib; }) mkJobs mkAction; action = mkAction { inherit (config) cachix; + inherit ci-platform; bundles = bundleName; jobs = let jdeps = genAttrs ci.mains (n: genCI.pkgsRevDepsSet.${n} or {}); diff --git a/default.nix b/default.nix index 3ba6f47c..55071001 100644 --- a/default.nix +++ b/default.nix @@ -17,6 +17,7 @@ in coq-overlays-dir ? get-path src "coq-overlays", ocaml-overlays-dir ? get-path src "ocaml-overlays", ci-matrix ? false, + ci-platform ? null, config ? {}, override ? {}, ocaml-override ? {}, @@ -44,6 +45,7 @@ let // { diag = f: x: f x x; }; inherit overlays-dir coq-overlays-dir ocaml-overlays-dir; inherit global-override override ocaml-override; + inherit ci-platform; }; my-throw = x: throw "Coq nix toolbox error: ${x}"; in