1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

fix(build): ignore empty flags after templating (#5103)

Ignore empty flags after templating is applied for final Go build line.

This caused us some problems since we had an `if` without `else`,
resulting in an empty flag, causing the whole build to fail with a
misleading error message like:

```
malformed import path "-myflag": leading dash
```
This commit is contained in:
Nicolás Parada 2024-08-27 08:06:27 -04:00 committed by GitHub
parent 69e2d8f45a
commit a9e0a8f112
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View File

@ -365,6 +365,11 @@ func processFlags(ctx *context.Context, a *artifact.Artifact, env, flags []strin
if err != nil {
return nil, err
}
if flag == "" {
continue
}
processed = append(processed, flagPrefix+flag)
}
return processed, nil

View File

@ -992,6 +992,16 @@ func TestProcessFlagsInvalid(t *testing.T) {
require.Nil(t, flags)
}
func TestProcessFlagsIgnoreEmptyFlags(t *testing.T) {
ctx := testctx.New()
source := []string{
"{{if eq 1 2}}-ignore-me{{end}}",
}
flags, err := processFlags(ctx, &artifact.Artifact{}, []string{}, source, "")
require.NoError(t, err)
require.Len(t, flags, 0)
}
func TestBuildModTimestamp(t *testing.T) {
// round to seconds since this will be a unix timestamp
modTime := time.Now().AddDate(-1, 0, 0).Round(1 * time.Second).UTC()