Notifications
Trunk Actions can also produce notifications to display in your terminal or in the VSCode extension!
Defining actions that produce notifications
Typically, whatever actions write to stdout is stored in the log file and perhaps shown to the user. However, actions can also produce structured output if output_type
is set on the Action Definition to be notification_v1
.
In this case, the action should print yaml to output with the following structure:
Some notes:
The ID can be whatever you want it to, but generally should be made to match the action ID.
You may emit multiple notifications per action.
icon
andcommands
are used to control notifications display in VSCode.High priority notifications are immediately shown to the user in terminal. Low priority notifications are only shown every 24 hours (These are configurable).
Deleting notifications
Actions can also clear their own notifications. in this case, make the output looks like this:
If actions produce a notification that is reflective of a current state or something actionable for the user to do, they may clear the notification once that state changes/when the user takes the requested action.
An example
We illustrate the cycle of actions managing their own notifications with the following example.
Consider the built-in action for trunk upgrade
- a command that upgrades trunk and a repo's enabled linters to their most recent versions. We'd like to notify the user of new upgrades once a day. Thus our trunk-upgrade-available
action definition looks like this:
trunk upgrade --notify
produces a notification that looks like this:
If there are no upgrades available, trunk upgrade --notify
will produce:
So in this scenario, the trunk-upgrade-available
action runs in the background periodically and produces a notification. The user takes action by running trunk upgrade
. Since trunk upgrade
modifies .trunk/trunk.yaml
, this will again trigger the trunk-upgrade-available
action (due to the file trigger). Since there is nothing else to upgrade, trunk upgrade --notify
will produce output telling Trunk to delete its notification. Now, the user is no longer shown a notification about available upgrades!
Last updated