Live data from Hacker News

Grep one-liners as CI tasks

phili.pe

11–20 of 36 posts

Re: Grep one-liners as CI tasks

#11
Shameless plug: if you find yourself wanting more advamced custom painting, you can try http://trunk.io, which provides you with three different ways to write your own linters (pass/fail based on your script's exit code, spit out a patch that should be applied to your code, or LSP diagnostics) that can get propagated to VSCode and CI (as well as just as a CLI tool, if that's your preference).

Disclaimer: I work on trunk :)

Re: Grep one-liners as CI tasks

#13

Wouldn't this example do the incorrect thing in the event of a grep error (exit code 2)?

Depends on what you mean by wrong. If the tests can’t run successfully because they detect an error or because they have an error, it still is a valuable signal to raise to the developer.

Consider what would happen if your unit test framework couldn’t compile the test files and failed with an error. Isn’t that also a test failure?

Re: Grep one-liners as CI tasks

#14

Wouldn't this example do the incorrect thing in the event of a grep error (exit code 2)?

I guess testing specifically for an exit code of 1 isn't as easy to remember.

  (grep -q notwanted /hay/stack ; test $? == 1) && echo "No violations found"
But you're right...the simpler format would do the wrong thing if, for example, the file didn't exist or had bad permissions or was a directory instead of a file.

Re: Grep one-liners as CI tasks

#15

Here is my favorite: https://github.com/ClickHouse/ClickHouse/blob/master/utils/c... "Too many exclamation marks"

I wonder how they picked three as too many. Why not two?

> Three shall be the number thou shalt count, and the number of the counting shall be three. Four shalt thou not count, neither count thou two, excepting that thou then proceed to three. Five is right out.

Re: Grep one-liners as CI tasks

#16

Wouldn't this example do the incorrect thing in the event of a grep error (exit code 2)?

Depends on what you mean by wrong. If the tests can’t run successfully because they detect an error or because they have an error, it still is a valuable signal to raise to the developer. Consider what would happen if your unit test framework couldn’t compile the test files and failed with an error. Isn’t that also a test failure?

What would happen is the test would pass, as the logical not of 2 is 0.

To address this: many CI pipelines allow you to specify which exot codes to succeed and fail on per job, or if it doesn't the one liner will need some boolean logic to check the exit code.

Re: Grep one-liners as CI tasks

#17
post #5

grep and other shell tool one-liners also make excellent kubernetes liveness checks. I have some kubernetes daemonsets that don't do anything other than assert that things on the node are as they should, via grep exit status.

It's also useful for alternative health check commands depending on which environment you're in.

For example you could configure a Docker Compose health check to curl an endpoint for a 200 in production but in development override the health check command to call /bin/true so you don't get log spam in development from your health check while ensuring the health check still passes since /bin/true is an extremely minimal command that returns an exit code of 0. This can be controlled by a single environment variable too, no changes needed to your docker-compose.yml file.

I covered this pattern in a recent DockerCon talk at https://nickjanetakis.com/blog/best-practices-around-product....

Re: Grep one-liners as CI tasks

#18

Here is my favorite: https://github.com/ClickHouse/ClickHouse/blob/master/utils/c... "Too many exclamation marks"

I wonder how they picked three as too many. Why not two? > Three shall be the number thou shalt count, and the number of the counting shall be three. Four shalt thou not count, neither count thou two, excepting that thou then proceed to three. Five is right out.

[deleted]

Re: Grep one-liners as CI tasks

#19
Wouldn't quick sanity checks like these make more sense in a git push hook?

No reason to wait for the CI. There's also the risk of broken intermediary commits unless the CI check each and every commit in isolation.

Re: Grep one-liners as CI tasks

#20
post #19

Wouldn't quick sanity checks like these make more sense in a git push hook? No reason to wait for the CI. There's also the risk of broken intermediary commits unless the CI check each and every commit in isolation.

One of the benefits of CI is that I don't need to make assumptions about the environment I'm operating in - that is, I don't need to worry about a tool like `jq` being installed, whether I have GNU or BSD `date`, or the biggest one in this case, whether I've even installed a commit hook after cloning the repo. It only takes one new hire that hasn't set up the hooks to merge a change that makes the repo fail checks.
Post reply on HN