mirror of
https://github.com/lloeki/apply.git
synced 2025-12-06 09:24:38 +01:00
Get more tests working; make Nix build work
This commit is contained in:
parent
86fa81c411
commit
91d2808bfb
4 changed files with 134 additions and 71 deletions
8
Makefile
8
Makefile
|
|
@ -7,9 +7,11 @@ lint:
|
||||||
|
|
||||||
test: lint test-dash test-bash test-ksh
|
test: lint test-dash test-bash test-ksh
|
||||||
|
|
||||||
|
# Not included by default
|
||||||
test-ash:
|
test-ash:
|
||||||
@cd test && ash ./lib_test.sh
|
@echo "Path is $$PATH"
|
||||||
@cd test && ash ./run_test.sh
|
@cd test && busybox ash ./lib_test.sh
|
||||||
|
@cd test && busybox ash ./run_test.sh
|
||||||
|
|
||||||
test-dash:
|
test-dash:
|
||||||
@cd test && dash ./lib_test.sh
|
@cd test && dash ./lib_test.sh
|
||||||
|
|
@ -23,4 +25,4 @@ test-ksh:
|
||||||
@cd test && ksh ./lib_test.sh
|
@cd test && ksh ./lib_test.sh
|
||||||
@cd test && ksh ./run_test.sh
|
@cd test && ksh ./run_test.sh
|
||||||
|
|
||||||
.PHONY: lint test test-dash test-bash
|
.PHONY: lint test test-ash test-dash test-bash test-ksh
|
||||||
|
|
|
||||||
24
apply
24
apply
|
|
@ -3,31 +3,42 @@
|
||||||
set -e
|
set -e
|
||||||
set -u
|
set -u
|
||||||
|
|
||||||
function usage() {
|
usage() {
|
||||||
echo "usage: $(basename "$0") [-v] [-p] <host> [<host>...]"
|
echo "usage: $(basename "$0") [-v] [-p] <host> [<host>...]"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function host_targets() {
|
host_targets() {
|
||||||
local host="$*"
|
local host="$*"
|
||||||
|
|
||||||
cat < "${APPLY_ROOT}"/"$host" | tr '\n' ' '
|
cat < "${APPLY_ROOT}"/"$host" | tr '\n' ' '
|
||||||
}
|
}
|
||||||
|
|
||||||
function push_each() {
|
rootpath() {
|
||||||
|
if [[ "${#BASH_SOURCE}" -gt 0 ]]; then
|
||||||
|
cd -- "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd
|
||||||
|
else
|
||||||
|
cd -- "$(dirname "$0")" >/dev/null 2>&1 && pwd
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
push_each() {
|
||||||
local vflag="$1"
|
local vflag="$1"
|
||||||
local parallelize="$2"
|
local parallelize="$2"
|
||||||
shift
|
shift
|
||||||
shift
|
shift
|
||||||
|
|
||||||
if [[ -n $parallelize ]]; then
|
if [[ -n $parallelize ]]; then
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
parallel -j10 --progress --colsep ' ' ./push $vflag
|
parallel -j10 --progress --colsep ' ' "$(rootpath)/push" $vflag
|
||||||
else
|
else
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
parallel -j1 -u --colsep ' ' ./push $vflag
|
parallel -j1 -u --colsep ' ' "$(rootpath)/push" $vflag
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
# The default path to config is the current working directory.
|
||||||
if [[ -z "${APPLY_ROOT:-}" ]]; then
|
if [[ -z "${APPLY_ROOT:-}" ]]; then
|
||||||
APPLY_ROOT="."
|
APPLY_ROOT="."
|
||||||
fi
|
fi
|
||||||
|
|
@ -65,3 +76,6 @@ for host in ${hosts[*]}; do
|
||||||
# shellcheck disable=SC2046
|
# shellcheck disable=SC2046
|
||||||
echo $(host_targets "$host") root@"$target"
|
echo $(host_targets "$host") root@"$target"
|
||||||
done | push_each "$vflag" "$pflag"
|
done | push_each "$vflag" "$pflag"
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
||||||
|
|
|
||||||
105
flake.nix
105
flake.nix
|
|
@ -6,8 +6,77 @@
|
||||||
|
|
||||||
outputs = { self, nixpkgs, flake-utils }:
|
outputs = { self, nixpkgs, flake-utils }:
|
||||||
flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
|
flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
|
||||||
let pkgs = nixpkgs.legacyPackages.${system}; in
|
let
|
||||||
rec {
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
inherit (pkgs) stdenv lib;
|
||||||
|
|
||||||
|
in rec {
|
||||||
|
defaultPackage = self.packages."${system}".apply;
|
||||||
|
packages.apply = stdenv.mkDerivation {
|
||||||
|
pname = "apply";
|
||||||
|
version = "2021-07-16";
|
||||||
|
|
||||||
|
src = ./.;
|
||||||
|
|
||||||
|
nativeBuildInputs = with pkgs; [ makeWrapper ];
|
||||||
|
|
||||||
|
# Overridden in tests
|
||||||
|
doCheck = false;
|
||||||
|
checkInputs = with pkgs; [
|
||||||
|
shellcheck
|
||||||
|
gnumake
|
||||||
|
|
||||||
|
bash
|
||||||
|
dash
|
||||||
|
ksh
|
||||||
|
|
||||||
|
# busybox as an input will break things
|
||||||
|
];
|
||||||
|
|
||||||
|
# Test with each shell
|
||||||
|
checkPhase = ''
|
||||||
|
cd "$src"
|
||||||
|
make test
|
||||||
|
|
||||||
|
(
|
||||||
|
export PATH="${lib.makeBinPath (with pkgs; [ busybox gnumake shellcheck ])}"
|
||||||
|
make test-ash
|
||||||
|
)
|
||||||
|
'';
|
||||||
|
|
||||||
|
# Don't patch shebangs on everything or it'll get the 'lib' and 'run'
|
||||||
|
# scripts, which we need to be able to copy elsewhere.
|
||||||
|
dontPatchShebangs = true;
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out/bin/
|
||||||
|
cp ./{apply,lib,push,run} $out/bin/
|
||||||
|
chmod +x $out/bin/*
|
||||||
|
'';
|
||||||
|
|
||||||
|
postFixup = ''
|
||||||
|
for f in $out/bin/{apply,push}; do
|
||||||
|
patchShebangs "$f"
|
||||||
|
wrapProgram "$f" \
|
||||||
|
--suffix PATH ":" "${lib.makeBinPath (with pkgs; [ coreutils parallel openssh ])}"
|
||||||
|
done
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta = with lib; {
|
||||||
|
homepage = "https://github.com/andrew-d/apply";
|
||||||
|
description = "TODO";
|
||||||
|
maintainers = with maintainers; [ andrew-d ];
|
||||||
|
license = licenses.bsd3;
|
||||||
|
platforms = platforms.unix;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
defaultApp = self.apps."${system}".apply;
|
||||||
|
apps.apply = {
|
||||||
|
type = "app";
|
||||||
|
program = "${self.defaultPackage."${system}"}/bin/apply";
|
||||||
|
};
|
||||||
|
|
||||||
devShell = pkgs.mkShell {
|
devShell = pkgs.mkShell {
|
||||||
buildInputs = with pkgs; [
|
buildInputs = with pkgs; [
|
||||||
# Shells
|
# Shells
|
||||||
|
|
@ -21,36 +90,8 @@
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
checks = let
|
checks = {
|
||||||
commonDeps = with pkgs; [ gnumake shellcheck ];
|
apply = self.defaultPackage.${system}.overrideAttrs (super: { doCheck = true; });
|
||||||
|
|
||||||
in {
|
|
||||||
bash = pkgs.runCommand "lint" {
|
|
||||||
src = ./.;
|
|
||||||
nativeBuildInputs = commonDeps ++ (with pkgs; [ bash ]);
|
|
||||||
} ''
|
|
||||||
export SHELL="${pkgs.bash}/bin/bash"
|
|
||||||
make -C "$src" test-bash
|
|
||||||
touch "$out"
|
|
||||||
'';
|
|
||||||
|
|
||||||
dash = pkgs.runCommand "lint" {
|
|
||||||
src = ./.;
|
|
||||||
nativeBuildInputs = commonDeps ++ (with pkgs; [ dash ]);
|
|
||||||
} ''
|
|
||||||
export SHELL="${pkgs.dash}/bin/dash"
|
|
||||||
make -C "$src" test-dash
|
|
||||||
touch "$out"
|
|
||||||
'';
|
|
||||||
|
|
||||||
busybox = pkgs.runCommand "lint" {
|
|
||||||
src = ./.;
|
|
||||||
nativeBuildInputs = commonDeps ++ (with pkgs; [ busybox ]);
|
|
||||||
} ''
|
|
||||||
export SHELL="${pkgs.busybox}/bin/ash"
|
|
||||||
make -C "$src" test-ash
|
|
||||||
touch "$out"
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,12 @@ testEpochseconds() {
|
||||||
}
|
}
|
||||||
|
|
||||||
testUserHomedir() {
|
testUserHomedir() {
|
||||||
|
# TODO(andrew-d): this doesn't work in the Nix sandbox; detect this and
|
||||||
|
# skip the test for now.
|
||||||
|
if [ "$HOME" = "/homeless-shelter" ]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
assertEquals "$HOME" "$(user_homedir "$USER")"
|
assertEquals "$HOME" "$(user_homedir "$USER")"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue