Skip to content

Commit

Permalink
fix: binary archive when multiple builds
Browse files Browse the repository at this point in the history
closes #3383

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Sep 17, 2022
1 parent 0ea3e0f commit fce8a78
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/pipe/archive/archive.go
Expand Up @@ -32,7 +32,7 @@ const (
// ErrArchiveDifferentBinaryCount happens when an archive uses several builds which have different goos/goarch/etc sets,
// causing the archives for some platforms to have more binaries than others.
// GoReleaser breaks in these cases as it will only cause confusion to other users.
var ErrArchiveDifferentBinaryCount = errors.New("archive has different count of built binaries for each platform, which may cause your users confusion. Please make sure all builds used have the same set of goos/goarch/etc or split it into multiple archives")
var ErrArchiveDifferentBinaryCount = errors.New("archive has different count of binaries for each platform, which may cause your users confusion.\nLearn more at https://goreleaser.com/errors/multiple-binaries-archive\n")

// nolint: gochecknoglobals
var lock sync.Mutex
Expand Down Expand Up @@ -96,7 +96,7 @@ func (Pipe) Run(ctx *context.Context) error {
filter = append(filter, artifact.ByIDs(archive.Builds...))
}
artifacts := ctx.Artifacts.Filter(artifact.And(filter...)).GroupByPlatform()
if err := checkArtifacts(artifacts); err != nil && !archive.AllowDifferentBinaryCount {
if err := checkArtifacts(artifacts); err != nil && archive.Format != "binary" && !archive.AllowDifferentBinaryCount {
return fmt.Errorf("invalid archive: %d: %w", i, ErrArchiveDifferentBinaryCount)
}
for group, artifacts := range artifacts {
Expand Down
51 changes: 51 additions & 0 deletions www/docs/errors/multiple-binaries-archive.md
@@ -0,0 +1,51 @@
# Archive has different count of binaries for each platform

This error looks like this:

```sh
⨯ release failed after 5s error=invalid archive: 0:archive has different count of binaries for each platform, which may cause your users confusion.
Learn more at https://goreleaser.com/errors/multiple-binaries-archive

```

This will happen when you have several builds, and their target platforms are
different:

```yaml
builds:
- id: b1
binary: b1
goos: [linux, darwin]
- id: b2
binary: b2
goos: [darwin]

archives:
- id: a1
```

In this scenario, GoReleaser will complain because the archive will have a
different binary count depending on which platform its being archived, since
it'll have 2 binaries on `darwin` and only 1 on `linux`.


From here on, you have a couple of options:

- add another archive, and filter the builds on each of them - e.g. archive `a1`
with binaries from build `b1`, and archive `a2` with builds from build `b2`:
```yaml
archives:
- id: a1
builds: b1
name_template: something-unique-for-a1
- id: a2
builds: b2
name_template: something-unique-for-a2
```
- if you really want to have the mixed archive, you can add
`allow_different_binary_count` to your archive configuration:
```yaml
archives:
- id: a1
allow_different_binary_count: true
```
1 change: 1 addition & 0 deletions www/mkdocs.yml
Expand Up @@ -139,6 +139,7 @@ nav:
- errors/no-main.md
- errors/resource-not-accessible-by-integration.md
- errors/no-history.md
- errors/multiple-binaries-archive.md
- deprecations.md
- Cookbooks:
- About: cookbooks/index.md
Expand Down

0 comments on commit fce8a78

Please sign in to comment.