mirror of
https://github.com/goreleaser/goreleaser.git
synced 2024-12-29 01:44:39 +02:00
fix(nix): multiple archives for the same platform (#4227)
this fixes is specially useful for universal binaries that replace the separated binaries. closes #4226
This commit is contained in:
parent
79688e0ae5
commit
1d17b311e3
@ -3,6 +3,7 @@ package nix
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -24,6 +25,10 @@ import (
|
||||
|
||||
const nixConfigExtra = "NixConfig"
|
||||
|
||||
// ErrMultipleArchivesSamePlatform happens when the config yields multiple
|
||||
// archives for the same platform.
|
||||
var ErrMultipleArchivesSamePlatform = errors.New("one nixpkg can handle only one archive of each OS/Arch combination")
|
||||
|
||||
type errNoArchivesFound struct {
|
||||
goamd64 string
|
||||
ids []string
|
||||
@ -287,7 +292,11 @@ func preparePkg(
|
||||
}
|
||||
|
||||
for _, goarch := range expandGoarch(art.Goarch) {
|
||||
data.Archives[art.Goos+goarch+art.Goarm] = archive
|
||||
key := art.Goos + goarch + art.Goarm
|
||||
if _, ok := data.Archives[key]; ok {
|
||||
return "", ErrMultipleArchivesSamePlatform
|
||||
}
|
||||
data.Archives[key] = archive
|
||||
plat := goosToPlatform[art.Goos+goarch+art.Goarm]
|
||||
platforms[plat] = true
|
||||
}
|
||||
|
@ -200,7 +200,8 @@ func TestRunPipe(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "unibin",
|
||||
name: "unibin",
|
||||
expectRunErrorIs: ErrMultipleArchivesSamePlatform,
|
||||
nix: config.Nix{
|
||||
Name: "unibin",
|
||||
IDs: []string{"unibin"},
|
||||
@ -452,9 +453,12 @@ func TestRunPipe(t *testing.T) {
|
||||
createFakeArtifact("partial", goos, goarch, "v1", "", "tar.gz", nil)
|
||||
createFakeArtifact("foo", goos, goarch, "v1", "", "tar.gz", nil)
|
||||
createFakeArtifact("unibin", goos, goarch, "v1", "", "tar.gz", nil)
|
||||
createFakeArtifact("unibin-replaces", goos, goarch, "v1", "", "tar.gz", nil)
|
||||
if goos != "darwin" {
|
||||
createFakeArtifact("unibin-replaces", goos, goarch, "v1", "", "tar.gz", nil)
|
||||
}
|
||||
createFakeArtifact("wrapped-in-dir", goos, goarch, "v1", "", "tar.gz", map[string]any{artifact.ExtraWrappedIn: "./foo"})
|
||||
createFakeArtifact("foo-zip", goos, goarch, "v1", "", "zip", nil)
|
||||
continue
|
||||
}
|
||||
if goarch == "arm" {
|
||||
if goos != "linux" {
|
||||
@ -462,12 +466,15 @@ func TestRunPipe(t *testing.T) {
|
||||
}
|
||||
createFakeArtifact("foo", goos, goarch, "", "6", "tar.gz", nil)
|
||||
createFakeArtifact("foo", goos, goarch, "", "7", "tar.gz", nil)
|
||||
createFakeArtifact("foo-zip", goos, goarch, "v1", "", "zip", nil)
|
||||
createFakeArtifact("foo-zip", goos, goarch, "", "", "zip", nil)
|
||||
createFakeArtifact("unibin-replaces", goos, goarch, "", "", "tar.gz", nil)
|
||||
continue
|
||||
}
|
||||
createFakeArtifact("foo", goos, goarch, "", "", "tar.gz", nil)
|
||||
createFakeArtifact("unibin", goos, goarch, "", "", "tar.gz", nil)
|
||||
createFakeArtifact("unibin-replaces", goos, goarch, "", "", "tar.gz", nil)
|
||||
if goos != "darwin" {
|
||||
createFakeArtifact("unibin-replaces", goos, goarch, "", "", "tar.gz", nil)
|
||||
}
|
||||
createFakeArtifact("wrapped-in-dir", goos, goarch, "", "", "tar.gz", map[string]any{artifact.ExtraWrappedIn: "./foo"})
|
||||
createFakeArtifact("foo-zip", goos, goarch, "v1", "", "zip", nil)
|
||||
}
|
||||
|
@ -20,8 +20,8 @@ let
|
||||
i686-linux = "https://dummyhost/download/v1.2.1/foo_linux_386.tar.gz";
|
||||
x86_64-linux = "https://dummyhost/download/v1.2.1/foo_linux_amd64v1.tar.gz";
|
||||
aarch64-linux = "https://dummyhost/download/v1.2.1/foo_linux_arm64.tar.gz";
|
||||
x86_64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_amd64v1.tar.gz";
|
||||
aarch64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_arm64.tar.gz";
|
||||
x86_64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_all.tar.gz";
|
||||
aarch64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_all.tar.gz";
|
||||
};
|
||||
in
|
||||
pkgs.stdenv.mkDerivation {
|
||||
|
@ -12,16 +12,16 @@ let
|
||||
i686-linux = "sha16";
|
||||
x86_64-linux = "sha1";
|
||||
aarch64-linux = "sha2";
|
||||
x86_64-darwin = "sha3";
|
||||
aarch64-darwin = "sha4";
|
||||
x86_64-darwin = "sha5";
|
||||
aarch64-darwin = "sha5";
|
||||
};
|
||||
|
||||
urlMap = {
|
||||
i686-linux = "https://dummyhost/download/v1.2.1/foo_linux_386.tar.gz";
|
||||
x86_64-linux = "https://dummyhost/download/v1.2.1/foo_linux_amd64v1.tar.gz";
|
||||
aarch64-linux = "https://dummyhost/download/v1.2.1/foo_linux_arm64.tar.gz";
|
||||
x86_64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_amd64v1.tar.gz";
|
||||
aarch64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_arm64.tar.gz";
|
||||
x86_64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_all.tar.gz";
|
||||
aarch64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_all.tar.gz";
|
||||
};
|
||||
in
|
||||
pkgs.stdenv.mkDerivation {
|
||||
|
@ -1,59 +0,0 @@
|
||||
# This file was generated by GoReleaser. DO NOT EDIT.
|
||||
# vim: set ft=nix ts=2 sw=2 sts=2 et sta
|
||||
{
|
||||
system ? builtins.currentSystem
|
||||
, pkgs
|
||||
, lib
|
||||
, fetchurl
|
||||
, installShellFiles
|
||||
}:
|
||||
let
|
||||
shaMap = {
|
||||
i686-linux = "0000000000000000000000000000000000000000000000000000";
|
||||
x86_64-linux = "0000000000000000000000000000000000000000000000000000";
|
||||
aarch64-linux = "0000000000000000000000000000000000000000000000000000";
|
||||
x86_64-darwin = "0000000000000000000000000000000000000000000000000000";
|
||||
aarch64-darwin = "0000000000000000000000000000000000000000000000000000";
|
||||
};
|
||||
|
||||
urlMap = {
|
||||
i686-linux = "https://dummyhost/download/v1.2.1/foo_linux_386.tar.gz";
|
||||
x86_64-linux = "https://dummyhost/download/v1.2.1/foo_linux_amd64v1.tar.gz";
|
||||
aarch64-linux = "https://dummyhost/download/v1.2.1/foo_linux_arm64.tar.gz";
|
||||
x86_64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_amd64v1.tar.gz";
|
||||
aarch64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_arm64.tar.gz";
|
||||
};
|
||||
in
|
||||
pkgs.stdenv.mkDerivation {
|
||||
pname = "unibin";
|
||||
version = "1.2.1";
|
||||
src = fetchurl {
|
||||
url = urlMap.${system};
|
||||
sha256 = shaMap.${system};
|
||||
};
|
||||
|
||||
sourceRoot = ".";
|
||||
|
||||
nativeBuildInputs = [ installShellFiles ];
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp -vr ./foo $out/bin/foo
|
||||
'';
|
||||
|
||||
system = system;
|
||||
|
||||
meta = {
|
||||
description = "my test";
|
||||
homepage = "https://goreleaser.com";
|
||||
license = lib.licenses.mit;
|
||||
|
||||
platforms = [
|
||||
"aarch64-darwin"
|
||||
"aarch64-linux"
|
||||
"i686-linux"
|
||||
"x86_64-darwin"
|
||||
"x86_64-linux"
|
||||
];
|
||||
};
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
# This file was generated by GoReleaser. DO NOT EDIT.
|
||||
# vim: set ft=nix ts=2 sw=2 sts=2 et sta
|
||||
{
|
||||
system ? builtins.currentSystem
|
||||
, pkgs
|
||||
, lib
|
||||
, fetchurl
|
||||
, installShellFiles
|
||||
}:
|
||||
let
|
||||
shaMap = {
|
||||
i686-linux = "sha16";
|
||||
x86_64-linux = "sha1";
|
||||
aarch64-linux = "sha2";
|
||||
x86_64-darwin = "sha3";
|
||||
aarch64-darwin = "sha4";
|
||||
};
|
||||
|
||||
urlMap = {
|
||||
i686-linux = "https://dummyhost/download/v1.2.1/foo_linux_386.tar.gz";
|
||||
x86_64-linux = "https://dummyhost/download/v1.2.1/foo_linux_amd64v1.tar.gz";
|
||||
aarch64-linux = "https://dummyhost/download/v1.2.1/foo_linux_arm64.tar.gz";
|
||||
x86_64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_amd64v1.tar.gz";
|
||||
aarch64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_arm64.tar.gz";
|
||||
};
|
||||
in
|
||||
pkgs.stdenv.mkDerivation {
|
||||
pname = "unibin";
|
||||
version = "1.2.1";
|
||||
src = fetchurl {
|
||||
url = urlMap.${system};
|
||||
sha256 = shaMap.${system};
|
||||
};
|
||||
|
||||
sourceRoot = ".";
|
||||
|
||||
nativeBuildInputs = [ installShellFiles ];
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp -vr ./foo $out/bin/foo
|
||||
'';
|
||||
|
||||
system = system;
|
||||
|
||||
meta = {
|
||||
description = "my test";
|
||||
homepage = "https://goreleaser.com";
|
||||
license = lib.licenses.mit;
|
||||
|
||||
platforms = [
|
||||
"aarch64-darwin"
|
||||
"aarch64-linux"
|
||||
"i686-linux"
|
||||
"x86_64-darwin"
|
||||
"x86_64-linux"
|
||||
];
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user