Configuration: Enabling and Writing your own Actions
Actions are defined and enabled in the
actions section of
Here is an example of the actions section of
trunk.yaml. If you are curious what your resolved configuration for actions looks like, run
trunk config print.
actions: enabled: - trunk-announce - trunk-upgrade-available - npm-install - seed-database - custom-git-hook - login definitions: - id: npm-install triggers: - files: [package.json] run: npm install - id: seed-database triggers: - schedule: 24h run: python3 seed_database.py runtime: python run_from: utils packages_file: requirements.txt - id: custom-git-hook triggers: - git_hooks: [pre-push, pre-commit] run: my_script.sh - id: login run: my_complicated_login_script.sh interactive: true
Now we'll walk through the process of creating your own action.
Actions are required to have a
The command will implicitly run relative to your workspace, but you can also specify a
run_from if you'd prefer to execute from a sub-directory.
We sandbox action executions and allow you to control the runtime. You can do this by specifying a
You can specify one of our built-in runtimes (
python, ...) or a system runtime that you define. See the runtimes documentation for more information.
node runtimes, we additionally provide the ability to install a requirements file like
You may run an action manually by running
trunk run <action_id> <args> or
trunk actions run <action_id> <args>. However, you can also provide a set of triggers so that actions run in response to some event. They are documented below.
We provide the ability to run actions in the background on a schedule.
triggers, you can add one or more
schedule entries. For example:
id: my-action triggers: - schedule: 1d
schedule entry should be in the Duration format specified here. The action will be run once per
This is a short-hand for specifying schedule as an object. You can also write -
id: my-action triggers: - schedule: interval: 1d
The action may occasionally run more often than the specified duration depending on the Trunk daemon's lifetime.
If you wish to stagger the execution of an action from others on a similar schedule, you may use the
delay field -
id: my-action triggers: - schedule: interval: 1d delay: 1h
You may also use cron syntax:
id: my-action triggers: # run every 2 hours - schedule: "0 0 */2 * * ?"
id: my-action triggers: # run every 2 hours - schedule: cron: "0 0 */2 * * ?"
We provide the ability to run actions automatically based on a file edit.
You may provide exact filenames, or globs.
id: my-action triggers: - files: [foo.txt, bar/**]
In this case
my-action will execute if either
foo.txt is edited (or created), or if a file inside
bar is edited or created.
Note: We only provide file triggers for files inside of your workspace.
You can also configure trunk to manage your git hooks. More detail is provided on this in our git hooks reference.
Actions can read from
stdin if they are marked as interactive (define
interactive: true on the action). Note - this feature is only available for git hooks and manually run actions - since file-triggered and scheduled actions run in the background, you cannot interact with their execution.
Updated 6 months ago