channable / hoff

A gatekeeper for your commits
Apache License 2.0
41 stars 3 forks source link

Make CI red when build fails #119

Closed rudymatela closed 2 years ago

rudymatela commented 2 years ago

Currently (Jun 2022) Hoff, whenever the nix-build step fails, the CI does not detect it and we are left with a green build :heavy_check_mark: even though the build was supposed to be red :x:.

Here is an example:

Here's the failing command and output section:

$ nix-build --no-out-link release.nix | cachix push channable-public
...
[11 of 12] Compiling WebInterface     ( src/WebInterface.hs, dist/build/WebInterface.p_o ) 00:43
[12 of 12] Compiling Server           ( src/Server.hs, dist/build/Server.p_o ) 00:45
dist/build/libHShoff-0.25.2-9YPwmF3FCRkEo14kDrjgdt-ghc8.10.4.a: hPutBuf: resource exhausted (No space left on device) 00:45
error: writing to file: No space left on device 00:45
Nothing to push. 00:45 

Semaphore fails to detect this as although nix-build fails, cachix succeeds. The error code of a pipe is (normally) the error code of the last command. So we should try to break down the commands into two. Something like this:

nix-build --no-out-link release.nix > something

cat something | cachix push channable-public

Issue present since 19 April 2022

The CI build was failing all along for two previous versions:

The issue has been here since 19 April 2022 after this merge with hash c4c2e38353046a9526e4ffd5390e6b38b554cbcf PR #105.

The CI build was still okay on v0.24.0

rudymatela commented 2 years ago

Btw, thanks to @ReinierMaas for actually discovering that the build was broken in the first place. ... and to @maartenberg for suggesting cachix push channable $(nix-build ...) as an alternative fix. :-)

tomwassenberg commented 2 years ago

suggesting cachix push channable $(nix-build ...) as an alternative fix. :-)

I think cachix push channable $(nix-build ...) will still attempt to run the outer command (cachix ...) when the inner command (nix-build ...) fails.

So if we don't want to rely on the cachix command itself returning a non-zero exit code, I think this would fix it:

# This will return the exit code of the inner command 
$ hoff_store_path=$(nix-build ...)

# Thus, the pipeline will have failed before here if the nix-build was unsuccessful.
$ cachix push channable $hoff_store_path
ruuda commented 2 years ago

Semaphore fails to detect this as although nix-build fails, cachix succeeds. The error code of a pipe is (normally) the error code of the last command.

You can also set -o pipefail to prevent errors from being masked.