mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-20 03:59:26 +02:00
fix(nix): sourceRoot when using archives.wrap_in_directory (#4550)
If `archives.[*].wrap_in_directory` is set, it'll create a folder inside the archive file, usually something like `app_goos_goarch`. In those cases, the root of the archive is not constant, so we create a `sourceRootMap` and use it instead. In cases where the `sourceRoot` is constant, the generated derivation will be the same. refs https://github.com/orgs/goreleaser/discussions/4549 Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
1ba3138c67
commit
1e0d269c97
@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/tmpl"
|
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||||
"github.com/goreleaser/goreleaser/pkg/config"
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
"github.com/goreleaser/goreleaser/pkg/context"
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
|
"golang.org/x/exp/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
const nixConfigExtra = "NixConfig"
|
const nixConfigExtra = "NixConfig"
|
||||||
@ -253,11 +254,6 @@ func preparePkg(
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
folder := artifact.ExtraOr(*archives[0], artifact.ExtraWrappedIn, ".")
|
|
||||||
if folder == "" {
|
|
||||||
folder = "."
|
|
||||||
}
|
|
||||||
|
|
||||||
inputs := []string{"installShellFiles"}
|
inputs := []string{"installShellFiles"}
|
||||||
dependencies := depNames(nix.Dependencies)
|
dependencies := depNames(nix.Dependencies)
|
||||||
if len(dependencies) > 0 {
|
if len(dependencies) > 0 {
|
||||||
@ -277,7 +273,7 @@ func preparePkg(
|
|||||||
Install: installs,
|
Install: installs,
|
||||||
PostInstall: postInstall,
|
PostInstall: postInstall,
|
||||||
Archives: map[string]Archive{},
|
Archives: map[string]Archive{},
|
||||||
SourceRoot: folder,
|
SourceRoots: map[string]string{},
|
||||||
Description: nix.Description,
|
Description: nix.Description,
|
||||||
Homepage: nix.Homepage,
|
Homepage: nix.Homepage,
|
||||||
License: nix.License,
|
License: nix.License,
|
||||||
@ -305,11 +301,20 @@ func preparePkg(
|
|||||||
if _, ok := data.Archives[key]; ok {
|
if _, ok := data.Archives[key]; ok {
|
||||||
return "", ErrMultipleArchivesSamePlatform
|
return "", ErrMultipleArchivesSamePlatform
|
||||||
}
|
}
|
||||||
|
folder := artifact.ExtraOr(*art, artifact.ExtraWrappedIn, ".")
|
||||||
|
if folder == "" {
|
||||||
|
folder = "."
|
||||||
|
}
|
||||||
|
data.SourceRoots[key] = folder
|
||||||
data.Archives[key] = archive
|
data.Archives[key] = archive
|
||||||
plat := goosToPlatform[art.Goos+goarch+art.Goarm]
|
plat := goosToPlatform[art.Goos+goarch+art.Goarm]
|
||||||
platforms[plat] = true
|
platforms[plat] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if roots := slices.Compact(maps.Values(data.SourceRoots)); len(roots) == 1 {
|
||||||
|
data.SourceRoot = roots[0]
|
||||||
|
}
|
||||||
data.Platforms = keys(platforms)
|
data.Platforms = keys(platforms)
|
||||||
sort.Strings(data.Platforms)
|
sort.Strings(data.Platforms)
|
||||||
|
|
||||||
|
@ -489,7 +489,7 @@ func TestRunPipe(t *testing.T) {
|
|||||||
if goos != "darwin" {
|
if goos != "darwin" {
|
||||||
createFakeArtifact("unibin-replaces", goos, goarch, "v1", "", "tar.gz", nil)
|
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_" + goarch})
|
||||||
createFakeArtifact("foo-zip", goos, goarch, "v1", "", "zip", nil)
|
createFakeArtifact("foo-zip", goos, goarch, "v1", "", "zip", nil)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -508,7 +508,7 @@ func TestRunPipe(t *testing.T) {
|
|||||||
if goos != "darwin" {
|
if goos != "darwin" {
|
||||||
createFakeArtifact("unibin-replaces", goos, goarch, "", "", "tar.gz", nil)
|
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_" + goarch})
|
||||||
createFakeArtifact("foo-zip", goos, goarch, "v1", "", "zip", nil)
|
createFakeArtifact("foo-zip", goos, goarch, "v1", "", "zip", nil)
|
||||||
if goos == "darwin" {
|
if goos == "darwin" {
|
||||||
createFakeArtifact("zip-and-tar", goos, goarch, "v1", "", "zip", nil)
|
createFakeArtifact("zip-and-tar", goos, goarch, "v1", "", "zip", nil)
|
||||||
|
@ -15,6 +15,7 @@ type templateData struct {
|
|||||||
Install []string
|
Install []string
|
||||||
PostInstall []string
|
PostInstall []string
|
||||||
SourceRoot string
|
SourceRoot string
|
||||||
|
SourceRoots map[string]string
|
||||||
Archives map[string]Archive
|
Archives map[string]Archive
|
||||||
Description string
|
Description string
|
||||||
Homepage string
|
Homepage string
|
||||||
|
@ -23,6 +23,13 @@ let
|
|||||||
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_amd64v1.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_arm64.tar.gz";
|
||||||
};
|
};
|
||||||
|
sourceRootMap = {
|
||||||
|
i686-linux = "./foo_386";
|
||||||
|
x86_64-linux = "./foo_amd64";
|
||||||
|
aarch64-linux = "./foo_arm64";
|
||||||
|
x86_64-darwin = "./foo_amd64";
|
||||||
|
aarch64-darwin = "./foo_arm64";
|
||||||
|
};
|
||||||
in
|
in
|
||||||
pkgs.stdenvNoCC.mkDerivation {
|
pkgs.stdenvNoCC.mkDerivation {
|
||||||
pname = "wrapped-in-dir";
|
pname = "wrapped-in-dir";
|
||||||
@ -32,7 +39,7 @@ pkgs.stdenvNoCC.mkDerivation {
|
|||||||
sha256 = shaMap.${system};
|
sha256 = shaMap.${system};
|
||||||
};
|
};
|
||||||
|
|
||||||
sourceRoot = "./foo";
|
sourceRoot = sourceRootMap.${system};
|
||||||
|
|
||||||
nativeBuildInputs = [ installShellFiles ];
|
nativeBuildInputs = [ installShellFiles ];
|
||||||
|
|
||||||
|
@ -23,6 +23,13 @@ let
|
|||||||
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_amd64v1.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_arm64.tar.gz";
|
||||||
};
|
};
|
||||||
|
sourceRootMap = {
|
||||||
|
i686-linux = "./foo_386";
|
||||||
|
x86_64-linux = "./foo_amd64";
|
||||||
|
aarch64-linux = "./foo_arm64";
|
||||||
|
x86_64-darwin = "./foo_amd64";
|
||||||
|
aarch64-darwin = "./foo_arm64";
|
||||||
|
};
|
||||||
in
|
in
|
||||||
pkgs.stdenvNoCC.mkDerivation {
|
pkgs.stdenvNoCC.mkDerivation {
|
||||||
pname = "wrapped-in-dir";
|
pname = "wrapped-in-dir";
|
||||||
@ -32,7 +39,7 @@ pkgs.stdenvNoCC.mkDerivation {
|
|||||||
sha256 = shaMap.${system};
|
sha256 = shaMap.${system};
|
||||||
};
|
};
|
||||||
|
|
||||||
sourceRoot = "./foo";
|
sourceRoot = sourceRootMap.${system};
|
||||||
|
|
||||||
nativeBuildInputs = [ installShellFiles ];
|
nativeBuildInputs = [ installShellFiles ];
|
||||||
|
|
||||||
|
@ -62,6 +62,32 @@ let
|
|||||||
aarch64-darwin = "{{ . }}";
|
aarch64-darwin = "{{ . }}";
|
||||||
{{- end }}
|
{{- end }}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
{{- if not .SourceRoot }}
|
||||||
|
sourceRootMap = {
|
||||||
|
{{- with .SourceRoots.linux386 }}
|
||||||
|
i686-linux = "{{ . }}";
|
||||||
|
{{- end }}
|
||||||
|
{{- with .SourceRoots.linuxamd64 }}
|
||||||
|
x86_64-linux = "{{ . }}";
|
||||||
|
{{- end }}
|
||||||
|
{{- with .SourceRoots.linuxarm6 }}
|
||||||
|
armv6l-linux = "{{ . }}";
|
||||||
|
{{- end }}
|
||||||
|
{{- with .SourceRoots.linuxarm7 }}
|
||||||
|
armv7l-linux = "{{ . }}";
|
||||||
|
{{- end }}
|
||||||
|
{{- with .SourceRoots.linuxarm64 }}
|
||||||
|
aarch64-linux = "{{ . }}";
|
||||||
|
{{- end }}
|
||||||
|
{{- with .SourceRoots.darwinamd64 }}
|
||||||
|
x86_64-darwin = "{{ . }}";
|
||||||
|
{{- end }}
|
||||||
|
{{- with .SourceRoots.darwinarm64 }}
|
||||||
|
aarch64-darwin = "{{ . }}";
|
||||||
|
{{- end }}
|
||||||
|
};
|
||||||
|
{{- end }}
|
||||||
in
|
in
|
||||||
pkgs.stdenvNoCC.mkDerivation {
|
pkgs.stdenvNoCC.mkDerivation {
|
||||||
pname = "{{ .Name }}";
|
pname = "{{ .Name }}";
|
||||||
@ -71,7 +97,7 @@ pkgs.stdenvNoCC.mkDerivation {
|
|||||||
sha256 = shaMap.${system};
|
sha256 = shaMap.${system};
|
||||||
};
|
};
|
||||||
|
|
||||||
sourceRoot = "{{ .SourceRoot }}";
|
sourceRoot = {{ with .SourceRoot }}"{{ . }}"{{ else }}sourceRootMap.${system}{{ end }};
|
||||||
|
|
||||||
nativeBuildInputs = [ {{ range $input, $plat := .Inputs }}{{ . }} {{ end }}];
|
nativeBuildInputs = [ {{ range $input, $plat := .Inputs }}{{ . }} {{ end }}];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user