113 lines
3.0 KiB
Nix
113 lines
3.0 KiB
Nix
|
|
{
|
||
|
|
# Exposes `apps.<system>` entries that point at small runnable programs.
|
||
|
|
description = "A minimal flake apps example";
|
||
|
|
|
||
|
|
inputs = {
|
||
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||
|
|
};
|
||
|
|
|
||
|
|
outputs =
|
||
|
|
{ self, nixpkgs, ... }:
|
||
|
|
let
|
||
|
|
system = "x86_64-linux";
|
||
|
|
pkgs = import nixpkgs { inherit system; };
|
||
|
|
|
||
|
|
releaseName = "search-index-2026-04";
|
||
|
|
releasePlan = [
|
||
|
|
{
|
||
|
|
stage = "staging";
|
||
|
|
percentage = 10;
|
||
|
|
owner = "team-search";
|
||
|
|
gates = [
|
||
|
|
"smoke-tests"
|
||
|
|
"error-budget"
|
||
|
|
];
|
||
|
|
}
|
||
|
|
{
|
||
|
|
stage = "canary";
|
||
|
|
percentage = 35;
|
||
|
|
owner = "team-search";
|
||
|
|
gates = [
|
||
|
|
"dashboard-review"
|
||
|
|
"support-readiness"
|
||
|
|
];
|
||
|
|
}
|
||
|
|
{
|
||
|
|
stage = "production";
|
||
|
|
percentage = 100;
|
||
|
|
owner = "team-search";
|
||
|
|
gates = [
|
||
|
|
"canary-slo"
|
||
|
|
"stakeholder-signoff"
|
||
|
|
];
|
||
|
|
}
|
||
|
|
];
|
||
|
|
|
||
|
|
renderWave =
|
||
|
|
wave:
|
||
|
|
"${wave.stage}: ${toString wave.percentage}% owned by ${wave.owner}; gates: ${builtins.concatStringsSep ", " wave.gates}";
|
||
|
|
|
||
|
|
reportText = builtins.concatStringsSep "\n" (
|
||
|
|
[
|
||
|
|
"release: ${releaseName}"
|
||
|
|
"waves:"
|
||
|
|
]
|
||
|
|
++ map renderWave releasePlan
|
||
|
|
);
|
||
|
|
|
||
|
|
nextWave = builtins.elemAt releasePlan 1;
|
||
|
|
|
||
|
|
reportPackage = pkgs.writeShellApplication {
|
||
|
|
name = "show-rollout-report";
|
||
|
|
text = ''
|
||
|
|
cat <<'EOF'
|
||
|
|
${reportText}
|
||
|
|
EOF
|
||
|
|
'';
|
||
|
|
};
|
||
|
|
|
||
|
|
promotePackage = pkgs.writeShellApplication {
|
||
|
|
name = "suggest-next-promotion";
|
||
|
|
text = ''
|
||
|
|
echo "next wave: ${nextWave.stage} (${toString nextWave.percentage}%) after ${builtins.concatStringsSep " and " nextWave.gates}"
|
||
|
|
'';
|
||
|
|
};
|
||
|
|
in
|
||
|
|
{
|
||
|
|
packages.${system} = {
|
||
|
|
default = reportPackage;
|
||
|
|
report = reportPackage;
|
||
|
|
promote = promotePackage;
|
||
|
|
};
|
||
|
|
|
||
|
|
apps.${system} = {
|
||
|
|
default = {
|
||
|
|
type = "app";
|
||
|
|
program = "${reportPackage}/bin/show-rollout-report";
|
||
|
|
meta.description = "Print the rollout report for a release train.";
|
||
|
|
};
|
||
|
|
|
||
|
|
promote = {
|
||
|
|
type = "app";
|
||
|
|
program = "${promotePackage}/bin/suggest-next-promotion";
|
||
|
|
meta.description = "Print the next rollout wave that should be promoted.";
|
||
|
|
};
|
||
|
|
};
|
||
|
|
|
||
|
|
checks.${system}.apps-run = pkgs.runCommand "flake-apps-run" { } ''
|
||
|
|
report="$(${self.apps.${system}.default.program})"
|
||
|
|
promote="$(${self.apps.${system}.promote.program})"
|
||
|
|
|
||
|
|
printf '%s\n' "$report" | grep -q '^release: ${releaseName}$'
|
||
|
|
printf '%s\n' "$report" | grep -q '^production: 100% owned by team-search; gates: canary-slo, stakeholder-signoff$'
|
||
|
|
|
||
|
|
if [ "$promote" != "next wave: canary (35%) after dashboard-review and support-readiness" ]; then
|
||
|
|
echo "unexpected promotion output: $promote" >&2
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo ok > "$out"
|
||
|
|
'';
|
||
|
|
};
|
||
|
|
}
|