1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-05 13:15:26 +02:00

fix: standardize .Ext to always have the preceding . (#5207)

historically this is kind of a mess, some places set the prefixed ext
(e.g. `.exe`) others don't (e.g. `msi`)

this standardize it to have the preceding `.`

also makes `ByExt` works with or without it so it doesn't break anyone's
config.

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2024-10-15 14:57:27 -03:00 committed by GitHub
parent 5d62156ed1
commit 24c6060050
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 40 additions and 36 deletions

View File

@ -152,7 +152,7 @@ func (t Type) String() string {
const (
ExtraID = "ID"
ExtraBinary = "Binary"
ExtraExt = "Ext"
ExtraExt = "Ext" // should always have the preceding '.'
ExtraFormat = "Format"
ExtraWrappedIn = "WrappedIn"
ExtraBinaries = "Binaries"
@ -512,11 +512,15 @@ func ByIDs(ids ...string) Filter {
}
// ByExt filter artifact by their 'Ext' extra field.
//
// The comp is done ignoring the preceding '.', so `ByExt("deb")` and
// `ByExt(".deb")` have the same result.
func ByExt(exts ...string) Filter {
filters := make([]Filter, 0, len(exts))
for _, ext := range exts {
filters = append(filters, func(a *Artifact) bool {
return ExtraOr(*a, ExtraExt, "") == ext
actual := ExtraOr(*a, ExtraExt, "")
return strings.TrimPrefix(actual, ".") == strings.TrimPrefix(ext, ".")
})
}
return Or(filters...)

View File

@ -477,7 +477,7 @@ func TestByExts(t *testing.T) {
{
Name: "foo",
Extra: map[string]interface{}{
ExtraExt: "deb",
ExtraExt: ".deb",
},
},
{
@ -504,7 +504,7 @@ func TestByExts(t *testing.T) {
require.Len(t, artifacts.Filter(ByExt("deb")).items, 2)
require.Len(t, artifacts.Filter(ByExt("rpm")).items, 1)
require.Len(t, artifacts.Filter(ByExt("rpm", "deb")).items, 3)
require.Len(t, artifacts.Filter(ByExt("rpm", ".deb")).items, 3)
require.Empty(t, artifacts.Filter(ByExt("foo")).items)
}

View File

@ -239,21 +239,21 @@ func TestUpload(t *testing.T) {
ext string
typ artifact.Type
}{
{"---", artifact.DockerImage},
{"deb", artifact.LinuxPackage},
{"bin", artifact.Binary},
{"tar", artifact.UploadableArchive},
{"tar.gz", artifact.UploadableSourceArchive},
{"ubi", artifact.UploadableBinary},
{"sum", artifact.Checksum},
{"meta", artifact.Metadata},
{"sig", artifact.Signature},
{"pem", artifact.Certificate},
{"", artifact.DockerImage},
{".deb", artifact.LinuxPackage},
{".bin", artifact.Binary},
{".tar", artifact.UploadableArchive},
{".tar.gz", artifact.UploadableSourceArchive},
{".ubi", artifact.UploadableBinary},
{".sum", artifact.Checksum},
{".meta", artifact.Metadata},
{".sig", artifact.Signature},
{".pem", artifact.Certificate},
} {
file := filepath.Join(folder, "a."+a.ext)
file := filepath.Join(folder, "a"+a.ext)
require.NoError(t, os.WriteFile(file, []byte("lorem ipsum"), 0o644))
ctx.Artifacts.Add(&artifact.Artifact{
Name: "a." + a.ext,
Name: "a" + a.ext,
Goos: "linux",
Goarch: "amd64",
Path: file,

View File

@ -531,7 +531,7 @@ func create(ctx *context.Context, fpm config.NFPM, format string, artifacts []*a
Extra: map[string]interface{}{
artifact.ExtraID: fpm.ID,
artifact.ExtraFormat: format,
artifact.ExtraExt: format,
artifact.ExtraExt: "." + format,
extraFiles: contents,
},
})

View File

@ -397,7 +397,7 @@ func TestRunPipe(t *testing.T) {
for _, pkg := range packages {
format := pkg.Format()
require.NotEmpty(t, format)
require.Equal(t, pkg.Format(), artifact.ExtraOr(*pkg, artifact.ExtraExt, ""))
require.Equal(t, "."+pkg.Format(), artifact.ExtraOr(*pkg, artifact.ExtraExt, ""))
arch := pkg.Goarch
if pkg.Goarm != "" {
arch += "v" + pkg.Goarm

View File

@ -30,7 +30,7 @@ func For(name string) Builder {
type Options struct {
Name string
Path string
Ext string
Ext string // with the leading `.`.
Target string
Goos string
Goarch string

View File

@ -102,23 +102,23 @@ You should be able to use all its fields on each item:
On fields that are related to a single artifact (e.g., the binary name), you
may have some extra fields:
| Key | Description |
| --------------- | ------------------------------ |
| `.Os` | `GOOS` |
| `.Arch` | `GOARCH` |
| `.Arm` | `GOARM` |
| `.Mips` | `GOMIPS` |
| `.Amd64` | `GOAMD64` |
| `.Arm64` | `GOARM64` (since v2.4) |
| `.Mips64` | `GOMIPS64` (since v2.4) |
| `.Ppc64` | `GOPPC64` (since v2.4) |
| `.Riscv64` | `GORISCV64` (since v2.4) |
| `.I386` | `GO386` (since v2.4) |
| `.Binary` | binary name |
| `.ArtifactID` | archive id (since v2.3[^pro]) |
| `.ArtifactName` | archive name |
| `.ArtifactPath` | absolute path to artifact |
| `.ArtifactExt` | binary extension (e.g. `.exe`) |
| Key | Description |
| --------------- | --------------------------------------------- |
| `.Os` | `GOOS` |
| `.Arch` | `GOARCH` |
| `.Arm` | `GOARM` |
| `.Mips` | `GOMIPS` |
| `.Amd64` | `GOAMD64` |
| `.Arm64` | `GOARM64` (since v2.4) |
| `.Mips64` | `GOMIPS64` (since v2.4) |
| `.Ppc64` | `GOPPC64` (since v2.4) |
| `.Riscv64` | `GORISCV64` (since v2.4) |
| `.I386` | `GO386` (since v2.4) |
| `.Binary` | artifact name |
| `.ArtifactID` | artifact id (since v2.3[^pro]) |
| `.ArtifactName` | artifact name |
| `.ArtifactPath` | absolute path to artifact |
| `.ArtifactExt` | artifact extension (e.g. `.exe`, `.dmg`, etc) |
## nFPM extra fields