How to add actions to your workshop¶
Actions automate mundane tasks inside an existing workshop and enhance its functionality without modifying the SDKs themselves or running lengthy workshop exec commands.
Add actions¶
To add actions,
edit your workshop.yaml file,
adding named action definitions in bash format under actions
and making use of the features provided by the SDKs in your workshop
Here’s an example of a workshop definition with two actions that use the capabilities provided by the sketch SDK from the Customize with sketch SDKs tutorial section:
name: dev
base: ubuntu@22.04
sdks:
- name: go
channel: 1.26
actions:
lint: |
golangci-lint run --out-format=colored-line-number -c .golangci.yaml
shellcheck: |
git ls-files | file --mime-type -Nnf- | grep shellscript | cut -f1 -d: | xargs shellcheck --check-sourced --external-sources
Unlike changes in SDK layout or base, action updates do not require a workshop refresh.
Accept arguments¶
Action bodies are bash scripts, and they consume the arguments that workshop run forwards to them as positional parameters.
For instance,
"$@" expands to every argument passed after the action name,
while "$1", "$2", and so on pick individual ones.
To add a tests action
that forwards arbitrary flags and paths
to go test:
name: dev
base: ubuntu@22.04
sdks:
- name: go
channel: 1.26
actions:
tests: go test "$@"
Keep the quotes around "$@":
they preserve the boundaries between arguments,
so flags with spaces or wildcards reach the action intact.
Note
For details on bash positional parameters, see Special Parameters in the bash manual.
Run actions¶
To execute an action,
use the workshop run command.
Specify the workshop and its action,
with an optional separator (--):
$ workshop run dev -- lint
main.go:1:
./main.go:5:2: "os" imported and not used (typecheck)
package main
$ workshop run dev shellcheck
In 1.sh line 10:
cat /etc/passwd | grep root
^---------^ SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
Any arguments supplied after the action name
are forwarded to the action’s bash script
as positional parameters.
For example, the tests action defined above
runs a single test under a specific package:
$ workshop run dev -- tests -run TestFoo ./pkg/...
In projects with a single workshop, the workshop name is optional:
$ workshop run -- lint
Conclusion¶
By adding actions to your workshop, you can streamline your daily Workshop workflows and reduce the risk of typing errors.
For more advanced scripting capabilities, consider exploring additional features of the SDKs, such as hooks.
See also¶
Explanation:
Reference: