1
0
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:
Carlos Alexandro Becker 2023-08-02 22:58:10 -03:00 committed by GitHub
parent 79688e0ae5
commit 1d17b311e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 129 deletions

View File

@ -3,6 +3,7 @@ package nix
import ( import (
"bufio" "bufio"
"bytes" "bytes"
"errors"
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
@ -24,6 +25,10 @@ import (
const nixConfigExtra = "NixConfig" 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 { type errNoArchivesFound struct {
goamd64 string goamd64 string
ids []string ids []string
@ -287,7 +292,11 @@ func preparePkg(
} }
for _, goarch := range expandGoarch(art.Goarch) { 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] plat := goosToPlatform[art.Goos+goarch+art.Goarm]
platforms[plat] = true platforms[plat] = true
} }

View File

@ -200,7 +200,8 @@ func TestRunPipe(t *testing.T) {
}, },
}, },
{ {
name: "unibin", name: "unibin",
expectRunErrorIs: ErrMultipleArchivesSamePlatform,
nix: config.Nix{ nix: config.Nix{
Name: "unibin", Name: "unibin",
IDs: []string{"unibin"}, IDs: []string{"unibin"},
@ -452,9 +453,12 @@ func TestRunPipe(t *testing.T) {
createFakeArtifact("partial", goos, goarch, "v1", "", "tar.gz", nil) createFakeArtifact("partial", goos, goarch, "v1", "", "tar.gz", nil)
createFakeArtifact("foo", goos, goarch, "v1", "", "tar.gz", nil) createFakeArtifact("foo", goos, goarch, "v1", "", "tar.gz", nil)
createFakeArtifact("unibin", 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("wrapped-in-dir", goos, goarch, "v1", "", "tar.gz", map[string]any{artifact.ExtraWrappedIn: "./foo"})
createFakeArtifact("foo-zip", goos, goarch, "v1", "", "zip", nil) createFakeArtifact("foo-zip", goos, goarch, "v1", "", "zip", nil)
continue
} }
if goarch == "arm" { if goarch == "arm" {
if goos != "linux" { if goos != "linux" {
@ -462,12 +466,15 @@ func TestRunPipe(t *testing.T) {
} }
createFakeArtifact("foo", goos, goarch, "", "6", "tar.gz", nil) createFakeArtifact("foo", goos, goarch, "", "6", "tar.gz", nil)
createFakeArtifact("foo", goos, goarch, "", "7", "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 continue
} }
createFakeArtifact("foo", goos, goarch, "", "", "tar.gz", nil) createFakeArtifact("foo", goos, goarch, "", "", "tar.gz", nil)
createFakeArtifact("unibin", 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("wrapped-in-dir", goos, goarch, "", "", "tar.gz", map[string]any{artifact.ExtraWrappedIn: "./foo"})
createFakeArtifact("foo-zip", goos, goarch, "v1", "", "zip", nil) createFakeArtifact("foo-zip", goos, goarch, "v1", "", "zip", nil)
} }

View File

@ -20,8 +20,8 @@ let
i686-linux = "https://dummyhost/download/v1.2.1/foo_linux_386.tar.gz"; 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"; 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"; 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"; x86_64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_all.tar.gz";
aarch64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_arm64.tar.gz"; aarch64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_all.tar.gz";
}; };
in in
pkgs.stdenv.mkDerivation { pkgs.stdenv.mkDerivation {

View File

@ -12,16 +12,16 @@ let
i686-linux = "sha16"; i686-linux = "sha16";
x86_64-linux = "sha1"; x86_64-linux = "sha1";
aarch64-linux = "sha2"; aarch64-linux = "sha2";
x86_64-darwin = "sha3"; x86_64-darwin = "sha5";
aarch64-darwin = "sha4"; aarch64-darwin = "sha5";
}; };
urlMap = { urlMap = {
i686-linux = "https://dummyhost/download/v1.2.1/foo_linux_386.tar.gz"; 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"; 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"; 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"; x86_64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_all.tar.gz";
aarch64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_arm64.tar.gz"; aarch64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_all.tar.gz";
}; };
in in
pkgs.stdenv.mkDerivation { pkgs.stdenv.mkDerivation {

View File

@ -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"
];
};
}

View File

@ -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"
];
};
}