Skip to content

Commit

Permalink
fix(nix): include unzip if any artifact is a zip (#4495)
Browse files Browse the repository at this point in the history
Instead of just the first one.

refs #4224
  • Loading branch information
caarlos0 committed Dec 21, 2023
1 parent c4dafdf commit 2b9e471
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 3 deletions.
9 changes: 6 additions & 3 deletions internal/pipe/nix/nix.go
Expand Up @@ -258,9 +258,12 @@ func preparePkg(
if len(dependencies) > 0 {
inputs = append(inputs, "makeWrapper")
}
if archives[0].Format() == "zip" {
inputs = append(inputs, "unzip")
dependencies = append(dependencies, "unzip")
for _, arch := range archives {
if arch.Format() == "zip" {
inputs = append(inputs, "unzip")
dependencies = append(dependencies, "unzip")
break
}
}

data := templateData{
Expand Down
19 changes: 19 additions & 0 deletions internal/pipe/nix/nix_test.go
Expand Up @@ -205,6 +205,20 @@ func TestRunPipe(t *testing.T) {
},
},
},
{
name: "zip-and-tar",
nix: config.Nix{
Name: "foozip",
IDs: []string{"zip-and-tar"},
Description: "my test",
Homepage: "https://goreleaser.com",
License: "mit",
Repository: config.RepoRef{
Owner: "foo",
Name: "bar",
},
},
},
{
name: "unibin",
expectRunErrorIs: ErrMultipleArchivesSamePlatform,
Expand Down Expand Up @@ -483,6 +497,11 @@ func TestRunPipe(t *testing.T) {
}
createFakeArtifact("wrapped-in-dir", goos, goarch, "", "", "tar.gz", map[string]any{artifact.ExtraWrappedIn: "./foo"})
createFakeArtifact("foo-zip", goos, goarch, "v1", "", "zip", nil)
if goos == "darwin" {
createFakeArtifact("zip-and-tar", goos, goarch, "v1", "", "zip", nil)
} else {
createFakeArtifact("zip-and-tar", goos, goarch, "v1", "", "tar.gz", nil)
}
}
}

Expand Down
@@ -0,0 +1,58 @@
# 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
, makeWrapper
, stdenv
, unzip
}:
let
shaMap = {
i686-linux = "0000000000000000000000000000000000000000000000000000";
aarch64-linux = "0000000000000000000000000000000000000000000000000000";
aarch64-darwin = "0000000000000000000000000000000000000000000000000000";
};

urlMap = {
i686-linux = "https://dummyhost/download/v1.2.1/foo_linux_386.tar.gz";
aarch64-linux = "https://dummyhost/download/v1.2.1/foo_linux_arm64.tar.gz";
aarch64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_arm64.zip";
};
in
pkgs.stdenv.mkDerivation {
pname = "foozip";
version = "1.2.1";
src = fetchurl {
url = urlMap.${system};
sha256 = shaMap.${system};
};

sourceRoot = ".";

nativeBuildInputs = [ installShellFiles unzip ];

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;

sourceProvenance = [ lib.sourceTypes.binaryNativeCode ];

platforms = [
"aarch64-darwin"
"aarch64-linux"
"i686-linux"
];
};
}
@@ -0,0 +1,58 @@
# 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
, makeWrapper
, stdenv
, unzip
}:
let
shaMap = {
i686-linux = "sha16";
aarch64-linux = "sha2";
aarch64-darwin = "sha11";
};

urlMap = {
i686-linux = "https://dummyhost/download/v1.2.1/foo_linux_386.tar.gz";
aarch64-linux = "https://dummyhost/download/v1.2.1/foo_linux_arm64.tar.gz";
aarch64-darwin = "https://dummyhost/download/v1.2.1/foo_darwin_arm64.zip";
};
in
pkgs.stdenv.mkDerivation {
pname = "foozip";
version = "1.2.1";
src = fetchurl {
url = urlMap.${system};
sha256 = shaMap.${system};
};

sourceRoot = ".";

nativeBuildInputs = [ installShellFiles unzip ];

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;

sourceProvenance = [ lib.sourceTypes.binaryNativeCode ];

platforms = [
"aarch64-darwin"
"aarch64-linux"
"i686-linux"
];
};
}

0 comments on commit 2b9e471

Please sign in to comment.