Integrate SDF into more complex workflows with pre and post hooks
SDF supports execution of arbitrary scripts
which can be executed via the sdf exec
command. In this way, you may string multiple commmands together, sequentially.
scripts
is a reserved name keyword in the config
yml block. Each property in scripts will be an independently executable command.
To execute any script run: sdf exec [SCRIPT_NAME]
Keep in mind:
stdout
and stderr
from subcommandssh
shell. Color coding will not be preserved.To configure a custom script, add a scripts
element to the config
block. Each element in the properties
array will become a separately executable command.
You are now able to execute these scripts as:
sdf exec my_script
sdf exec other_script
sdf exec macro_script
In addition to generic scripts, SDF has 4 reserved keywords which will execute scripts natively as part of sdf compile
and sdf run
commands.
pre-compile
-> When executing sdf compile
or sdf check
or sdf report
, the script in pre-compile is executed firstpost-compile
-> When executing sdf compile
or sdf check
or sdf report
, the script in post-compile is executed after compile has successfully finishedpre-run
-> When executing sdf run
or sdf test
or sdf stats
, the script in pre-run is executed firstpost-run
-> When executing sdf run
or sdf test
or sdf stats
, the script in post-run is executed after run has successfully finishedThe configuration below utilizes all 4 keywords. Let’s add it to the default workspace from sdf new
When executing sdf compile
, we now run the pre-compile script first, and then post-compile resulting in the below output.
Scripts allow for organization specific workflows
Scripts inherit the user of the calling SDF process. As a result sudo sdf exec ...
will run subcommands as sudo as well.
See the below script to validate whether an SDF script is root.