travis: cache all build outputs with cachix

This further speeds up builds, in particular the modules test in the
next commit. By checking if the expected final build output has already
been cached, we can even skip the download of cached builds.
This commit is contained in:
Erik Arvstedt 2020-01-12 20:52:36 +01:00
parent b0e759160d
commit 766fa4f300
No known key found for this signature in database
GPG Key ID: 33312B944DD97846
2 changed files with 54 additions and 1 deletions

View File

@ -14,6 +14,9 @@ install:
- cachix use nix-bitcoin
- VER="$(nix eval nixpkgs.lib.version)"
env:
global:
# CACHIX_SIGNING_KEY
- secure: "xXCFZ7g+k5YmCGm8R8l3bZElVmt+RD1KscG3kGr5w4HyyDPTzFetPo+sT8bUpysDU0u3HWhfVhHtpog2mhNhwVl3tQwKXea3dHKC1i6ypBg3gjDngmJRR5wo++ocYDpK8qPaU7m/jHQTNFnTA4CbmMcc05GcYx/1Ai/ZGkNwWFjdIcVeOUoiol33gykMOXIGDg2qlXudt33wP53FHbX8L4fxzodWfAuxKK4AoGprxy5eSnU7LCaXxxJmu4HwuV+Ux2U1NfE/E33cvhlUvTQCswVSZFG06mg8rwhMG1ozsDvlL2itZlu/BeUQH5y3XMMlnJIUXUazkRBibf1w/ebVjpOF+anqkqmq8tcbFEa7T+RJeVTIsvP+L8rE8fcmuZtdg9hNmgRnLmaeT0vVwD1L2UqW9HdRyujdoS0jPYuoc1W7f1JQWfAPhBPQ1SrtKyNNqcbVJ34aN7b+4vCzRpQL1JTbmjzQIWhkiKN1qMo1v/wbIydW8yka4hc4JOfdQLaAJEPI1eAC1MLotSAegMnwKWE1dzm66MuPSipksYjZrvsB28cV4aCVUffIuRhrSr1i2afRHwTpNbK9U4/576hah15ftUdR79Sfkcoi1ekSQTFGRvkRIPYtkKLYwFa3jVA41qz7+IIZCf4TsApy3XDdFx91cRub7yPq9BeZ83A+qYQ="
jobs:
- PKG=nodeinfo STABLE=1
- PKG=hwi STABLE=1
@ -30,4 +33,25 @@ env:
- PKG=liquid-swap STABLE=1
script:
- printf '%s (%s)\n' "$NIX_PATH" "$VER"
- nix-build -A $PKG
- time nix-instantiate -A $PKG --add-root ./drv --indirect
- outPath=$(nix-store --query ./drv)
- |
if nix path-info --store https://nix-bitcoin.cachix.org $outPath &>/dev/null; then
echo "$outPath" has already been built successfully.
travis_terminate 0
fi
# Travis doesn't expose secrets to pull-request builds,
# so skip cache uploading in this case
- |
if [[ $CACHIX_SIGNING_KEY ]]; then
cachix push nix-bitcoin --watch-store &
cachixPid=$!
fi
- nix-build ./drv
- |
if [[ $CACHIX_SIGNING_KEY ]]; then
# Wait until cachix has finished uploading
# Run as root because yama/ptrace_scope != 0
ruby=$(nix-build '<nixpkgs>' -A ruby)/bin/ruby
time sudo $ruby helper/wait-for-network-idle.rb $cachixPid
fi

29
helper/wait-for-network-idle.rb Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env ruby
require 'open3'
# Wait until the given PID had no network activity for `Timeout` seconds, then exit.
pid = ARGV.first
Timeout = 2
stdin, out, err, wait_thread = Open3.popen3("strace -f -e trace=network -s 1 -q -p #{pid}")
while IO.select([err], nil, nil, Timeout)
begin
out = err.read_nonblock(1 << 10)
rescue EOFError
status = wait_thread.value
if status.success?
puts "Monitored process #{pid} exited"
exit 0
else
puts "Strace failed with exit code #{status.to_i}. Last output:\n#{out}"
# strace often fails with code 256 which looks like success to shells. fail with 1 instead.
exit 1
end
end
end
# If we exit without an explicit kill,
# ptrace can fail on reattachment: ptrace(PTRACE_SEIZE, $PID): Operation not permitted
# Only relevant for testing.
Process.kill("TERM", wait_thread.pid)