2018-03-28 15:31:09 +02:00
|
|
|
---
|
|
|
|
title: Global Hooks
|
|
|
|
---
|
|
|
|
|
|
|
|
Some builds may need pre-build steps before building, e.g. `go generate`.
|
|
|
|
The `before` section allows for global hooks which will be executed before
|
|
|
|
the build is started.
|
|
|
|
|
|
|
|
The configuration is very simple, here is a complete example:
|
|
|
|
|
2020-05-10 23:59:21 +02:00
|
|
|
```yaml
|
2018-03-28 15:31:09 +02:00
|
|
|
# .goreleaser.yml
|
|
|
|
before:
|
2019-03-03 19:12:22 +02:00
|
|
|
# Templates for the commands to be ran.
|
2018-03-28 15:31:09 +02:00
|
|
|
hooks:
|
2021-05-27 19:46:59 +02:00
|
|
|
- make clean
|
|
|
|
- go generate ./...
|
|
|
|
- go mod tidy
|
|
|
|
- touch {{ .Env.FILE_TO_TOUCH }}
|
2018-03-28 15:31:09 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
If any of the hooks fails the build process is aborted.
|
2018-08-15 05:18:59 +02:00
|
|
|
|
2021-05-27 19:47:38 +02:00
|
|
|
## 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 real fast.
|
|
|
|
|
|
|
|
|
2021-05-27 19:46:59 +02:00
|
|
|
## Pro Features
|
|
|
|
|
2021-06-21 04:13:49 +02:00
|
|
|
With [GoReleaser Pro](/pro/), things are a bit more flexible: you can specify the dir, environment variables and also global after hooks.
|
2021-05-27 00:08:46 +02:00
|
|
|
|
|
|
|
```yaml
|
|
|
|
# .goreleaser.yml
|
2021-05-27 19:46:59 +02:00
|
|
|
|
|
|
|
# global before hooks
|
|
|
|
before:
|
2021-05-27 00:08:46 +02:00
|
|
|
# Templates for the commands to be ran.
|
|
|
|
hooks:
|
|
|
|
- make clean # simple string
|
|
|
|
- cmd: go generate ./... # specify cmd
|
|
|
|
- cmd: go mod tidy
|
|
|
|
dir: ./submodule # specify command working directory
|
|
|
|
- cmd: touch {{ .Env.FILE_TO_TOUCH }}
|
|
|
|
env:
|
|
|
|
FILE_TO_TOUCH: 'something-{{ .ProjectName }}' # specify hook level environment variables
|
2021-05-27 19:46:59 +02:00
|
|
|
|
|
|
|
# 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
|
|
|
```
|
|
|
|
|
|
|
|
!!! info
|
2021-06-21 04:13:49 +02:00
|
|
|
Global after hooks is a [GoReleaser Pro feature](/pro/).
|
2019-03-03 19:12:22 +02:00
|
|
|
|
2020-05-10 23:59:21 +02:00
|
|
|
!!! tip
|
2020-11-19 22:31:26 +02:00
|
|
|
Learn more about the [name template engine](/customization/templates/).
|