enabling and writing your own actions
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.
- id: npm-install
- files: [package.json]
run: npm install
- id: seed-database
- schedule: 24h
run: python3 seed_database.py
- id: custom-git-hook
- git_hooks: [pre-push, pre-commit]
- id: login
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_fromif 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
noderuntimes, 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
scheduleentries. For example:
- schedule: 1d
This is a short-hand for specifying schedule as an object. You can also write -
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
You may also use cron syntax:
# run every 2 hours
- schedule: "0 0 */2 * * ?"
# run every 2 hours
cron: "0 0 */2 * * ?"
We provide the ability to run actions automatically based on a file edit.
You may provide exact filenames, or globs.
- files: [foo.txt, bar/**]
In this case
my-actionwill execute if either
foo.txtis edited (or created), or if a file inside
baris edited or created.
Note: We only provide file triggers for files inside of your workspace.
Actions can read from
stdinif they are marked as interactive (define
interactive: trueon 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.