mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-04 03:11:55 +02:00
fix: allow underscores in formula name (#2205)
* fix: allow underscores in formula name
I was trying to create two formulas per release. One signifying the latest and
another with the version explicitly: formula.rb and formula@v0.0.0.rb
The filenames are fine but the formula name for the explicit version
was created as FormulaATv0.0.0 which isn't valid Ruby.
Looking at the function history I couldn't find why underscores were being replaced
since underscores are valid for Ruby identifiers. I opted to replace dots in a formula with
underscores
- 1399a39603
- https://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#ident
* test: add test for version in formula name
I think underscores are removed to make the Formula name cleaner
* test: re-add old test
This commit is contained in:
parent
7ff11a7730
commit
a9ce8f89d4
@ -323,9 +323,14 @@ func split(s string) []string {
|
||||
return strings
|
||||
}
|
||||
|
||||
// formulaNameFor transforms the formula name into a form
|
||||
// that more resembles a valid Ruby class name
|
||||
// e.g. foo_bar@v6.0.0-rc is turned into FooBarATv6_0_0RC
|
||||
// The order of these replacements is important
|
||||
func formulaNameFor(name string) string {
|
||||
name = strings.ReplaceAll(name, "-", " ")
|
||||
name = strings.ReplaceAll(name, "_", " ")
|
||||
name = strings.ReplaceAll(name, ".", "_")
|
||||
name = strings.ReplaceAll(name, "@", "AT")
|
||||
return strings.ReplaceAll(strings.Title(name), " ", "")
|
||||
}
|
||||
|
@ -31,6 +31,10 @@ func TestNameWithUnderline(t *testing.T) {
|
||||
require.Equal(t, formulaNameFor("some_binary"), "SomeBinary")
|
||||
}
|
||||
|
||||
func TestNameWithDots(t *testing.T) {
|
||||
require.Equal(t, formulaNameFor("binaryv0.0.0"), "Binaryv0_0_0")
|
||||
}
|
||||
|
||||
func TestNameWithAT(t *testing.T) {
|
||||
require.Equal(t, formulaNameFor("some_binary@1"), "SomeBinaryAT1")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user