2020-06-27 18:14:58 +02:00
|
|
|
# This file configures the primary build pipeline used for the
|
|
|
|
# top-level list of depot targets.
|
|
|
|
#
|
|
|
|
# It outputs a "YAML" (actually JSON) file which is evaluated and
|
|
|
|
# submitted to Buildkite at the start of each build. This means we can
|
|
|
|
# dynamically configure the pipeline execution here.
|
2020-08-27 02:05:45 +02:00
|
|
|
{ depot, lib, pkgs, ... }:
|
2020-06-27 18:14:58 +02:00
|
|
|
|
|
|
|
let
|
2020-08-27 02:05:45 +02:00
|
|
|
inherit (builtins) concatStringsSep foldl' map toJSON;
|
|
|
|
inherit (lib) singleton;
|
2020-06-27 18:14:58 +02:00
|
|
|
inherit (pkgs) writeText;
|
|
|
|
|
2020-08-27 02:05:45 +02:00
|
|
|
# Create an expression that builds the target at the specified
|
|
|
|
# location.
|
2020-08-31 02:36:03 +02:00
|
|
|
mkBuildExpr = target:
|
|
|
|
let
|
|
|
|
descend = expr: attr: "builtins.getAttr \"${attr}\" (${expr})";
|
|
|
|
targetExpr = foldl' descend "import ./. {}" target.__readTree;
|
|
|
|
subtargetExpr = descend targetExpr target.__subtarget;
|
|
|
|
in if target ? __subtarget then subtargetExpr else targetExpr;
|
2020-08-27 02:05:45 +02:00
|
|
|
|
|
|
|
# Create a pipeline label from the targets tree location.
|
2020-08-31 02:36:03 +02:00
|
|
|
mkLabel = target:
|
|
|
|
let label = concatStringsSep "/" target.__readTree;
|
|
|
|
in if target ? __subtarget
|
|
|
|
then "${label}:${target.__subtarget}"
|
|
|
|
else label;
|
2020-08-27 02:05:45 +02:00
|
|
|
|
|
|
|
# Create a pipeline step from a single target.
|
|
|
|
#
|
|
|
|
# If the build fails, Buildkite metadata is updated to mark the
|
|
|
|
# pipeline as failed. Buildkite has a concept of a failed pipeline
|
|
|
|
# regardless, but this data is not accessible.
|
|
|
|
mkStep = target: {
|
|
|
|
command = ''
|
2020-08-31 02:36:03 +02:00
|
|
|
nix-build -E '${mkBuildExpr target}' || (buildkite-agent meta-data set "failure" "1"; exit 1)
|
2020-08-27 02:05:45 +02:00
|
|
|
'';
|
2020-08-31 02:36:03 +02:00
|
|
|
label = ":nix: ${mkLabel target}";
|
2020-08-27 02:05:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
# Protobuf check step which validates that changes to .proto files
|
|
|
|
# between revisions don't cause backwards-incompatible or otherwise
|
|
|
|
# flawed changes.
|
|
|
|
protoCheck = {
|
|
|
|
command = "${depot.nix.bufCheck}/bin/ci-buf-check";
|
|
|
|
label = ":water_buffalo:";
|
|
|
|
};
|
|
|
|
|
2020-06-27 18:14:58 +02:00
|
|
|
# This defines the build pipeline, using the pipeline format
|
|
|
|
# documented on https://buildkite.com/docs/pipelines/defining-steps
|
2020-08-27 02:05:45 +02:00
|
|
|
#
|
|
|
|
# Pipeline steps need to stay in order.
|
|
|
|
pipeline.steps =
|
|
|
|
# Zero the failure status
|
|
|
|
[
|
|
|
|
{
|
|
|
|
command = "buildkite-agent meta-data set 'failure' '0'";
|
|
|
|
label = ":buildkite:";
|
|
|
|
}
|
|
|
|
{ wait = null; }
|
|
|
|
]
|
|
|
|
|
|
|
|
# Create build steps for each CI target
|
|
|
|
++ (map mkStep depot.ci.targets)
|
|
|
|
|
|
|
|
++ [
|
|
|
|
# Simultaneously run protobuf checks
|
|
|
|
protoCheck
|
|
|
|
|
|
|
|
# Wait for all previous checks to complete
|
|
|
|
({
|
|
|
|
wait = null;
|
|
|
|
continue_on_failure = true;
|
|
|
|
})
|
|
|
|
|
|
|
|
# Wait for all steps to complete, then exit with success or
|
|
|
|
# failure depending on whether any failure status was written.
|
|
|
|
# This step must be :duck:! (yes, really!)
|
|
|
|
({
|
|
|
|
command = "exit $(buildkite-agent meta-data get 'failure')";
|
|
|
|
label = ":duck:";
|
|
|
|
})
|
|
|
|
];
|
|
|
|
in (writeText "depot.yaml" (toJSON pipeline))
|