Created
November 4, 2022 21:51
-
-
Save wpcarro/b18c376a55e79926bb703c67c145798a to your computer and use it in GitHub Desktop.
Supporting dependsOn for extraSteps API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/tvl-kit/buildkite/default.nix b/tvl-kit/buildkite/default.nix | |
| index b04dc55a0..2be217937 100644 | |
| --- a/tvl-kit/buildkite/default.nix | |
| +++ b/tvl-kit/buildkite/default.nix | |
| @@ -340,6 +340,7 @@ rec { | |
| , postBuild ? null | |
| , skip ? false | |
| , agents ? null | |
| + , dependsOn ? [ ] | |
| }: | |
| let | |
| parent = overridableParent parentOverride; | |
| @@ -368,6 +369,13 @@ rec { | |
| skip | |
| agents; | |
| + # The Buildkite API supports a string and list of strings. | |
| + dependsOn = | |
| + if builtins.isString dependsOn then | |
| + [ dependsOn ] | |
| + else | |
| + dependsOn; | |
| + | |
| # //nix/buildkite is growing a new feature for adding different | |
| # "build phases" which supersedes the previous `postBuild` | |
| # boolean API. | |
| @@ -419,9 +427,23 @@ rec { | |
| in | |
| if cfg.alwaysRun then false else skip'; | |
| - depends_on = lib.optional | |
| - (buildEnabled && !cfg.alwaysRun && !cfg.needsOutput) | |
| - cfg.parent.key; | |
| + depends_on = | |
| + let | |
| + # Buildkite requires keys to be globally unique, but for extraSteps | |
| + # it's more convenient to define dependencies local to the | |
| + # extraSteps configuration. | |
| + # | |
| + # We can support this by namespacing the dependsOn keys with the key | |
| + # of the parent step to which they're attached to make them globally | |
| + # unique. | |
| + namespacedDependsOn = builtins.map | |
| + (key: "${cfg.parent.key}-${key}") | |
| + cfg.dependsOn; | |
| + in | |
| + if buildEnabled && !cfg.alwaysRun && !cfg.needsOutput then | |
| + [ cfg.parent.key ] ++ namespacedDependsOn | |
| + else | |
| + namespacedDependsOn; | |
| command = pkgs.writeShellScript "${cfg.key}-script" '' | |
| set -ueo pipefail | |
| @@ -433,8 +455,10 @@ rec { | |
| exec ${cfg.command} | |
| ''; | |
| + key = "${cfg.parent.key}-${cfg.key}"; | |
| soft_fail = cfg.softFail; | |
| - } // (lib.optionalAttrs (cfg.agents != null) { inherit (cfg) agents; }) | |
| + } | |
| + // (lib.optionalAttrs (cfg.agents != null) { inherit (cfg) agents; }) | |
| // (lib.optionalAttrs (cfg.branches != null) { | |
| branches = lib.concatStringsSep " " cfg.branches; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment