ci: separate dependency builds, checks and cache uploads
Build the workspace dependencies in their own step, skipped when they are already in Cachix, so their compile output no longer shares a log with the build, test and lint results. Steps do not share /nix/store, so later steps import the paths exported by that step, on pull requests as well. Push to Cachix in a separate step that alone holds the token and also runs when a build fails. Pass --quiet to nix in all steps, which removes the fetch lists and copying lines while keeping builder logs and errors.
This commit is contained in:
4 files changed
+113
-43
No files matched your search
@@ -60,7 +60,12 @@
|
||||
{ pkgs, builds, ... }:
|
||||
{
|
||||
default = builds.bootvine;
|
||||
inherit (builds) bootvine scripted-demos repo-tasks;
|
||||
inherit (builds)
|
||||
bootvine
|
||||
scripted-demos
|
||||
repo-tasks
|
||||
workspace-dependencies
|
||||
;
|
||||
sample-unit-files = pkgs.callPackage ./vm-tests/slow-services/sample-unit-files.nix {
|
||||
inherit (vmTests) sampleUnits;
|
||||
};
|
||||
@@ -101,6 +106,39 @@
|
||||
}
|
||||
) vmTests.machineDescriptions;
|
||||
|
||||
exportBuiltPathsHook = pkgs.writeShellApplication {
|
||||
name = "export-built-paths-hook";
|
||||
text = ''
|
||||
exported_paths_dir="$CI_WORKSPACE/.nix-built-paths"
|
||||
mkdir -p "$exported_paths_dir"
|
||||
read -ra built_paths <<< "$OUT_PATHS"
|
||||
nix copy --quiet --to "file://$exported_paths_dir?compression=zstd" "''${built_paths[@]}"
|
||||
printf '%s\n' "''${built_paths[@]}" >> "$exported_paths_dir/paths.txt"
|
||||
'';
|
||||
};
|
||||
|
||||
buildAndExportPaths = pkgs.writeShellApplication {
|
||||
name = "build-and-export-paths";
|
||||
text = ''
|
||||
export NIX_CONFIG="''${NIX_CONFIG:-}
|
||||
post-build-hook = ${lib.getExe exportBuiltPathsHook}"
|
||||
nix build --quiet --print-build-logs "$@"
|
||||
'';
|
||||
};
|
||||
|
||||
importExportedPaths = pkgs.writeShellApplication {
|
||||
name = "import-exported-paths";
|
||||
text = ''
|
||||
exported_paths_dir="$CI_WORKSPACE/.nix-built-paths"
|
||||
if [[ ! -s "$exported_paths_dir/paths.txt" ]]; then
|
||||
echo "No exported paths to import"
|
||||
exit 0
|
||||
fi
|
||||
mapfile -t built_paths < "$exported_paths_dir/paths.txt"
|
||||
nix copy --quiet --no-check-sigs --from "file://$exported_paths_dir" "''${built_paths[@]}"
|
||||
'';
|
||||
};
|
||||
|
||||
releasePlzOnCodeberg =
|
||||
subcommand: description:
|
||||
shellScriptApp "release-plz-${subcommand}" description {
|
||||
@@ -150,12 +188,47 @@
|
||||
text = "exec xtask publish-recordings";
|
||||
};
|
||||
|
||||
build-and-push-to-cachix =
|
||||
shellScriptApp "build-and-push-to-cachix"
|
||||
"Build flake outputs and push everything built to the wvhulle Cachix cache"
|
||||
build-and-export-paths = {
|
||||
type = "app";
|
||||
meta.description = "Build flake outputs and export newly built paths to the CI workspace";
|
||||
program = lib.getExe buildAndExportPaths;
|
||||
};
|
||||
|
||||
build-unless-cached =
|
||||
shellScriptApp "build-unless-cached"
|
||||
"Build a flake output and export it to the CI workspace unless it is already in Cachix"
|
||||
{
|
||||
text = ''
|
||||
built_output=$(nix eval --quiet --raw "$1.outPath")
|
||||
if nix path-info --quiet --store https://wvhulle.cachix.org "$built_output" > /dev/null 2>&1; then
|
||||
echo "$built_output is already in Cachix"
|
||||
exit 0
|
||||
fi
|
||||
${lib.getExe buildAndExportPaths} "$1"
|
||||
'';
|
||||
};
|
||||
|
||||
import-exported-paths = {
|
||||
type = "app";
|
||||
meta.description = "Import paths exported to the CI workspace by an earlier step";
|
||||
program = lib.getExe importExportedPaths;
|
||||
};
|
||||
|
||||
upload-exported-paths =
|
||||
shellScriptApp "upload-exported-paths"
|
||||
"Push paths exported to the CI workspace to the wvhulle Cachix cache"
|
||||
{
|
||||
runtimeInputs = [ pkgs.cachix ];
|
||||
text = ''exec cachix watch-exec wvhulle -- nix build --print-build-logs "$@"'';
|
||||
text = ''
|
||||
exported_paths_dir="$CI_WORKSPACE/.nix-built-paths"
|
||||
if [[ ! -s "$exported_paths_dir/paths.txt" ]]; then
|
||||
echo "No newly built paths to upload"
|
||||
exit 0
|
||||
fi
|
||||
${lib.getExe importExportedPaths}
|
||||
mapfile -t built_paths < "$exported_paths_dir/paths.txt"
|
||||
cachix push wvhulle "''${built_paths[@]}"
|
||||
'';
|
||||
};
|
||||
|
||||
check-conventional-commits =
|
||||
|
||||
Reference in new issue
Block a user