feat(nix/buildkite): Validate available phases in extra steps

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
This commit is contained in:
Vincent Ambo 2022-06-02 17:42:56 +00:00 committed by tazjin
parent 876b71f641
commit cf00365f84

View file

@ -13,6 +13,7 @@ let
attrValues attrValues
concatLists concatLists
concatStringsSep concatStringsSep
elem
foldl' foldl'
hasAttr hasAttr
hashString hashString
@ -165,7 +166,7 @@ rec {
# Split extra steps by phase. # Split extra steps by phase.
splitExtraSteps = lib.groupBy ({ phase, ... }: phase) splitExtraSteps = lib.groupBy ({ phase, ... }: phase)
(attrValues (mapAttrs (normaliseExtraStep overridable) (attrValues (mapAttrs (normaliseExtraStep phases overridable)
(target.meta.ci.extraSteps or { }))); (target.meta.ci.extraSteps or { })));
extraSteps = mapAttrs (_: steps: map mkExtraStep steps) splitExtraSteps; extraSteps = mapAttrs (_: steps: map mkExtraStep steps) splitExtraSteps;
@ -287,7 +288,7 @@ rec {
# Validate and normalise extra step configuration before actually # Validate and normalise extra step configuration before actually
# generating build steps, in order to use user-provided metadata # generating build steps, in order to use user-provided metadata
# during the pipeline generation. # during the pipeline generation.
normaliseExtraStep = overridableParent: key: normaliseExtraStep = knownPhases: overridableParent: key:
{ command { command
, label ? key , label ? key
, needsOutput ? false , needsOutput ? false
@ -305,6 +306,15 @@ rec {
let let
parent = overridableParent parentOverride; parent = overridableParent parentOverride;
parentLabel = parent.env.READTREE_TARGET; 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 in
{ {
inherit inherit
@ -322,8 +332,6 @@ rec {
# boolean API. # boolean API.
# #
# To help users transition, emit warnings if the old API is used. # To help users transition, emit warnings if the old API is used.
#
# TODO(tazjin): Validate available phases.
phase = lib.warnIfNot (isNull postBuild) '' phase = lib.warnIfNot (isNull postBuild) ''
In step '${label}' (from ${parentLabel}): In step '${label}' (from ${parentLabel}):
@ -339,7 +347,7 @@ rec {
step definitions. Please remove the `postBuild` parameter from step definitions. Please remove the `postBuild` parameter from
this step and instead set `phase = ${phase};`. this step and instead set `phase = ${phase};`.
'' ''
phase; validPhase;
prompt = lib.throwIf (prompt != false && phase == "build") '' prompt = lib.throwIf (prompt != false && phase == "build") ''
In step '${label}' (from ${parentLabel}): In step '${label}' (from ${parentLabel}):