1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/www/docs/customization/hooks.md

75 lines
2.2 KiB
Markdown
Raw Normal View History

2021-10-30 14:50:23 +02:00
# Global Hooks
2018-03-28 15:31:09 +02:00
Some release cycles may need to run something before or after everything else.
2018-03-28 15:31:09 +02:00
GoReleaser allows this with the global hooks feature.
2018-03-28 15:31:09 +02:00
=== "OSS"
The `before` section allows for global hooks that will be executed
**before** the release is started.
2018-03-28 15:31:09 +02:00
The configuration is straightforward, here is an example will all possible
options:
2018-08-15 05:18:59 +02:00
```yaml
# .goreleaser.yaml
before:
# Templates for the commands to be ran.
hooks:
- make clean
- go generate ./...
- go mod tidy
- touch {{ .Env.FILE_TO_TOUCH }}
```
2021-05-27 19:47:38 +02:00
=== "Pro"
!!! success "GoReleaser Pro"
Global after hooks, and the additional options in before hooks (`dir`
and `env`) are [GoReleaser Pro features](/pro/).
2021-05-27 19:47:38 +02:00
The `before` section allows for global hooks that will be executed
**before** the release is started. Likewise, the `after` section allows for
global hooks that will be executed **after** the release is started.
The configuration is straightforward, here is an example will all possible
options:
2021-05-27 19:47:38 +02:00
```yaml
# .goreleaser.yaml
# global before hooks
before:
# Templates for the commands to be ran.
hooks:
- make clean # simple string
- cmd: go generate ./... # specify cmd
- cmd: go mod tidy
output: true # always prints command output. Since GoReleaser v1.5.
dir: ./submodule # specify command working directory
- cmd: touch {{ .Env.FILE_TO_TOUCH }}
env:
- 'FILE_TO_TOUCH=something-{{ .ProjectName }}' # specify hook level environment variables
# global after hooks
after:
# Templates for the commands to be ran.
hooks:
- make clean
- cmd: cat *.yaml
dir: ./submodule
- cmd: touch {{ .Env.RELEASE_DONE }}
env:
- 'RELEASE_DONE=something-{{ .ProjectName }}' # specify hook level environment variables
```
2021-05-27 00:08:46 +02:00
Note that if any of the hooks fails the release process is aborted.
## Complex commands
If you need to do anything more complex, it is recommended to create a shell
script and call it instead. You can also go crazy with `sh -c "my commands"`,
but it gets ugly really fast.
2021-05-27 00:08:46 +02:00
!!! tip
Learn more about the [name template engine](/customization/templates/).