about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-06-02T17·42+0000
committertazjin <tazjin@tvl.su>2022-06-03T17·36+0000
commitcf00365f84d4d59e8054a8de0918591e15041bbb (patch)
treef3240200bee69c76d789e9e2eba46246adeff7b6
parent876b71f6417ea0489e16dbd8c1e11794d4e3ab10 (diff)
feat(nix/buildkite): Validate available phases in extra steps r/4205
This will avoid things like extra steps being accidentally ignored
because of typos.

Change-Id: Ic4fa5925e42a7a449f89b4cde1510e216e91da6a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/5827
Reviewed-by: ezemtsov <eugene.zemtsov@gmail.com>
Tested-by: BuildkiteCI
-rw-r--r--nix/buildkite/default.nix18
1 files changed, 13 insertions, 5 deletions
diff --git a/nix/buildkite/default.nix b/nix/buildkite/default.nix
index 6a24fea074..5b83f9c661 100644
--- a/nix/buildkite/default.nix
+++ b/nix/buildkite/default.nix
@@ -13,6 +13,7 @@ let
     attrValues
     concatLists
     concatStringsSep
+    elem
     foldl'
     hasAttr
     hashString
@@ -165,7 +166,7 @@ rec {
 
           # Split extra steps by phase.
           splitExtraSteps = lib.groupBy ({ phase, ... }: phase)
-            (attrValues (mapAttrs (normaliseExtraStep overridable)
+            (attrValues (mapAttrs (normaliseExtraStep phases overridable)
               (target.meta.ci.extraSteps or { })));
 
           extraSteps = mapAttrs (_: steps: map mkExtraStep steps) splitExtraSteps;
@@ -287,7 +288,7 @@ rec {
   # Validate and normalise extra step configuration before actually
   # generating build steps, in order to use user-provided metadata
   # during the pipeline generation.
-  normaliseExtraStep = overridableParent: key:
+  normaliseExtraStep = knownPhases: overridableParent: key:
     { command
     , label ? key
     , needsOutput ? false
@@ -305,6 +306,15 @@ rec {
     let
       parent = overridableParent parentOverride;
       parentLabel = parent.env.READTREE_TARGET;
+
+      validPhase = lib.throwIfNot (elem phase knownPhases) ''
+        In step '${label}' (from ${parentLabel}):
+
+        Phase '${phase}' is not valid.
+
+        Known phases: ${concatStringsSep ", " knownPhases}
+      ''
+        phase;
     in
     {
       inherit
@@ -322,8 +332,6 @@ rec {
       # boolean API.
       #
       # To help users transition, emit warnings if the old API is used.
-      #
-      # TODO(tazjin): Validate available phases.
       phase = lib.warnIfNot (isNull postBuild) ''
         In step '${label}' (from ${parentLabel}):
 
@@ -339,7 +347,7 @@ rec {
         step definitions. Please remove the `postBuild` parameter from
         this step and instead set `phase = ${phase};`.
       ''
-        phase;
+        validPhase;
 
       prompt = lib.throwIf (prompt != false && phase == "build") ''
         In step '${label}' (from ${parentLabel}):