|
|
@ -1,14 +1,13 @@
|
|
|
|
---
|
|
|
|
---
|
|
|
|
title: "Git Tips - Lint + Test Pre-commit Hook"
|
|
|
|
title: "Git Tips - Lint + Test Pre-commit Hook"
|
|
|
|
date: 2020-01-01T21:00:39Z
|
|
|
|
date: 2020-01-01T21:00:39Z
|
|
|
|
tags: [git, bash, ]
|
|
|
|
tags: [git, bash]
|
|
|
|
---
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
One of my favorite inventions is a `pre-commit` hook that auto runs test and lint commands from a `makefile` or
|
|
|
|
One of my favorite inventions is a `pre-commit` hook that auto runs test and lint commands from a `makefile` or
|
|
|
|
`package.json` if they're found:
|
|
|
|
`package.json` if they're found:
|
|
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
```bash {linenos=table}
|
|
|
|
{{<highlight bash "linenos=table">}}
|
|
|
|
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
|
|
|
if [ -f "$PWD/makefile" ] && [ ! -z "$(cat $PWD/makefile | grep '^lint:')" ]; then
|
|
|
|
if [ -f "$PWD/makefile" ] && [ ! -z "$(cat $PWD/makefile | grep '^lint:')" ]; then
|
|
|
@ -26,7 +25,6 @@ elif [ -f "$PWD/package.json" ] && [ ! -z "$(cat $PWD/package.json | grep "^\"te
|
|
|
|
echo "running npm run test"
|
|
|
|
echo "running npm run test"
|
|
|
|
npm run test
|
|
|
|
npm run test
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
{{</highlight>}}
|
|
|
|
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
The `/usr/bin/env bash` piece ensures that the script has access to all of the environment variables you expect in your
|
|
|
|
The `/usr/bin/env bash` piece ensures that the script has access to all of the environment variables you expect in your
|
|
|
|