2021-10-30 14:50:23 +02:00
|
|
|
# Global Hooks
|
2018-03-28 15:31:09 +02:00
|
|
|
|
2022-09-17 05:13:09 +02:00
|
|
|
Some release cycles may need to run something before or after everything else.
|
2018-03-28 15:31:09 +02:00
|
|
|
|
2021-09-23 04:37:30 +02:00
|
|
|
GoReleaser allows this with the global hooks feature.
|
2018-03-28 15:31:09 +02:00
|
|
|
|
2021-09-23 04:37:30 +02:00
|
|
|
=== "OSS"
|
2022-09-17 05:13:09 +02:00
|
|
|
The `before` section allows for global hooks that will be executed
|
|
|
|
**before** the release is started.
|
2018-03-28 15:31:09 +02:00
|
|
|
|
2022-09-17 05:13:09 +02:00
|
|
|
The configuration is straightforward, here is an example will all possible
|
|
|
|
options:
|
2018-08-15 05:18:59 +02:00
|
|
|
|
2021-09-23 04:37:30 +02:00
|
|
|
```yaml
|
2021-12-23 02:52:01 +02:00
|
|
|
# .goreleaser.yaml
|
2021-09-23 04:37:30 +02:00
|
|
|
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
|
|
|
|
2021-09-23 05:31:50 +02:00
|
|
|
=== "Pro"
|
2021-09-23 04:37:30 +02:00
|
|
|
!!! success "GoReleaser Pro"
|
2022-09-17 05:13:09 +02:00
|
|
|
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
|
|
|
|
2022-09-17 05:13:09 +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.
|
2021-09-23 04:40:55 +02:00
|
|
|
|
2022-09-17 05:13:09 +02:00
|
|
|
The configuration is straightforward, here is an example will all possible
|
|
|
|
options:
|
2021-05-27 19:47:38 +02:00
|
|
|
|
2021-09-23 04:37:30 +02:00
|
|
|
```yaml
|
2021-12-23 02:52:01 +02:00
|
|
|
# .goreleaser.yaml
|
2021-09-23 04:37:30 +02:00
|
|
|
# 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
|
2022-09-11 21:54:51 +02:00
|
|
|
output: true # always prints command output. Since GoReleaser v1.5.
|
2021-09-23 04:37:30 +02:00
|
|
|
dir: ./submodule # specify command working directory
|
|
|
|
- cmd: touch {{ .Env.FILE_TO_TOUCH }}
|
|
|
|
env:
|
2021-12-15 21:03:58 +02:00
|
|
|
- 'FILE_TO_TOUCH=something-{{ .ProjectName }}' # specify hook level environment variables
|
2021-05-27 19:46:59 +02:00
|
|
|
|
2021-09-23 04:37:30 +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:
|
2021-12-15 21:03:58 +02:00
|
|
|
- 'RELEASE_DONE=something-{{ .ProjectName }}' # specify hook level environment variables
|
2021-09-23 04:37:30 +02:00
|
|
|
```
|
2021-09-23 04:30:16 +02:00
|
|
|
|
2021-05-27 00:08:46 +02:00
|
|
|
|
2021-09-23 04:40:55 +02:00
|
|
|
Note that if any of the hooks fails the release process is aborted.
|
2021-05-27 19:46:59 +02:00
|
|
|
|
2021-09-23 04:37:30 +02:00
|
|
|
## Complex commands
|
|
|
|
|
2022-09-17 05:13:09 +02:00
|
|
|
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
|
|
|
|
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/).
|