Merge fort-nix/nix-bitcoin#795: CI: Switch from Cirrus to Github Actions

5516bcc43b ci: switch from Cirrus to Github Actions (Erik Arvstedt)
7d33e9d5e9 tests: extract fn `instantiateTestsFromStr` (Erik Arvstedt)

Pull request description:

ACKs for top commit:
  jonasnick:
    ACK 5516bcc43b

Tree-SHA512: 1aa23ffc52c8e9b7efd38fbf31be9bab7a7e187571c6bee8c1dbdb8eb14f90995b260d10f0d3d9968d6e9be1be452d22173d9775fd6d42a94a01f41ab3305d21
This commit is contained in:
Jonas Nick 2025-07-03 08:16:36 +00:00
commit e2ca2e4967
No known key found for this signature in database
GPG key ID: 4861DBF262123605
11 changed files with 140 additions and 61 deletions

View file

@ -28,7 +28,9 @@ fi
## Build
if [[ -v CIRRUS_CI ]]; then
if [[ -v GITHUB_ACTIONS ]]; then
# Avoid cachix warning message
mkdir -p ~/.config/nix && touch ~/.config/nix/nix.conf
cachix use "$cachixCache"
fi

View file

@ -3,19 +3,17 @@
# This script can also be run locally for testing:
# ./build.sh <scenario>
#
# When variable CIRRUS_CI is unset, this script leaves no persistent traces on the host system.
# When variable GITHUB_ACTIONS is unset, this script leaves no persistent traces on the host system.
set -euo pipefail
scenario=$1
if [[ -v CIRRUS_CI ]]; then
if [[ -v GITHUB_ACTIONS ]]; then
if [[ ! -e /dev/kvm ]]; then
>&2 echo "No KVM available on VM host."
exit 1
fi
# Enable KVM access for nixbld users
chmod o+rw /dev/kvm
fi
cd "${BASH_SOURCE[0]%/*}"

52
test/ci/build_test_drivers.sh Executable file
View file

@ -0,0 +1,52 @@
#!/usr/bin/env bash
set -euo pipefail
cd "${BASH_SOURCE[0]%/*}"
cachixCache=nix-bitcoin
# Declare variables for shellcheck
driverDrvs=()
drivers=()
scenarioTests=()
# Call ./test-info.nix
testInfo=$(time nix eval --raw --show-trace ../..#ciTestInfo)
# This sets variables `driverDrvs`, `drivers`, `scenarioTests`
eval "$testInfo"
if nix path-info --store "https://${cachixCache}.cachix.org" "${scenarioTests[@]}" &>/dev/null; then
echo
echo "All tests have already been built successfully:"
printf '%s\n' "${scenarioTests[@]}"
exit 0
fi
echo "run_scenario_tests=true" >> "$GITHUB_OUTPUT"
## Build test drivers
if nix path-info --store "https://${cachixCache}.cachix.org" "${drivers[@]}" &>/dev/null; then
echo
echo "All test drivers have already been built successfully:"
exit 0
fi
if [[ -v GITHUB_ACTIONS ]]; then
# Avoid cachix warning message
mkdir -p ~/.config/nix && touch ~/.config/nix/nix.conf
cachix use "$cachixCache"
fi
if [[ $CACHIX_SIGNING_KEY ]]; then
# Speed up task by uploading store paths as soon as they are created
buildCmd="cachix watch-exec $cachixCache nix -- build"
else
buildCmd="nix build"
fi
$buildCmd --no-link --print-build-logs "${driverDrvs[@]}"
if [[ $CACHIX_SIGNING_KEY ]]; then
cachix push "$cachixCache" "${drivers[@]}"
fi

22
test/ci/test-info.nix Normal file
View file

@ -0,0 +1,22 @@
pkgs: instantiateTests:
let
# `instantiateTests` prints the test name before evaluating, which is useful for debugging
ciTests = instantiateTests [
"default"
"netns"
"netnsRegtest"
];
drivers = map (x: x.driver) ciTests;
driverDrvs = map (x: ''"${x.drvPath}^*"'') drivers;
in ''
driverDrvs=(
${builtins.concatStringsSep "\n" driverDrvs}
)
drivers=(
${builtins.concatStringsSep "\n" drivers}
)
scenarioTests=(
${builtins.concatStringsSep "\n" ciTests}
)
''

View file

@ -193,7 +193,7 @@ buildTests() {
# TODO-EXTERNAL:
# Simplify and switch to pure build when `nix build` can instantiate flake function outputs
# shellcheck disable=SC2207
drvs=($(nixInstantiate "pkgs.instantiateTests \"${tests[*]}\""))
drvs=($(nixInstantiate "pkgs.instantiateTestsFromStr \"${tests[*]}\""))
for i in "${!tests[@]}"; do
testName=${tests[$i]}
drv=${drvs[$i]}

View file

@ -459,16 +459,15 @@ in {
};
});
instantiateTestsFromStr = testNamesStr: instantiateTests (lib.splitString " " testNamesStr);
instantiateTests = testNames:
let
testNames' = lib.splitString " " testNames;
in
map (name:
let
test = tests.${name};
in
builtins.seq (builtins.trace "Evaluating test '${name}'" test.outPath)
test
) testNames';
map (name:
let
test = tests.${name};
in
builtins.seq (builtins.trace "Evaluating test '${name}'" test.outPath)
test
) testNames;
};
}