2021-10-30 14:50:23 +02:00
|
|
|
# Monorepo
|
2021-05-27 00:08:46 +02:00
|
|
|
|
2021-09-23 04:30:16 +02:00
|
|
|
!!! success "GoReleaser Pro"
|
|
|
|
The monorepo support is a [GoReleaser Pro feature](/pro/).
|
|
|
|
|
2022-09-17 05:13:09 +02:00
|
|
|
If you want to use GoReleaser within a monorepo and use tag prefixes to mark
|
|
|
|
"which tags belong to which sub project", GoReleaser has you covered.
|
2021-05-27 00:08:46 +02:00
|
|
|
|
2022-09-04 21:16:21 +02:00
|
|
|
## Premises
|
2021-05-27 00:08:46 +02:00
|
|
|
|
2022-09-04 21:16:21 +02:00
|
|
|
You project falls into either one of these categories:
|
|
|
|
|
|
|
|
1. tags are like `subproject1/v1.2.3` and `subproject2/v1.2.3`;
|
|
|
|
1. tags are like `@user/thing@v1.2.3` (for a NPM package, for example)
|
|
|
|
and `v1.2.3` for the rest of the (Go) code.
|
2021-05-27 00:08:46 +02:00
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
2022-09-04 21:16:21 +02:00
|
|
|
### Category 1
|
|
|
|
|
2022-09-17 05:13:09 +02:00
|
|
|
You'll need to create a `.goreleaser.yaml` for each subproject you want to use
|
|
|
|
GoReleaser in:
|
2021-05-27 00:08:46 +02:00
|
|
|
|
|
|
|
```yaml
|
2021-12-23 02:52:01 +02:00
|
|
|
# subroj1/.goreleaser.yaml
|
2021-05-27 00:08:46 +02:00
|
|
|
project_name: subproj1
|
|
|
|
|
|
|
|
monorepo:
|
|
|
|
tag_prefix: subproject1/
|
2021-08-04 22:39:50 +02:00
|
|
|
dir: subproj1
|
2021-05-27 00:08:46 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
Then, you can release with (from the project's root directory):
|
|
|
|
|
2022-09-04 21:16:21 +02:00
|
|
|
```bash
|
2021-12-23 02:52:01 +02:00
|
|
|
goreleaser release --rm-dist -f ./subproj1/.goreleaser.yaml
|
2021-05-27 00:08:46 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
Then, the following is different from a "regular" run:
|
|
|
|
|
2022-09-17 05:13:09 +02:00
|
|
|
- GoReleaser will then look if current commit has a tag prefixed with
|
|
|
|
`subproject1`, and the previous tag with the same prefix;
|
|
|
|
- Changelog will include only commits that contain changes to files within the
|
|
|
|
`subproj1` directory;
|
2021-05-27 00:08:46 +02:00
|
|
|
- Release name gets prefixed with `{{ .ProjectName }} ` if empty;
|
2021-08-04 22:39:50 +02:00
|
|
|
- All build's `dir` setting get set to `monorepo.dir` if empty;
|
2021-05-27 00:08:46 +02:00
|
|
|
- if yours is not, you might want to change that manually;
|
2022-09-17 05:13:09 +02:00
|
|
|
- Extra files on the release, archives, Docker builds, etc are prefixed with
|
|
|
|
`monorepo.dir`;
|
2022-10-12 03:09:42 +02:00
|
|
|
- If using `changelog.use: git`, only commits matching files in `monorepo.dir`
|
|
|
|
will be included in the changelog.
|
2022-09-17 05:13:09 +02:00
|
|
|
- On templates, `{{.PrefixedTag}}` will be `monorepo.prefix/tag` (aka the actual
|
|
|
|
tag name), and `{{.Tag}}` has the prefix stripped;
|
2021-05-27 00:08:46 +02:00
|
|
|
|
|
|
|
The rest of the release process should work as usual.
|
|
|
|
|
2022-09-04 21:16:21 +02:00
|
|
|
|
|
|
|
### Category 2
|
|
|
|
|
|
|
|
You'll need to create a `.goreleaser.yaml` for your Go code in the root of the
|
|
|
|
project:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
# .goreleaser.yaml
|
|
|
|
monorepo:
|
|
|
|
tag_prefix: v
|
|
|
|
```
|
|
|
|
|
|
|
|
Then, you can release with:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
goreleaser release --rm-dist
|
|
|
|
```
|
|
|
|
|
|
|
|
GoReleaser will then ignore the tags that are not prefixed with `v`, and it
|
|
|
|
should work as expected from there on.
|