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 18:59:21 -03:00
|
|
|
```yaml
|
2018-03-28 15:31:09 +02:00
|
|
|
# .goreleaser.yml
|
|
|
|
before:
|
2019-03-03 14:12:22 -03:00
|
|
|
# Templates for the commands to be ran.
|
2018-03-28 15:31:09 +02:00
|
|
|
hooks:
|
|
|
|
- make clean
|
|
|
|
- go generate ./...
|
2020-02-17 13:13:28 +01:00
|
|
|
- go mod download
|
2019-03-03 14:12:22 -03:00
|
|
|
- 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 00:18:59 -03:00
|
|
|
|
|
|
|
It is important to note that you can't have "complex" commands, like
|
|
|
|
`bash -c "echo foo bar"` or `foo | bar` or anything like that. If you need
|
|
|
|
to do things that are more complex than just calling a command with some
|
|
|
|
attributes, wrap it in a shell script or into your `Makefile`.
|
2019-03-03 14:12:22 -03:00
|
|
|
|
2020-05-10 18:59:21 -03:00
|
|
|
!!! tip
|
2020-11-19 12:31:26 -08:00
|
|
|
Learn more about the [name template engine](/customization/templates/).
|