Skip to content

Commit

Permalink
nix: Add checks for release packages
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Jul 9, 2020
1 parent 3e19b47 commit 830d26d
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 51 deletions.
3 changes: 2 additions & 1 deletion default.nix
Expand Up @@ -141,8 +141,9 @@ let
]) ++ (with pkgs; [
niv
pkgconfig
sqlite-interactive
python3Packages.openapi-spec-validator
ruby
sqlite-interactive
yq
]);
tools = {
Expand Down
43 changes: 30 additions & 13 deletions nix/linux-release.nix
Expand Up @@ -15,18 +15,35 @@ with pkgs.lib;
assert (assertMsg (builtins.length exes > 0) "empty list of exes");

let
name = (head exes).meta.name;
tarname = "${name}-linux64.tar.gz";
exe = head exes;
name = exe.meta.name;

in pkgs.runCommand name {
in pkgs.stdenv.mkDerivation {
inherit name;
buildInputs = with pkgs.buildPackages; [ gnutar gzip binutils ];
} ''
mkdir ${name}
cp -R ${concatMapStringsSep " " (exe: "${exe}/bin/*") exes} ${name}
chmod -R 755 ${name}
strip ${name}/*
mkdir -p $out/nix-support
tar -czf $out/${tarname} ${name}
echo "file binary-dist $out/${tarname}" > $out/nix-support/hydra-build-products
''
checkInputs = [ pkgs.buildPackages.ruby ];
doCheck = true;
phases = [ "buildPhase" "checkPhase" ];
tarname = "${name}-linux64.tar.gz";
buildPhase = ''
mkdir $name
cp -nR ${concatMapStringsSep " " (exe: "${exe}/bin/*") exes} $name
chmod -R 755 $name
strip $name/*
mkdir -p $out/nix-support
tar -czf $out/$tarname $name
echo "file binary-dist $out/$tarname" > $out/nix-support/hydra-build-products
'';

# test that executables work
checkPhase = ''
cd `mktemp -d`
echo " - extracting $tarname"
tar -xzvf $out/$tarname
export PATH=`pwd`/$name:$PATH
echo " - running checks"
ruby ${../scripts/check-bundle.rb} ${getName exe.name}
'';
}
41 changes: 29 additions & 12 deletions nix/macos-release.nix
Expand Up @@ -15,17 +15,34 @@ with pkgs.lib;
assert (assertMsg (builtins.length exes > 0) "empty list of exes");

let
name = (head exes).meta.name;
tarname = "${name}-macos64.tar.gz";
exe = head exes;
name = exe.meta.name;

in pkgs.runCommand name {
in pkgs.stdenv.mkDerivation {
inherit name;
buildInputs = with pkgs.buildPackages; [ gnutar gzip binutils ];
} ''
mkdir ${name}
cp -fR ${concatMapStringsSep " " (exe: "${exe}/bin/*") exes} ${name}
chmod -R 755 ${name}
mkdir -p $out/nix-support
tar -czf $out/${tarname} ${name}
echo "file binary-dist $out/${tarname}" > $out/nix-support/hydra-build-products
''
checkInputs = [ pkgs.buildPackages.ruby ];
doCheck = true;
phases = [ "buildPhase" "checkPhase" ];
tarname = "${name}-linux64.tar.gz";
buildPhase = ''
mkdir $name
cp -nR ${concatMapStringsSep " " (exe: "${exe}/bin/*") exes} $name
chmod -R 755 $name
mkdir -p $out/nix-support
tar -czf $out/$tarname $name
echo "file binary-dist $out/$tarname" > $out/nix-support/hydra-build-products
'';

# test that executables work
checkPhase = ''
cd `mktemp -d`
echo " - extracting $tarname"
tar -xzvf $out/$tarname
export PATH=`pwd`/$name:$PATH
echo " - running checks"
ruby ${../scripts/check-bundle.rb} ${getName exe.name}
'';
}
80 changes: 55 additions & 25 deletions nix/windows-release.nix
Expand Up @@ -10,38 +10,68 @@
, exes ? []
}:

with pkgs.lib;

assert (assertMsg (builtins.length exes > 0) "empty list of exes");

let
# Take the filename from the first exe passed in
exe = pkgs.lib.head exes;
exe = head exes;
name = "${exe.meta.name}-win64";

in pkgs.runCommand name { buildInputs = [ pkgs.buildPackages.zip ]; } ''
mkdir -p $out/nix-support release
cd release
in pkgs.stdenv.mkDerivation {
inherit name;
buildInputs = [ pkgs.buildPackages.zip ];
checkInputs = with pkgs.buildPackages; [ unzip ruby wineMinimal ];
doCheck = true;
phases = [ "buildPhase" "checkPhase" ];
zipname = "${name}.zip";
buildPhase = ''
mkdir -p $out/nix-support release
cd release
cp -fR ${pkgs.lib.concatMapStringsSep " " (exe: "${exe}/bin/*") exes} .
chmod -R +w .
cp -nR ${concatMapStringsSep " " (exe: "${exe}/bin/*") exes} .
chmod -R +w .
zip -r $out/${name}.zip .
echo "file binary-dist $out/${name}.zip" > $out/nix-support/hydra-build-products
zip -r $out/$zipname .
echo "file binary-dist $out/$zipname" > $out/nix-support/hydra-build-products
# make a separate configuration package if needed
if [ -d ${exe}/configuration ]; then
cp -R ${exe}/configuration ..
cd ../configuration
chmod -R +w .
# make a separate configuration package if needed
if [ -d ${exe}/configuration ]; then
cp -R ${exe}/configuration ..
cd ../configuration
chmod -R +w .
zip -r $out/${exe.name}-configuration.zip .
echo "file binary-dist $out/${exe.name}-configuration.zip" >> $out/nix-support/hydra-build-products
fi
zip -r $out/${exe.name}-configuration.zip .
echo "file binary-dist $out/${exe.name}-configuration.zip" >> $out/nix-support/hydra-build-products
fi
# make a separate deployments configuration package if needed
if [ -d ${exe}/deployments ]; then
cp -R ${exe}/deployments ..
cd ../deployments
chmod -R +w .
# make a separate deployments configuration package if needed
if [ -d ${exe}/deployments ]; then
cp -R ${exe}/deployments ..
cd ../deployments
chmod -R +w .
zip -r $out/${exe.name}-deployments.zip .
echo "file binary-dist $out/${exe.name}-deployments.zip" >> $out/nix-support/hydra-build-products
fi
'';

# test that executables work under wine
checkPhase = ''
cd `mktemp -d`
echo " - extracting $zipname"
unzip $out/$zipname
export PATH=`pwd`/$name:$PATH
# setup wine
export WINEPREFIX=$TMP
export HOME=$TMP
export WINEDLLOVERRIDES="winemac.drv=d"
export WINEDEBUG=warn-all,fixme-all,-menubuilder,-mscoree,-ole,-secur32,-winediag
export LC_ALL=en_US.UTF-8
zip -r $out/${exe.name}-deployments.zip .
echo "file binary-dist $out/${exe.name}-deployments.zip" >> $out/nix-support/hydra-build-products
fi
''
echo " - running checks"
ruby ${../scripts/check-bundle.rb} ${getName exe.name} wine64
'';
}
49 changes: 49 additions & 0 deletions scripts/check-bundle.rb
@@ -0,0 +1,49 @@
#!/usr/bin/env ruby

############################################################################
# Checks that every executable required in the release package is
# present and works.
############################################################################

require 'open3'

tests = {
"cardano-wallet-jormungandr" => [ "jormungandr", "jcli" ],
"cardano-wallet-byron" => [ "cardano-node", "cardano-cli", "bech32", "cardano-tx", "cardano-address" ],
"cardano-wallet-shelley" => [ "cardano-node", "cardano-cli", "bech32", "cardano-tx", "cardano-address" ]
}

if ARGV.length < 1 || ARGV.length > 2 || tests[ARGV[0]] == nil
STDERR.puts "Usage: check-bundle cardano-wallet-(jormungandr|byron|shelley) [RUNNER]"
exit 1
end

wallet = ARGV[0]

# Runner is used to run windows exes under wine.
runner = ARGV.fetch(1, "")

$failed = 0

def report(cmd, status)
res = status == 0 ? "pass" : "FAIL"
puts "#{cmd.ljust(40)}[#{res}]"
if status then
$failed = status
end
end

cmd = "#{wallet} version"
ver, status = Open3.capture2("#{runner} #{cmd}")
report(cmd, status)

tests[wallet].each do |cmd|
begin
stdout_str, status = Open3.capture2("#{runner} #{cmd} --help")
report(cmd, 0)
rescue Errno::ENOENT
report(cmd, 1)
end
end

exit($failed)

0 comments on commit 830d26d

Please sign in to comment.