We can use `(*regexp.Regexp).MatchString` instead of
`(*regexp.Regexp).Match([]byte(...))` to avoid unnecessary `[]byte`
conversions and reduce allocations. A one-line change for free
performance gain.
Benchmark:
```go
func BenchmarkMatch(b *testing.B) {
for i := 0; i < b.N; i++ {
if match := envOnlyRe.Match([]byte("{{ .Env.FOO }}")); !match {
b.Fail()
}
}
}
func BenchmarkMatchString(b *testing.B) {
for i := 0; i < b.N; i++ {
if match := envOnlyRe.MatchString("{{ .Env.FOO }}"); !match {
b.Fail()
}
}
}
```
Result:
```
goos: linux
goarch: amd64
pkg: github.com/goreleaser/goreleaser/internal/tmpl cpu: AMD Ryzen 7 PRO 4750U with Radeon Graphics
BenchmarkMatch-16 4320873 381.2 ns/op 16 B/op 1 allocs/op
BenchmarkMatchString-16 5973543 203.9 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/goreleaser/goreleaser/internal/tmpl 3.366s
```
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
also regex is not possible there currenctly, didnt realized it at the
time
refs #4255
---------
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Add a new function `map` to template functions.
`map` creates a map from a list of pairs of key values, then you can
convert a key to a value using `.Get`. This simplifies writing
key-mapping templates. For example, the defaule `archives.name_template`
```yaml
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
```
becomes
```yaml
name_template: >-
{{ $arch := map "amd64" "x86_64" "386" "i386" -}}
{{ .ProjectName }}_
{{- title .OS }}_
{{- $arch.Get .Arch .Arch }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
```
---------
Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
this will log everything that's being skipped in the beginning of the
release process.
also added some tests to `skips`
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
the paths of the artifacts always use forward slashes, and the logic to
handle the relative path stuff inside the sbom pipe did not account for
that.
running the paths through `filepath.Clean` beforehand fixes it.
also improved yamlschema a little bit :)
closes#4289
Laying the ground work to allow skipping more pipes without adding new
flags et al.
---------
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
tested this on a fake repo, and it seems to fix the problem...
seems like choco does not like when the path has `/` in it, so passing
it through `filepath.Clean` fixes it.
also improved tests a bit, and made a small docs fix.
closes https://github.com/goreleaser/goreleaser/issues/4292
<!--
Hi, thanks for contributing!
Please make sure you read our CONTRIBUTING guide.
Also, add tests and the respective documentation changes as well.
-->
<!-- If applied, this commit will... -->
The gomod pipe will skip if the Go version does not support modules.
<!-- Why is this change being made? -->
I tried to use goreleaser to build a project with Go v1.8.7 and it
failed on `loading go mod information` step. The Go version used doesn't
support `go list -m`.
The build failed with the following error:
```
• loading go mod information
⨯ release failed after 0s error=failed to get module path: exit status 2: flag provided but not defined: -m
usage: list [-e] [-f format] [-json] [build flags] [packages]
List lists the packages named by the import paths, one per line.
...
```
<!-- # Provide links to any relevant tickets, URLs or other resources
-->
...
the publish pipe, which runs all publishers, already skips all
publishers if skip publish is set, so this check is not needed here.
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
the publish pipe, which runs all publishers, already skips all
publishers if skip publish is set, so this check is not needed here.
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
the publish pipe, which runs all publishers, already skips all
publishers if skip publish is set, so this check is not needed here.
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Currently, GoReleaser will assume you're running against github, gitea
or gitlab.
You could set `release.disable: true`, but it would still set and try to
use some defaults that could break things up.
Now, if you disable the release, goreleaser will not set these defaults.
It'll also hard error in some cases in which it would happily produce
invalid resources before, namely, if `release.disable` is set, and, for
example, `brews.url_template` is empty (in which case it would try to
use the one from the release, usually github).
closes#4208
if the base branch is empty, it'll try to fetch the default branch,
which would fail if base repo name/owner are also empty.
the default behavior when base owner/name are missing is to using
head's, so I changed it do that before trying to get the default branch,
which should fix the issue.
<!--
Hi, thanks for contributing!
Please make sure you read our CONTRIBUTING guide.
Also, add tests and the respective documentation changes as well.
-->
<!-- If applied, this commit will... -->
...
<!-- Why is this change being made? -->
...
<!-- # Provide links to any relevant tickets, URLs or other resources
-->
...
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
allows to disable a specific custom publisher based on a template, akin
to other pipes.
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>