Common builder bash utilities across multiple CrashOverride repos
Add to build.sh
:
util=_util.sh
commit=main # or pin commit/tag
util_url=https://raw.githubusercontent.com/crashappsec/util.sh/$commit/util.sh
[ ! -f $util ] && curl -f -L $util_url -o $util
source $util
This will allow you to call reusable functions. For example:
exit_on_common $@
util.sh
exposes multiple bash functions. All function names starting with
_
are considered private functions and should not be directly used. Other
functions are allowed to be used. All public functions in the comment above
have usage example how to use them.
util.sh
can also auto-generate help from the both the bash files
as well as other supporting files.
To see help simply run either:
./build.sh help
./build.sh -h
./build.sh --help
Add a comment with the format:
## help:command:<commandname> <description>
For example:
## help:command:lint run lint checks
In addition to documenting commands, flags can be documented as well:
## help:flag:<flag> <description>
For example:
## help:flag:-v/--verbose show debug logs
Each Makefile target can document its help with:
<target>: ## <description>
For example:
lint: ## run lint checks
As this is a json file, to keep syntax valid json, all help strings are extracted from the script string itself:
{
"scripts": {
"<name>": "<command> ## <description>"
}
}
For example:
{
"scripts": {
"lint": "eslint ## run lint checks"
}
}
util.sh
can also automatically figure out which compose service should be
used for the given command. The service_for_compose
accepts the default
service if not override is found. Overrides can be specified like so:
<target>: # docker-compose:<service>
For example:
lint: # docker-compose:precommit
docker-compose
service is annotated as part of the help description
{
"scripts": {
"<name>": "<command> ## @@docker-compose:<service> <description>"
}
}
For example:
{
"scripts": {
"test": "playwright test ## @@docker-compose:tests run UI tests"
}
}