mirror of
https://github.com/goreleaser/goreleaser.git
synced 2024-12-31 01:53:50 +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/pkg/config"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
"golang.org/x/exp/maps"
|
||||
)
|
||||
|
||||
const nixConfigExtra = "NixConfig"
|
||||
@ -253,11 +254,6 @@ func preparePkg(
|
||||
return "", err
|
||||
}
|
||||
|
||||
folder := artifact.ExtraOr(*archives[0], artifact.ExtraWrappedIn, ".")
|
||||
if folder == "" {
|
||||
folder = "."
|
||||
}
|
||||
|
||||
inputs := []string{"installShellFiles"}
|
||||
dependencies := depNames(nix.Dependencies)
|
||||
if len(dependencies) > 0 {
|
||||
@ -277,7 +273,7 @@ func preparePkg(
|
||||
Install: installs,
|
||||
PostInstall: postInstall,
|
||||
Archives: map[string]Archive{},
|
||||
SourceRoot: folder,
|
||||
SourceRoots: map[string]string{},
|
||||
Description: nix.Description,
|
||||
Homepage: nix.Homepage,
|
||||
License: nix.License,
|
||||
@ -305,11 +301,20 @@ func preparePkg(
|
||||
if _, ok := data.Archives[key]; ok {
|
||||
return "", ErrMultipleArchivesSamePlatform
|
||||
}
|
||||
folder := artifact.ExtraOr(*art, artifact.ExtraWrappedIn, ".")
|
||||
if folder == "" {
|
||||
folder = "."
|
||||
}
|
||||
data.SourceRoots[key] = folder
|
||||
data.Archives[key] = archive
|
||||
plat := goosToPlatform[art.Goos+goarch+art.Goarm]
|
||||
platforms[plat] = true
|
||||
}
|
||||
}
|
||||
|
||||
if roots := slices.Compact(maps.Values(data.SourceRoots)); len(roots) == 1 {
|
||||
data.SourceRoot = roots[0]
|
||||
}
|
||||
data.Platforms = keys(platforms)
|
||||
sort.Strings(data.Platforms)
|
||||
|
||||
|
@ -489,7 +489,7 @@ func TestRunPipe(t *testing.T) {
|
||||
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_" + goarch})
|
||||
createFakeArtifact("foo-zip", goos, goarch, "v1", "", "zip", nil)
|
||||
continue
|
||||
}
|
||||
@ -508,7 +508,7 @@ func TestRunPipe(t *testing.T) {
|
||||
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_" + goarch})
|
||||
createFakeArtifact("foo-zip", goos, goarch, "v1", "", "zip", nil)
|
||||
if goos == "darwin" {
|
||||
createFakeArtifact("zip-and-tar", goos, goarch, "v1", "", "zip", nil)
|
||||
|
@ -15,6 +15,7 @@ type templateData struct {
|
||||
Install []string
|
||||
PostInstall []string
|
||||
SourceRoot string
|
||||
SourceRoots map[string]string
|
||||
Archives map[string]Archive
|
||||
Description string
|
||||
Homepage string
|
||||
|
@ -23,6 +23,13 @@ let
|
||||
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";
|
||||
};
|
||||
sourceRootMap = {
|
||||
i686-linux = "./foo_386";
|
||||
x86_64-linux = "./foo_amd64";
|
||||
aarch64-linux = "./foo_arm64";
|
||||
x86_64-darwin = "./foo_amd64";
|
||||
aarch64-darwin = "./foo_arm64";
|
||||
};
|
||||
in
|
||||
pkgs.stdenvNoCC.mkDerivation {
|
||||
pname = "wrapped-in-dir";
|
||||
@ -32,7 +39,7 @@ pkgs.stdenvNoCC.mkDerivation {
|
||||
sha256 = shaMap.${system};
|
||||
};
|
||||
|
||||
sourceRoot = "./foo";
|
||||
sourceRoot = sourceRootMap.${system};
|
||||
|
||||
nativeBuildInputs = [ installShellFiles ];
|
||||
|
||||
|
@ -23,6 +23,13 @@ let
|
||||
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";
|
||||
};
|
||||
sourceRootMap = {
|
||||
i686-linux = "./foo_386";
|
||||
x86_64-linux = "./foo_amd64";
|
||||
aarch64-linux = "./foo_arm64";
|
||||
x86_64-darwin = "./foo_amd64";
|
||||
aarch64-darwin = "./foo_arm64";
|
||||
};
|
||||
in
|
||||
pkgs.stdenvNoCC.mkDerivation {
|
||||
pname = "wrapped-in-dir";
|
||||
@ -32,7 +39,7 @@ pkgs.stdenvNoCC.mkDerivation {
|
||||
sha256 = shaMap.${system};
|
||||
};
|
||||
|
||||
sourceRoot = "./foo";
|
||||
sourceRoot = sourceRootMap.${system};
|
||||
|
||||
nativeBuildInputs = [ installShellFiles ];
|
||||
|
||||
|
@ -62,6 +62,32 @@ let
|
||||
aarch64-darwin = "{{ . }}";
|
||||
{{- 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
|
||||
pkgs.stdenvNoCC.mkDerivation {
|
||||
pname = "{{ .Name }}";
|
||||
@ -71,7 +97,7 @@ pkgs.stdenvNoCC.mkDerivation {
|
||||
sha256 = shaMap.${system};
|
||||
};
|
||||
|
||||
sourceRoot = "{{ .SourceRoot }}";
|
||||
sourceRoot = {{ with .SourceRoot }}"{{ . }}"{{ else }}sourceRootMap.${system}{{ end }};
|
||||
|
||||
nativeBuildInputs = [ {{ range $input, $plat := .Inputs }}{{ . }} {{ end }}];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user