Hooks
Hooks are scripts that run before and/or after task execution.
Tasks can produce hook scripts which dependent tasks will then execute.
A common use case for hooks is authentication. A before script can authenticate into a service, while an after script can ensure credentials are removed from disk.
Hooks will run in the order dependencies are specified in the use declaration of the task.
Example
Create hooks by writing scripts to the $MINT_HOOKS_BEFORE_TASK
and $MINT_HOOKS_AFTER_TASK
directories.
tasks:
- key: some-auth-hook
run: |
cp --preserve mode your-login-script.sh $MINT_HOOKS_BEFORE_TASK
cp --preserve mode your-logout-script.sh $MINT_HOOKS_AFTER_TASK
When writing scripts to the hooks directories make sure that the scripts are executable, either via using cp --preserve
or chmod +x
after writing the file to the directory.
To configure a task to use the hook, add it to the dependencies via use
.
tasks:
- key: example-task
use: some-auth-hook
run: ...
In this case, your-login-script.sh
would run before the run
script of example-task
, and your-logout-script.sh
would run after the run
script of example-task
.
Transitive Dependencies
Hooks will also run for transitive dependencies. For example:
tasks:
- key: example-task
use: some-auth-hook
run: ...
- key: another-example-task
use: example-task
run: ...
In this case, the hooks configured via some-auth-hook
will run around both example-task
and also another-example-task
.
Execution Logic
- Hooks execute in the same order that tasks are specified in
use
- If one task produces multiple hooks, they will run in alphabetical order
- If one task overwrites a hook from another task, only the rightmost task in
use
will run - If a hook exits non-zero, the task will fail
The file names for hook scripts should be sufficiently unique, because they're all flattened in the same directory. Avoid conflicts by choosing a unique name for your script.