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
|
||||
|
||||
# Not included by default
|
||||
test-ash:
|
||||
@cd test && ash ./lib_test.sh
|
||||
@cd test && ash ./run_test.sh
|
||||
@echo "Path is $$PATH"
|
||||
@cd test && busybox ash ./lib_test.sh
|
||||
@cd test && busybox ash ./run_test.sh
|
||||
|
||||
test-dash:
|
||||
@cd test && dash ./lib_test.sh
|
||||
|
|
@ -23,4 +25,4 @@ test-ksh:
|
|||
@cd test && ksh ./lib_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
|
||||
|
|
|
|||
86
apply
86
apply
|
|
@ -3,65 +3,79 @@
|
|||
set -e
|
||||
set -u
|
||||
|
||||
function usage() {
|
||||
usage() {
|
||||
echo "usage: $(basename "$0") [-v] [-p] <host> [<host>...]"
|
||||
exit 1
|
||||
}
|
||||
|
||||
function host_targets() {
|
||||
host_targets() {
|
||||
local host="$*"
|
||||
|
||||
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 parallelize="$2"
|
||||
shift
|
||||
shift
|
||||
|
||||
if [[ -n $parallelize ]]; then
|
||||
# shellcheck disable=SC2086
|
||||
parallel -j10 --progress --colsep ' ' ./push $vflag
|
||||
parallel -j10 --progress --colsep ' ' "$(rootpath)/push" $vflag
|
||||
else
|
||||
# shellcheck disable=SC2086
|
||||
parallel -j1 -u --colsep ' ' ./push $vflag
|
||||
parallel -j1 -u --colsep ' ' "$(rootpath)/push" $vflag
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ -z "${APPLY_ROOT:-}" ]]; then
|
||||
APPLY_ROOT="."
|
||||
fi
|
||||
main() {
|
||||
# The default path to config is the current working directory.
|
||||
if [[ -z "${APPLY_ROOT:-}" ]]; then
|
||||
APPLY_ROOT="."
|
||||
fi
|
||||
|
||||
if [[ $# -lt 1 ]]; then
|
||||
usage
|
||||
fi
|
||||
if [[ $# -lt 1 ]]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [[ "$1" == "-v" ]]; then
|
||||
vflag='-v'
|
||||
shift
|
||||
else
|
||||
vflag=''
|
||||
fi
|
||||
if [[ "$1" == "-v" ]]; then
|
||||
vflag='-v'
|
||||
shift
|
||||
else
|
||||
vflag=''
|
||||
fi
|
||||
|
||||
if [[ "$1" == "-p" ]]; then
|
||||
pflag='-p'
|
||||
shift
|
||||
else
|
||||
pflag=''
|
||||
fi
|
||||
if [[ "$1" == "-p" ]]; then
|
||||
pflag='-p'
|
||||
shift
|
||||
else
|
||||
pflag=''
|
||||
fi
|
||||
|
||||
if [[ $# -lt 1 ]]; then
|
||||
usage
|
||||
fi
|
||||
if [[ $# -lt 1 ]]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
hosts=()
|
||||
while [[ $# -gt 0 ]]; do
|
||||
hosts+=("$1")
|
||||
shift
|
||||
done
|
||||
hosts=()
|
||||
while [[ $# -gt 0 ]]; do
|
||||
hosts+=("$1")
|
||||
shift
|
||||
done
|
||||
|
||||
for host in ${hosts[*]}; do
|
||||
target=${host#*/}
|
||||
# shellcheck disable=SC2046
|
||||
echo $(host_targets "$host") root@"$target"
|
||||
done | push_each "$vflag" "$pflag"
|
||||
for host in ${hosts[*]}; do
|
||||
target=${host#*/}
|
||||
# shellcheck disable=SC2046
|
||||
echo $(host_targets "$host") root@"$target"
|
||||
done | push_each "$vflag" "$pflag"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
|
|
|||
105
flake.nix
105
flake.nix
|
|
@ -6,8 +6,77 @@
|
|||
|
||||
outputs = { self, nixpkgs, flake-utils }:
|
||||
flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
|
||||
let pkgs = nixpkgs.legacyPackages.${system}; in
|
||||
rec {
|
||||
let
|
||||
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 {
|
||||
buildInputs = with pkgs; [
|
||||
# Shells
|
||||
|
|
@ -21,36 +90,8 @@
|
|||
];
|
||||
};
|
||||
|
||||
checks = let
|
||||
commonDeps = with pkgs; [ gnumake shellcheck ];
|
||||
|
||||
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"
|
||||
'';
|
||||
checks = {
|
||||
apply = self.defaultPackage.${system}.overrideAttrs (super: { doCheck = true; });
|
||||
};
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -96,6 +96,12 @@ testEpochseconds() {
|
|||
}
|
||||
|
||||
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")"
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue