Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nix): include unzip if any artifact is a zip #4495

Merged
merged 1 commit into from Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"
];
};
}