From 2b9e471370e488fa497f565df8c9fa8b4fbfaa51 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Thu, 21 Dec 2023 14:21:20 -0300 Subject: [PATCH] fix(nix): include unzip if any artifact is a zip (#4495) Instead of just the first one. refs #4224 --- internal/pipe/nix/nix.go | 9 ++- internal/pipe/nix/nix_test.go | 19 ++++++ .../TestRunPipe/zip-and-tar_build.nix.golden | 58 +++++++++++++++++++ .../zip-and-tar_publish.nix.golden | 58 +++++++++++++++++++ 4 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 internal/pipe/nix/testdata/TestRunPipe/zip-and-tar_build.nix.golden create mode 100644 internal/pipe/nix/testdata/TestRunPipe/zip-and-tar_publish.nix.golden diff --git a/internal/pipe/nix/nix.go b/internal/pipe/nix/nix.go index e546f09cdf3..9d0a2ec732d 100644 --- a/internal/pipe/nix/nix.go +++ b/internal/pipe/nix/nix.go @@ -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{ diff --git a/internal/pipe/nix/nix_test.go b/internal/pipe/nix/nix_test.go index 977468bd5ab..76da25f65b0 100644 --- a/internal/pipe/nix/nix_test.go +++ b/internal/pipe/nix/nix_test.go @@ -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, @@ -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) + } } } diff --git a/internal/pipe/nix/testdata/TestRunPipe/zip-and-tar_build.nix.golden b/internal/pipe/nix/testdata/TestRunPipe/zip-and-tar_build.nix.golden new file mode 100644 index 00000000000..07c22003485 --- /dev/null +++ b/internal/pipe/nix/testdata/TestRunPipe/zip-and-tar_build.nix.golden @@ -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" + ]; + }; +} diff --git a/internal/pipe/nix/testdata/TestRunPipe/zip-and-tar_publish.nix.golden b/internal/pipe/nix/testdata/TestRunPipe/zip-and-tar_publish.nix.golden new file mode 100644 index 00000000000..d4998cc40dc --- /dev/null +++ b/internal/pipe/nix/testdata/TestRunPipe/zip-and-tar_publish.nix.golden @@ -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" + ]; + }; +}