Skip to content

Commit

Permalink
feat: remove deprecated replacements (#4075)
Browse files Browse the repository at this point in the history
since this will be a late, big release, let's remove the deprecated
stuff that expired

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Jun 6, 2023
1 parent 2e2bde5 commit 66cee94
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 238 deletions.
12 changes: 1 addition & 11 deletions internal/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,10 @@ type command struct {
// Those variables can be replaced by the given context, goos, goarch, goarm and more.
func resolveCommand(ctx *context.Context, publisher config.Publisher, artifact *artifact.Artifact) (*command, error) {
var err error

replacements := make(map[string]string)
// TODO: Replacements should be associated only with relevant artifacts/archives
// this is pretty much all wrong and will be removed soon.
archives := ctx.Config.Archives
if len(archives) > 0 {
replacements = archives[0].Replacements
}

dir := publisher.Dir

// nolint:staticcheck
tpl := tmpl.New(ctx).
WithArtifactReplacements(artifact, replacements)
tpl := tmpl.New(ctx).WithArtifact(artifact)
if dir != "" {
dir, err = tpl.Apply(dir)
if err != nil {
Expand Down
7 changes: 0 additions & 7 deletions internal/exec/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ import (
func TestExecute(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
ProjectName: "blah",
Archives: []config.Archive{
{
Replacements: map[string]string{
"linux": "Linux",
},
},
},
Env: []string{
"TEST_A_SECRET=x",
"TEST_A_USERNAME=u2",
Expand Down
35 changes: 2 additions & 33 deletions internal/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func uploadAsset(ctx *context.Context, upload *config.Upload, artifact *artifact
secret := getPassword(ctx, upload, kind)

// Generate the target url
targetURL, err := resolveTargetTemplate(ctx, upload, artifact)
targetURL, err := tmpl.New(ctx).WithArtifact(artifact).Apply(upload.Target)
if err != nil {
return fmt.Errorf("%s: %s: error while building target URL: %w", upload.Name, kind, err)
}
Expand All @@ -241,7 +241,7 @@ func uploadAsset(ctx *context.Context, upload *config.Upload, artifact *artifact
headers := map[string]string{}
if upload.CustomHeaders != nil {
for name, value := range upload.CustomHeaders {
resolvedValue, err := resolveHeaderTemplate(ctx, upload, artifact, value)
resolvedValue, err := tmpl.New(ctx).WithArtifact(artifact).Apply(value)
if err != nil {
return fmt.Errorf("%s: %s: failed to resolve custom_headers template: %w", upload.Name, kind, err)
}
Expand Down Expand Up @@ -361,34 +361,3 @@ func executeHTTPRequest(ctx *context.Context, upload *config.Upload, req *h.Requ

return resp, err
}

// resolveTargetTemplate returns the resolved target template with replaced variables
// Those variables can be replaced by the given context, goos, goarch, goarm and more.
func resolveTargetTemplate(ctx *context.Context, upload *config.Upload, artifact *artifact.Artifact) (string, error) {
replacements := map[string]string{}
if upload.Mode == ModeBinary {
// TODO: multiple archives here
// will be removed soon anyway
replacements = ctx.Config.Archives[0].Replacements
}

// nolint:staticcheck
return tmpl.New(ctx).
WithArtifactReplacements(artifact, replacements).
Apply(upload.Target)
}

// resolveHeaderTemplate returns the resolved custom header template with replaced variables
// Those variables can be replaced by the given context, goos, goarch, goarm and more.
func resolveHeaderTemplate(ctx *context.Context, upload *config.Upload, artifact *artifact.Artifact, headerValue string) (string, error) {
replacements := map[string]string{}
if upload.Mode == ModeBinary {
// TODO: multiple archives here
// will be removed soon anyway
replacements = ctx.Config.Archives[0].Replacements
}
// nolint:staticcheck
return tmpl.New(ctx).
WithArtifactReplacements(artifact, replacements).
Apply(headerValue)
}
9 changes: 1 addition & 8 deletions internal/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,6 @@ func TestUpload(t *testing.T) {
}
ctx := testctx.NewWithCfg(config.Project{
ProjectName: "blah",
Archives: []config.Archive{
{
Replacements: map[string]string{
"linux": "Linux",
},
},
},
Env: []string{
"TEST_A_SECRET=x",
"TEST_A_USERNAME=u2",
Expand Down Expand Up @@ -397,7 +390,7 @@ func TestUpload(t *testing.T) {
TrustedCerts: cert(s),
}
},
checks(check{"/blah/2.1.0/Linux/amd64/a.ubi", "u2", "x", content, map[string]string{}}),
checks(check{"/blah/2.1.0/linux/amd64/a.ubi", "u2", "x", content, map[string]string{}}),
},
{
"binary_with_ids", true, true, false, false,
Expand Down
20 changes: 8 additions & 12 deletions internal/pipe/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ func (Pipe) Default(ctx *context.Context) error {
archive.NameTemplate = defaultBinaryNameTemplate
}
}
if len(archive.Replacements) != 0 {
deprecate.Notice(ctx, "archives.replacements")
}
ids.Inc(archive.ID)
}
return ids.Validate()
Expand Down Expand Up @@ -141,17 +138,19 @@ func checkArtifacts(artifacts map[string][]*artifact.Artifact) error {
}

func createMeta(ctx *context.Context, arch config.Archive) error {
return doCreate(ctx, arch, nil, arch.Format, tmpl.New(ctx))
return doCreate(ctx, arch, nil, arch.Format)
}

func create(ctx *context.Context, arch config.Archive, binaries []*artifact.Artifact) error {
// nolint:staticcheck
template := tmpl.New(ctx).WithArtifactReplacements(binaries[0], arch.Replacements)
format := packageFormat(arch, binaries[0].Goos)
return doCreate(ctx, arch, binaries, format, template)
return doCreate(ctx, arch, binaries, format)
}

func doCreate(ctx *context.Context, arch config.Archive, binaries []*artifact.Artifact, format string, template *tmpl.Template) error {
func doCreate(ctx *context.Context, arch config.Archive, binaries []*artifact.Artifact, format string) error {
template := tmpl.New(ctx)
if len(binaries) > 0 {
template = template.WithArtifact(binaries[0])
}
folder, err := template.Apply(arch.NameTemplate)
if err != nil {
return err
Expand Down Expand Up @@ -253,10 +252,7 @@ func wrapFolder(a config.Archive) string {

func skip(ctx *context.Context, archive config.Archive, binaries []*artifact.Artifact) error {
for _, binary := range binaries {
// nolint:staticcheck
name, err := tmpl.New(ctx).
WithArtifactReplacements(binary, archive.Replacements).
Apply(archive.NameTemplate)
name, err := tmpl.New(ctx).WithArtifact(binary).Apply(archive.NameTemplate)
if err != nil {
return err
}
Expand Down
7 changes: 2 additions & 5 deletions internal/pipe/archive/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,9 +678,6 @@ func TestRunPipeWrap(t *testing.T) {
NameTemplate: "foo",
WrapInDirectory: "foo_{{ .Os }}",
Format: "tar.gz",
Replacements: map[string]string{
"darwin": "macOS",
},
Files: []config.File{
{Source: "README.*"},
},
Expand All @@ -704,11 +701,11 @@ func TestRunPipeWrap(t *testing.T) {

archives := ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive)).List()
require.Len(t, archives, 1)
require.Equal(t, "foo_macOS", artifact.ExtraOr(*archives[0], artifact.ExtraWrappedIn, ""))
require.Equal(t, "foo_darwin", artifact.ExtraOr(*archives[0], artifact.ExtraWrappedIn, ""))

require.ElementsMatch(
t,
[]string{"foo_macOS/README.md", "foo_macOS/mybin"},
[]string{"foo_darwin/README.md", "foo_darwin/mybin"},
testlib.LsArchive(t, filepath.Join(dist, "foo.tar.gz"), "tar.gz"),
)
}
Expand Down
11 changes: 1 addition & 10 deletions internal/pipe/nfpm/nfpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ func (Pipe) Default(ctx *context.Context) error {
if fpm.Maintainer == "" {
deprecate.NoticeCustom(ctx, "nfpms.maintainer", "`{{ .Property }}` should always be set, check {{ .URL }} for more info")
}
if len(fpm.Replacements) != 0 {
deprecate.Notice(ctx, "nfpms.replacements")
}
for _, rfpm := range fpm.Overrides {
if len(rfpm.Replacements) != 0 {
deprecate.Notice(ctx, "nfpms.replacements")
}
}
ids.Inc(fpm.ID)
}

Expand Down Expand Up @@ -184,9 +176,8 @@ func create(ctx *context.Context, fpm config.NFPM, format string, binaries []*ar
return err
}

// nolint:staticcheck
t := tmpl.New(ctx).
WithArtifactReplacements(binaries[0], overridden.Replacements).
WithArtifact(binaries[0]).
WithExtraFields(tmpl.Fields{
"Release": fpm.Release,
"Epoch": fpm.Epoch,
Expand Down
46 changes: 2 additions & 44 deletions internal/pipe/nfpm/nfpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,6 @@ func TestRunPipeNoFormats(t *testing.T) {
testlib.AssertSkipped(t, Pipe{}.Run(ctx))
}

func TestDefaultsDeprecated(t *testing.T) {
t.Run("replacements", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
NFPMs: []config.NFPM{
{
NFPMOverridables: config.NFPMOverridables{
Replacements: map[string]string{
"linux": "Tux",
},
},
},
},
})
require.NoError(t, Pipe{}.Default(ctx))
require.True(t, ctx.Deprecated)
})

t.Run("replacements overrides", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
NFPMs: []config.NFPM{
{
Overrides: map[string]config.NFPMOverridables{
"apk": {
Replacements: map[string]string{
"linux": "Tux",
},
},
},
},
},
})
require.NoError(t, Pipe{}.Default(ctx))
require.True(t, ctx.Deprecated)
})
}

func TestRunPipeError(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Dist: t.TempDir(),
Expand Down Expand Up @@ -206,9 +170,6 @@ func TestRunPipe(t *testing.T) {
Destination: "/etc/folder",
},
},
Replacements: map[string]string{
"linux": "Tux",
},
},
},
},
Expand Down Expand Up @@ -304,7 +265,7 @@ func TestRunPipe(t *testing.T) {
}

if pkg.Goos == "linux" {
require.Equal(t, "foo_1.0.0_Tux_"+arch+"-10-20"+ext, pkg.Name)
require.Equal(t, "foo_1.0.0_linux_"+arch+"-10-20"+ext, pkg.Name)
} else {
require.Equal(t, "foo_1.0.0_ios_arm64-10-20"+ext, pkg.Name)
}
Expand Down Expand Up @@ -1256,9 +1217,6 @@ func TestMeta(t *testing.T) {
Type: "dir",
},
},
Replacements: map[string]string{
"linux": "Tux",
},
},
},
},
Expand All @@ -1283,7 +1241,7 @@ func TestMeta(t *testing.T) {
for _, pkg := range packages {
format := pkg.Format()
require.NotEmpty(t, format)
require.Equal(t, pkg.Name, "foo_1.0.0_Tux_"+pkg.Goarch+"-10-20."+format)
require.Equal(t, pkg.Name, "foo_1.0.0_linux_"+pkg.Goarch+"-10-20."+format)
require.Equal(t, pkg.ID(), "someid")
require.ElementsMatch(t, []string{
"/var/log/foobar",
Expand Down
9 changes: 1 addition & 8 deletions internal/pipe/snapcraft/snapcraft.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/caarlos0/log"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/deprecate"
"github.com/goreleaser/goreleaser/internal/gio"
"github.com/goreleaser/goreleaser/internal/ids"
"github.com/goreleaser/goreleaser/internal/pipe"
Expand Down Expand Up @@ -132,9 +131,6 @@ func (Pipe) Default(ctx *context.Context) error {
snap.Builds = append(snap.Builds, b.ID)
}
}
if len(snap.Replacements) != 0 {
deprecate.Notice(ctx, "snapcrafts.replacements")
}
ids.Inc(snap.ID)
}
return ids.Validate()
Expand Down Expand Up @@ -224,10 +220,7 @@ func (Pipe) Publish(ctx *context.Context) error {

func create(ctx *context.Context, snap config.Snapcraft, arch string, binaries []*artifact.Artifact) error {
log := log.WithField("arch", arch)
// nolint:staticcheck
folder, err := tmpl.New(ctx).
WithArtifactReplacements(binaries[0], snap.Replacements).
Apply(snap.NameTemplate)
folder, err := tmpl.New(ctx).WithArtifact(binaries[0]).Apply(snap.NameTemplate)
if err != nil {
return err
}
Expand Down
25 changes: 0 additions & 25 deletions internal/tmpl/tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,6 @@ func (t *Template) WithExtraFields(f Fields) *Template {
return t
}

// WithArtifactReplacements populates Fields from the artifact and replacements.
//
// Deprecated: use WithArtifact instead.
func (t *Template) WithArtifactReplacements(a *artifact.Artifact, replacements map[string]string) *Template {
t.fields[osKey] = replace(replacements, a.Goos)
t.fields[arch] = replace(replacements, a.Goarch)
t.fields[arm] = replace(replacements, a.Goarm)
t.fields[mips] = replace(replacements, a.Gomips)
t.fields[amd64] = replace(replacements, a.Goamd64)
t.fields[binary] = artifact.ExtraOr(*a, binary, t.fields[projectName].(string))
t.fields[artifactName] = a.Name
t.fields[artifactExt] = artifact.ExtraOr(*a, artifact.ExtraExt, "")
t.fields[artifactPath] = a.Path
return t
}

// WithArtifact populates Fields from the artifact.
func (t *Template) WithArtifact(a *artifact.Artifact) *Template {
t.fields[osKey] = a.Goos
Expand Down Expand Up @@ -280,15 +264,6 @@ func (t *Template) ApplySingleEnvOnly(s string) (string, error) {
return out.String(), err
}

// deprecated: will be removed soon.
func replace(replacements map[string]string, original string) string {
result := replacements[original]
if result == "" {
return original
}
return result
}

func incMajor(v string) string {
return prefix(v) + semver.MustParse(v).IncMajor().String()
}
Expand Down

0 comments on commit 66cee94

Please sign in to comment.