You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-11-06 09:09:29 +02:00
feat: improve universal binaries on krew/brew/gofish (#2747)
* feat: improve universal binaries on krew/brew/gofish Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * test: OnlyReplacingUnibins Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: archive Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: do not replace single-arch Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
committed by
GitHub
parent
87a1ac21d7
commit
e8c8a2832f
@@ -34,7 +34,7 @@ builds:
|
|||||||
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{ .CommitDate }} -X main.builtBy=goreleaser
|
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{ .CommitDate }} -X main.builtBy=goreleaser
|
||||||
|
|
||||||
universal_binaries:
|
universal_binaries:
|
||||||
- replace: true
|
- replace: false
|
||||||
|
|
||||||
checksum:
|
checksum:
|
||||||
name_template: 'checksums.txt'
|
name_template: 'checksums.txt'
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ const (
|
|||||||
ExtraWrappedIn = "WrappedIn"
|
ExtraWrappedIn = "WrappedIn"
|
||||||
ExtraBinaries = "Binaries"
|
ExtraBinaries = "Binaries"
|
||||||
ExtraRefresh = "Refresh"
|
ExtraRefresh = "Refresh"
|
||||||
|
ExtraReplaces = "Replaces"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Extras represents the extra fields in an artifact.
|
// Extras represents the extra fields in an artifact.
|
||||||
@@ -143,6 +144,10 @@ type Artifact struct {
|
|||||||
Extra Extras `json:"extra,omitempty"`
|
Extra Extras `json:"extra,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a Artifact) String() string {
|
||||||
|
return a.Name
|
||||||
|
}
|
||||||
|
|
||||||
// ExtraOr returns the Extra field with the given key or the or value specified
|
// ExtraOr returns the Extra field with the given key or the or value specified
|
||||||
// if it is nil.
|
// if it is nil.
|
||||||
func (a Artifact) ExtraOr(key string, or interface{}) interface{} {
|
func (a Artifact) ExtraOr(key string, or interface{}) interface{} {
|
||||||
@@ -287,6 +292,13 @@ func (artifacts *Artifacts) Remove(filter Filter) error {
|
|||||||
// function.
|
// function.
|
||||||
type Filter func(a *Artifact) bool
|
type Filter func(a *Artifact) bool
|
||||||
|
|
||||||
|
// OnlyReplacingUnibins removes universal binaries that did not replace the single-arch ones.
|
||||||
|
//
|
||||||
|
// This is useful specially on homebrew et al, where you'll want to use only either the single-arch or the universal binaries.
|
||||||
|
func OnlyReplacingUnibins(a *Artifact) bool {
|
||||||
|
return a.ExtraOr(ExtraReplaces, true).(bool)
|
||||||
|
}
|
||||||
|
|
||||||
// ByGoos is a predefined filter that filters by the given goos.
|
// ByGoos is a predefined filter that filters by the given goos.
|
||||||
func ByGoos(s string) Filter {
|
func ByGoos(s string) Filter {
|
||||||
return func(a *Artifact) bool {
|
return func(a *Artifact) bool {
|
||||||
|
|||||||
@@ -69,6 +69,22 @@ func TestFilter(t *testing.T) {
|
|||||||
Name: "checkzumm",
|
Name: "checkzumm",
|
||||||
Type: Checksum,
|
Type: Checksum,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "unibin-replaces",
|
||||||
|
Goos: "darwin",
|
||||||
|
Goarch: "all",
|
||||||
|
Extra: map[string]interface{}{
|
||||||
|
ExtraReplaces: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "unibin-noreplace",
|
||||||
|
Goos: "darwin",
|
||||||
|
Goarch: "all",
|
||||||
|
Extra: map[string]interface{}{
|
||||||
|
ExtraReplaces: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
artifacts := New()
|
artifacts := New()
|
||||||
for _, a := range data {
|
for _, a := range data {
|
||||||
@@ -76,7 +92,7 @@ func TestFilter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
require.Len(t, artifacts.Filter(ByGoos("linux")).items, 1)
|
require.Len(t, artifacts.Filter(ByGoos("linux")).items, 1)
|
||||||
require.Len(t, artifacts.Filter(ByGoos("darwin")).items, 0)
|
require.Len(t, artifacts.Filter(ByGoos("darwin")).items, 2)
|
||||||
|
|
||||||
require.Len(t, artifacts.Filter(ByGoarch("amd64")).items, 1)
|
require.Len(t, artifacts.Filter(ByGoarch("amd64")).items, 1)
|
||||||
require.Len(t, artifacts.Filter(ByGoarch("386")).items, 0)
|
require.Len(t, artifacts.Filter(ByGoarch("386")).items, 0)
|
||||||
@@ -87,7 +103,10 @@ func TestFilter(t *testing.T) {
|
|||||||
require.Len(t, artifacts.Filter(ByType(Checksum)).items, 2)
|
require.Len(t, artifacts.Filter(ByType(Checksum)).items, 2)
|
||||||
require.Len(t, artifacts.Filter(ByType(Binary)).items, 0)
|
require.Len(t, artifacts.Filter(ByType(Binary)).items, 0)
|
||||||
|
|
||||||
require.Len(t, artifacts.Filter(nil).items, 5)
|
require.Len(t, artifacts.Filter(OnlyReplacingUnibins).items, 6)
|
||||||
|
require.Len(t, artifacts.Filter(And(OnlyReplacingUnibins, ByGoos("darwin"))).items, 1)
|
||||||
|
|
||||||
|
require.Len(t, artifacts.Filter(nil).items, 7)
|
||||||
|
|
||||||
require.Len(t, artifacts.Filter(
|
require.Len(t, artifacts.Filter(
|
||||||
And(
|
And(
|
||||||
|
|||||||
@@ -198,6 +198,7 @@ func create(ctx *context.Context, arch config.Archive, binaries []*artifact.Arti
|
|||||||
artifact.ExtraFormat: arch.Format,
|
artifact.ExtraFormat: arch.Format,
|
||||||
artifact.ExtraWrappedIn: wrap,
|
artifact.ExtraWrappedIn: wrap,
|
||||||
artifact.ExtraBinaries: bins,
|
artifact.ExtraBinaries: bins,
|
||||||
|
artifact.ExtraReplaces: binaries[0].Extra[artifact.ExtraReplaces],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
@@ -235,10 +236,11 @@ func skip(ctx *context.Context, archive config.Archive, binaries []*artifact.Art
|
|||||||
Goarm: binary.Goarm,
|
Goarm: binary.Goarm,
|
||||||
Gomips: binary.Gomips,
|
Gomips: binary.Gomips,
|
||||||
Extra: map[string]interface{}{
|
Extra: map[string]interface{}{
|
||||||
artifact.ExtraBuilds: []*artifact.Artifact{binary},
|
artifact.ExtraBuilds: []*artifact.Artifact{binary},
|
||||||
artifact.ExtraID: archive.ID,
|
artifact.ExtraID: archive.ID,
|
||||||
artifact.ExtraFormat: archive.Format,
|
artifact.ExtraFormat: archive.Format,
|
||||||
artifact.ExtraBinary: binary.Name,
|
artifact.ExtraBinary: binary.Name,
|
||||||
|
artifact.ExtraReplaces: binaries[0].Extra[artifact.ExtraReplaces],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,10 +80,11 @@ func TestRunPipe(t *testing.T) {
|
|||||||
Goarch: "all",
|
Goarch: "all",
|
||||||
Name: "bin/mybin",
|
Name: "bin/mybin",
|
||||||
Path: filepath.Join(dist, "darwinall", "bin", "mybin"),
|
Path: filepath.Join(dist, "darwinall", "bin", "mybin"),
|
||||||
Type: artifact.Binary,
|
Type: artifact.UniversalBinary,
|
||||||
Extra: map[string]interface{}{
|
Extra: map[string]interface{}{
|
||||||
artifact.ExtraBinary: "bin/mybin",
|
artifact.ExtraBinary: "bin/mybin",
|
||||||
artifact.ExtraID: "default",
|
artifact.ExtraID: "default",
|
||||||
|
artifact.ExtraReplaces: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
darwinBuild := &artifact.Artifact{
|
darwinBuild := &artifact.Artifact{
|
||||||
@@ -368,10 +369,11 @@ func TestRunPipeBinary(t *testing.T) {
|
|||||||
Goarch: "all",
|
Goarch: "all",
|
||||||
Name: "myunibin",
|
Name: "myunibin",
|
||||||
Path: filepath.Join(dist, "darwinamd64", "mybin"),
|
Path: filepath.Join(dist, "darwinamd64", "mybin"),
|
||||||
Type: artifact.Binary,
|
Type: artifact.UniversalBinary,
|
||||||
Extra: map[string]interface{}{
|
Extra: map[string]interface{}{
|
||||||
artifact.ExtraBinary: "myunibin",
|
artifact.ExtraBinary: "myunibin",
|
||||||
artifact.ExtraID: "default",
|
artifact.ExtraID: "default",
|
||||||
|
artifact.ExtraReplaces: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
ctx.Artifacts.Add(&artifact.Artifact{
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
@@ -397,6 +399,7 @@ func TestRunPipeBinary(t *testing.T) {
|
|||||||
artifact.ByGoos("darwin"),
|
artifact.ByGoos("darwin"),
|
||||||
artifact.ByGoarch("all"),
|
artifact.ByGoarch("all"),
|
||||||
)).List()[0]
|
)).List()[0]
|
||||||
|
require.True(t, darwinUniversal.ExtraOr(artifact.ExtraReplaces, false).(bool))
|
||||||
windows := binaries.Filter(artifact.ByGoos("windows")).List()[0]
|
windows := binaries.Filter(artifact.ByGoos("windows")).List()[0]
|
||||||
require.Equal(t, "mybin_0.0.1_darwin_amd64", darwinThin.Name)
|
require.Equal(t, "mybin_0.0.1_darwin_amd64", darwinThin.Name)
|
||||||
require.Equal(t, "mybin", darwinThin.ExtraOr(artifact.ExtraBinary, ""))
|
require.Equal(t, "mybin", darwinThin.ExtraOr(artifact.ExtraBinary, ""))
|
||||||
|
|||||||
@@ -170,6 +170,7 @@ func doRun(ctx *context.Context, brew config.Homebrew, cl client.Client) error {
|
|||||||
),
|
),
|
||||||
artifact.ByType(artifact.UploadableBinary),
|
artifact.ByType(artifact.UploadableBinary),
|
||||||
),
|
),
|
||||||
|
artifact.OnlyReplacingUnibins,
|
||||||
}
|
}
|
||||||
if len(brew.IDs) > 0 {
|
if len(brew.IDs) > 0 {
|
||||||
filters = append(filters, artifact.ByIDs(brew.IDs...))
|
filters = append(filters, artifact.ByIDs(brew.IDs...))
|
||||||
|
|||||||
@@ -1040,6 +1040,87 @@ func TestRunPipeUniversalBinary(t *testing.T) {
|
|||||||
artifact.ExtraID: "unibin",
|
artifact.ExtraID: "unibin",
|
||||||
artifact.ExtraFormat: "tar.gz",
|
artifact.ExtraFormat: "tar.gz",
|
||||||
artifact.ExtraBinaries: []string{"unibin"},
|
artifact.ExtraBinaries: []string{"unibin"},
|
||||||
|
artifact.ExtraReplaces: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
f, err := os.Create(path)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NoError(t, f.Close())
|
||||||
|
client := client.NewMock()
|
||||||
|
distFile := filepath.Join(folder, "unibin.rb")
|
||||||
|
|
||||||
|
require.NoError(t, runAll(ctx, client))
|
||||||
|
require.NoError(t, publishAll(ctx, client))
|
||||||
|
require.True(t, client.CreatedFile)
|
||||||
|
golden.RequireEqualRb(t, []byte(client.Content))
|
||||||
|
distBts, err := os.ReadFile(distFile)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, client.Content, string(distBts))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRunPipeUniversalBinaryNotReplacing(t *testing.T) {
|
||||||
|
folder := t.TempDir()
|
||||||
|
ctx := &context.Context{
|
||||||
|
Git: context.GitInfo{
|
||||||
|
CurrentTag: "v1.0.1",
|
||||||
|
},
|
||||||
|
Version: "1.0.1",
|
||||||
|
Artifacts: artifact.New(),
|
||||||
|
Config: config.Project{
|
||||||
|
Dist: folder,
|
||||||
|
ProjectName: "unibin",
|
||||||
|
Brews: []config.Homebrew{
|
||||||
|
{
|
||||||
|
Name: "unibin",
|
||||||
|
Tap: config.RepoRef{
|
||||||
|
Owner: "unibin",
|
||||||
|
Name: "bar",
|
||||||
|
},
|
||||||
|
IDs: []string{
|
||||||
|
"unibin",
|
||||||
|
},
|
||||||
|
Install: `bin.install "unibin"`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
path := filepath.Join(folder, "bin.tar.gz")
|
||||||
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
|
Name: "bin_amd64.tar.gz",
|
||||||
|
Path: path,
|
||||||
|
Goos: "darwin",
|
||||||
|
Goarch: "amd64",
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
Extra: map[string]interface{}{
|
||||||
|
artifact.ExtraID: "unibin",
|
||||||
|
artifact.ExtraFormat: "tar.gz",
|
||||||
|
artifact.ExtraBinaries: []string{"unibin"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
|
Name: "bin_arm64.tar.gz",
|
||||||
|
Path: path,
|
||||||
|
Goos: "darwin",
|
||||||
|
Goarch: "arm64",
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
Extra: map[string]interface{}{
|
||||||
|
artifact.ExtraID: "unibin",
|
||||||
|
artifact.ExtraFormat: "tar.gz",
|
||||||
|
artifact.ExtraBinaries: []string{"unibin"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
|
Name: "bin.tar.gz",
|
||||||
|
Path: path,
|
||||||
|
Goos: "darwin",
|
||||||
|
Goarch: "all",
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
Extra: map[string]interface{}{
|
||||||
|
artifact.ExtraID: "unibin",
|
||||||
|
artifact.ExtraFormat: "tar.gz",
|
||||||
|
artifact.ExtraBinaries: []string{"unibin"},
|
||||||
|
artifact.ExtraReplaces: false,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
29
internal/pipe/brew/testdata/TestRunPipeUniversalBinaryNotReplacing.rb.golden
vendored
Normal file
29
internal/pipe/brew/testdata/TestRunPipeUniversalBinaryNotReplacing.rb.golden
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# typed: false
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# This file was generated by GoReleaser. DO NOT EDIT.
|
||||||
|
class Unibin < Formula
|
||||||
|
desc ""
|
||||||
|
homepage ""
|
||||||
|
version "1.0.1"
|
||||||
|
depends_on :macos
|
||||||
|
|
||||||
|
on_macos do
|
||||||
|
if Hardware::CPU.intel?
|
||||||
|
url "https://dummyhost/download/v1.0.1/bin_amd64.tar.gz"
|
||||||
|
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||||
|
|
||||||
|
def install
|
||||||
|
bin.install "unibin"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if Hardware::CPU.arm?
|
||||||
|
url "https://dummyhost/download/v1.0.1/bin_arm64.tar.gz"
|
||||||
|
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||||
|
|
||||||
|
def install
|
||||||
|
bin.install "unibin"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -100,6 +100,7 @@ func doRun(ctx *context.Context, goFish config.GoFish, cl client.Client) error {
|
|||||||
artifact.ByType(artifact.UploadableArchive),
|
artifact.ByType(artifact.UploadableArchive),
|
||||||
artifact.ByType(artifact.UploadableBinary),
|
artifact.ByType(artifact.UploadableBinary),
|
||||||
),
|
),
|
||||||
|
artifact.OnlyReplacingUnibins,
|
||||||
}
|
}
|
||||||
if len(goFish.IDs) > 0 {
|
if len(goFish.IDs) > 0 {
|
||||||
filters = append(filters, artifact.ByIDs(goFish.IDs...))
|
filters = append(filters, artifact.ByIDs(goFish.IDs...))
|
||||||
|
|||||||
@@ -277,6 +277,86 @@ func TestRunPipeUniversalBinary(t *testing.T) {
|
|||||||
artifact.ExtraID: "unibin",
|
artifact.ExtraID: "unibin",
|
||||||
artifact.ExtraFormat: "tar.gz",
|
artifact.ExtraFormat: "tar.gz",
|
||||||
artifact.ExtraBinaries: []string{"unibin"},
|
artifact.ExtraBinaries: []string{"unibin"},
|
||||||
|
artifact.ExtraReplaces: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
f, err := os.Create(path)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NoError(t, f.Close())
|
||||||
|
client := client.NewMock()
|
||||||
|
distFile := filepath.Join(folder, "unibin.lua")
|
||||||
|
|
||||||
|
require.NoError(t, runAll(ctx, client))
|
||||||
|
require.NoError(t, publishAll(ctx, client))
|
||||||
|
require.True(t, client.CreatedFile)
|
||||||
|
golden.RequireEqualLua(t, []byte(client.Content))
|
||||||
|
distBts, err := os.ReadFile(distFile)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, client.Content, string(distBts))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRunPipeUniversalBinaryNotReplacing(t *testing.T) {
|
||||||
|
folder := t.TempDir()
|
||||||
|
ctx := &context.Context{
|
||||||
|
Git: context.GitInfo{
|
||||||
|
CurrentTag: "v1.0.1",
|
||||||
|
},
|
||||||
|
Version: "1.0.1",
|
||||||
|
Artifacts: artifact.New(),
|
||||||
|
Config: config.Project{
|
||||||
|
Dist: folder,
|
||||||
|
ProjectName: "unibin",
|
||||||
|
Rigs: []config.GoFish{
|
||||||
|
{
|
||||||
|
Name: "unibin",
|
||||||
|
Rig: config.RepoRef{
|
||||||
|
Owner: "unibin",
|
||||||
|
Name: "bar",
|
||||||
|
},
|
||||||
|
IDs: []string{
|
||||||
|
"unibin",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
path := filepath.Join(folder, "bin.tar.gz")
|
||||||
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
|
Name: "unibin_amd64.tar.gz",
|
||||||
|
Path: path,
|
||||||
|
Goos: "darwin",
|
||||||
|
Goarch: "amd64",
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
Extra: map[string]interface{}{
|
||||||
|
artifact.ExtraID: "unibin",
|
||||||
|
artifact.ExtraFormat: "tar.gz",
|
||||||
|
artifact.ExtraBinaries: []string{"unibin"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
|
Name: "unibin_arm64.tar.gz",
|
||||||
|
Path: path,
|
||||||
|
Goos: "darwin",
|
||||||
|
Goarch: "arm64",
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
Extra: map[string]interface{}{
|
||||||
|
artifact.ExtraID: "unibin",
|
||||||
|
artifact.ExtraFormat: "tar.gz",
|
||||||
|
artifact.ExtraBinaries: []string{"unibin"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
|
Name: "unibin.tar.gz",
|
||||||
|
Path: path,
|
||||||
|
Goos: "darwin",
|
||||||
|
Goarch: "all",
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
Extra: map[string]interface{}{
|
||||||
|
artifact.ExtraID: "unibin",
|
||||||
|
artifact.ExtraFormat: "tar.gz",
|
||||||
|
artifact.ExtraBinaries: []string{"unibin"},
|
||||||
|
artifact.ExtraReplaces: false,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
38
internal/pipe/gofish/testdata/TestRunPipeUniversalBinaryNotReplacing.lua.golden
vendored
Normal file
38
internal/pipe/gofish/testdata/TestRunPipeUniversalBinaryNotReplacing.lua.golden
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
local name = "unibin"
|
||||||
|
local version = "1.0.1"
|
||||||
|
|
||||||
|
food = {
|
||||||
|
name = name,
|
||||||
|
description = "",
|
||||||
|
license = "",
|
||||||
|
homepage = "",
|
||||||
|
version = version,
|
||||||
|
packages = {
|
||||||
|
{
|
||||||
|
os = "darwin",
|
||||||
|
arch = "amd64",
|
||||||
|
url = "https://dummyhost/download/v1.0.1/unibin_amd64.tar.gz",
|
||||||
|
sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
||||||
|
resources = {
|
||||||
|
{
|
||||||
|
path = "unibin",
|
||||||
|
installpath = "bin/unibin",
|
||||||
|
executable = true
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
os = "darwin",
|
||||||
|
arch = "arm64",
|
||||||
|
url = "https://dummyhost/download/v1.0.1/unibin_arm64.tar.gz",
|
||||||
|
sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
||||||
|
resources = {
|
||||||
|
{
|
||||||
|
path = "unibin",
|
||||||
|
installpath = "bin/unibin",
|
||||||
|
executable = true
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -105,6 +105,7 @@ func doRun(ctx *context.Context, krew config.Krew, cl client.Client) error {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
artifact.ByType(artifact.UploadableArchive),
|
artifact.ByType(artifact.UploadableArchive),
|
||||||
|
artifact.OnlyReplacingUnibins,
|
||||||
}
|
}
|
||||||
if len(krew.IDs) > 0 {
|
if len(krew.IDs) > 0 {
|
||||||
filters = append(filters, artifact.ByIDs(krew.IDs...))
|
filters = append(filters, artifact.ByIDs(krew.IDs...))
|
||||||
|
|||||||
@@ -336,6 +336,89 @@ func TestRunPipeUniversalBinary(t *testing.T) {
|
|||||||
artifact.ExtraID: "unibin",
|
artifact.ExtraID: "unibin",
|
||||||
artifact.ExtraFormat: "tar.gz",
|
artifact.ExtraFormat: "tar.gz",
|
||||||
artifact.ExtraBinaries: []string{"unibin"},
|
artifact.ExtraBinaries: []string{"unibin"},
|
||||||
|
artifact.ExtraReplaces: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
f, err := os.Create(path)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NoError(t, f.Close())
|
||||||
|
client := client.NewMock()
|
||||||
|
distFile := filepath.Join(folder, manifestName(t)+".yaml")
|
||||||
|
|
||||||
|
require.NoError(t, runAll(ctx, client))
|
||||||
|
require.NoError(t, publishAll(ctx, client))
|
||||||
|
require.True(t, client.CreatedFile)
|
||||||
|
golden.RequireEqualNakedYaml(t, []byte(client.Content))
|
||||||
|
requireValidManifest(t)
|
||||||
|
distBts, err := os.ReadFile(distFile)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, client.Content, string(distBts))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRunPipeUniversalBinaryNotReplacing(t *testing.T) {
|
||||||
|
folder := t.TempDir()
|
||||||
|
ctx := &context.Context{
|
||||||
|
Git: context.GitInfo{
|
||||||
|
CurrentTag: "v1.0.1",
|
||||||
|
},
|
||||||
|
Version: "1.0.1",
|
||||||
|
Artifacts: artifact.New(),
|
||||||
|
Config: config.Project{
|
||||||
|
Dist: folder,
|
||||||
|
ProjectName: "unibin",
|
||||||
|
Krews: []config.Krew{
|
||||||
|
{
|
||||||
|
Name: manifestName(t),
|
||||||
|
Description: "Some desc",
|
||||||
|
ShortDescription: "Short desc",
|
||||||
|
Index: config.RepoRef{
|
||||||
|
Owner: "unibin",
|
||||||
|
Name: "bar",
|
||||||
|
},
|
||||||
|
IDs: []string{
|
||||||
|
"unibin",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
path := filepath.Join(folder, "bin.tar.gz")
|
||||||
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
|
Name: "unibin_amd64.tar.gz",
|
||||||
|
Path: path,
|
||||||
|
Goos: "darwin",
|
||||||
|
Goarch: "amd64",
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
Extra: map[string]interface{}{
|
||||||
|
artifact.ExtraID: "unibin",
|
||||||
|
artifact.ExtraFormat: "tar.gz",
|
||||||
|
artifact.ExtraBinaries: []string{"unibin"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
|
Name: "unibin_amd64.tar.gz",
|
||||||
|
Path: path,
|
||||||
|
Goos: "darwin",
|
||||||
|
Goarch: "arm64",
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
Extra: map[string]interface{}{
|
||||||
|
artifact.ExtraID: "unibin",
|
||||||
|
artifact.ExtraFormat: "tar.gz",
|
||||||
|
artifact.ExtraBinaries: []string{"unibin"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
|
Name: "unibin.tar.gz",
|
||||||
|
Path: path,
|
||||||
|
Goos: "darwin",
|
||||||
|
Goarch: "all",
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
Extra: map[string]interface{}{
|
||||||
|
artifact.ExtraID: "unibin",
|
||||||
|
artifact.ExtraFormat: "tar.gz",
|
||||||
|
artifact.ExtraBinaries: []string{"unibin"},
|
||||||
|
artifact.ExtraReplaces: false,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
23
internal/pipe/krew/testdata/TestRunPipeUniversalBinaryNotReplacing.yaml
vendored
Normal file
23
internal/pipe/krew/testdata/TestRunPipeUniversalBinaryNotReplacing.yaml
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
apiVersion: krew.googlecontainertools.github.com/v1alpha2
|
||||||
|
kind: Plugin
|
||||||
|
metadata:
|
||||||
|
name: TestRunPipeUniversalBinaryNotReplacing
|
||||||
|
spec:
|
||||||
|
version: v1.0.1
|
||||||
|
platforms:
|
||||||
|
- bin: unibin
|
||||||
|
uri: https://dummyhost/download/v1.0.1/unibin_amd64.tar.gz
|
||||||
|
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: darwin
|
||||||
|
arch: amd64
|
||||||
|
- bin: unibin
|
||||||
|
uri: https://dummyhost/download/v1.0.1/unibin_amd64.tar.gz
|
||||||
|
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: darwin
|
||||||
|
arch: arm64
|
||||||
|
shortDescription: Short desc
|
||||||
|
description: Some desc
|
||||||
@@ -206,13 +206,19 @@ func makeUniversalBinary(ctx *context.Context, unibin config.UniversalBinary) er
|
|||||||
return fmt.Errorf("failed to close file: %w", err)
|
return fmt.Errorf("failed to close file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extra := map[string]interface{}{}
|
||||||
|
for k, v := range binaries[0].Extra {
|
||||||
|
extra[k] = v
|
||||||
|
}
|
||||||
|
extra[artifact.ExtraReplaces] = unibin.Replace
|
||||||
|
|
||||||
ctx.Artifacts.Add(&artifact.Artifact{
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
Type: artifact.UniversalBinary,
|
Type: artifact.UniversalBinary,
|
||||||
Name: name,
|
Name: name,
|
||||||
Path: path,
|
Path: path,
|
||||||
Goos: "darwin",
|
Goos: "darwin",
|
||||||
Goarch: "all",
|
Goarch: "all",
|
||||||
Extra: binaries[0].Extra,
|
Extra: extra,
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -206,15 +206,19 @@ func TestRun(t *testing.T) {
|
|||||||
t.Run("replacing", func(t *testing.T) {
|
t.Run("replacing", func(t *testing.T) {
|
||||||
require.NoError(t, Pipe{}.Run(ctx1))
|
require.NoError(t, Pipe{}.Run(ctx1))
|
||||||
require.Len(t, ctx1.Artifacts.Filter(artifact.ByType(artifact.Binary)).List(), 0)
|
require.Len(t, ctx1.Artifacts.Filter(artifact.ByType(artifact.Binary)).List(), 0)
|
||||||
require.Len(t, ctx1.Artifacts.Filter(artifact.ByType(artifact.UniversalBinary)).List(), 1)
|
unis := ctx1.Artifacts.Filter(artifact.ByType(artifact.UniversalBinary)).List()
|
||||||
checkUniversalBinary(t, ctx1.Artifacts.Filter(artifact.ByType(artifact.UniversalBinary)).List()[0])
|
require.Len(t, unis, 1)
|
||||||
|
checkUniversalBinary(t, unis[0])
|
||||||
|
require.True(t, unis[0].Extra[artifact.ExtraReplaces].(bool))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("keeping", func(t *testing.T) {
|
t.Run("keeping", func(t *testing.T) {
|
||||||
require.NoError(t, Pipe{}.Run(ctx2))
|
require.NoError(t, Pipe{}.Run(ctx2))
|
||||||
require.Len(t, ctx2.Artifacts.Filter(artifact.ByType(artifact.Binary)).List(), 2)
|
require.Len(t, ctx2.Artifacts.Filter(artifact.ByType(artifact.Binary)).List(), 2)
|
||||||
require.Len(t, ctx2.Artifacts.Filter(artifact.ByType(artifact.UniversalBinary)).List(), 1)
|
unis := ctx2.Artifacts.Filter(artifact.ByType(artifact.UniversalBinary)).List()
|
||||||
checkUniversalBinary(t, ctx2.Artifacts.Filter(artifact.ByType(artifact.UniversalBinary)).List()[0])
|
require.Len(t, unis, 1)
|
||||||
|
checkUniversalBinary(t, unis[0])
|
||||||
|
require.False(t, unis[0].Extra[artifact.ExtraReplaces].(bool))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("bad template", func(t *testing.T) {
|
t.Run("bad template", func(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user