From bb140e16a2d44bbfe96911f29f1b6c5ef4947b85 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 2 Feb 2022 12:22:58 +0300 Subject: feat(nix/buildkite): Add parentOverride argument to extra steps This can be used to override the parent derivation if its output is required, for example to inject versions which are only used during releases to avoid cache-busting. Change-Id: I2211496efa8f9bc98ea43b23e4f3f92c61a6da73 Reviewed-on: https://cl.tvl.fyi/c/depot/+/5184 Tested-by: BuildkiteCI Autosubmit: tazjin Reviewed-by: ezemtsov --- nix/buildkite/default.nix | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'nix') diff --git a/nix/buildkite/default.nix b/nix/buildkite/default.nix index d17b5c86c4..b1653e1ad5 100644 --- a/nix/buildkite/default.nix +++ b/nix/buildkite/default.nix @@ -159,6 +159,13 @@ rec { let step = mkStep headBranch parentTargetMap target; + # Same step, but with an override function applied. This is + # used in mkExtraStep if the extra step needs to modify the + # parent derivation somehow. + # + # Note that this will never affect the label. + overridable = f: mkStep headBranch parentTargetMap (f target); + # Split build/post-build steps splitExtraSteps = partition ({ postStep, ... }: postStep) (attrValues (mapAttrs @@ -168,7 +175,7 @@ rec { }) (target.meta.ci.extraSteps or { }))); - mkExtraStep' = { name, value, ... }: mkExtraStep step name value; + mkExtraStep' = { name, value, ... }: mkExtraStep overridable name value; extraBuildSteps = map mkExtraStep' splitExtraSteps.wrong; # 'wrong' -> no prompt extraPostSteps = map mkExtraStep' splitExtraSteps.right; # 'right' -> has prompt in @@ -260,6 +267,10 @@ rec { # command. Output will be available as 'result'. # TODO: Figure out multiple-output derivations. # + # parentOverride (optional): A function (drv -> drv) to override + # the parent's target definition when preparing its output. Only + # used in extra steps that use needsOutput. + # # branches (optional): Git references (branches, tags ... ) on # which this step should be allowed to run. List of strings. # @@ -291,15 +302,18 @@ rec { # Create the Buildkite configuration for an extra step, optionally # wrapping it in a gate group. - mkExtraStep = parent: key: { command - , label ? key - , prompt ? false - , needsOutput ? false - , branches ? null - , alwaysRun ? false - , postBuild ? false - }@cfg: + mkExtraStep = overridableParent: key: + { command + , label ? key + , prompt ? false + , needsOutput ? false + , parentOverride ? (x: x) + , branches ? null + , alwaysRun ? false + , postBuild ? false + }@cfg: let + parent = overridableParent parentOverride; parentLabel = parent.env.READTREE_TARGET; step = { -- cgit 1.4.1