mirror of
https://github.com/goreleaser/nfpm
synced 2024-05-06 00:26:11 +02:00
fix(apk): conventional name template (#794)
* fix(apk): conventional name template closes #793 Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> * fix: pkginfo Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
4a7322bba1
commit
29c8a210fe
42
apk/apk.go
42
apk/apk.go
|
@ -88,16 +88,7 @@ type Apk struct{}
|
|||
|
||||
func (a *Apk) ConventionalFileName(info *nfpm.Info) string {
|
||||
info = ensureValidArch(info)
|
||||
version := info.Version
|
||||
|
||||
if info.Prerelease != "" {
|
||||
version += "_" + info.Prerelease
|
||||
}
|
||||
|
||||
if info.Release != "" {
|
||||
version += "_p" + info.Release
|
||||
}
|
||||
|
||||
version := pkgver(info)
|
||||
return fmt.Sprintf("%s_%s_%s.apk", info.Name, version, info.Arch)
|
||||
}
|
||||
|
||||
|
@ -469,9 +460,7 @@ func copyToTarAndDigest(file *files.Content, tw *tar.Writer, sizep *int64) error
|
|||
const controlTemplate = `
|
||||
{{- /* Mandatory fields */ -}}
|
||||
pkgname = {{.Info.Name}}
|
||||
pkgver = {{.Info.Version}}
|
||||
{{- if .Info.Prerelease}}{{ .Info.Prerelease }}{{- end }}
|
||||
{{- if .Info.Release}}-{{ .Info.Release }}{{- end }}
|
||||
pkgver = {{ pkgver .Info }}
|
||||
arch = {{.Info.Arch}}
|
||||
size = {{.InstalledSize}}
|
||||
pkgdesc = {{multiline .Info.Description}}
|
||||
|
@ -509,6 +498,33 @@ func writeControl(w io.Writer, data controlData) error {
|
|||
ret := strings.ReplaceAll(strs, "\n", "\n ")
|
||||
return strings.Trim(ret, " \n")
|
||||
},
|
||||
"pkgver": pkgver,
|
||||
})
|
||||
return template.Must(tmpl.Parse(controlTemplate)).Execute(w, data)
|
||||
}
|
||||
|
||||
func pkgver(info *nfpm.Info) string {
|
||||
version := info.Version
|
||||
|
||||
if info.Prerelease != "" {
|
||||
version += "_" + info.Prerelease
|
||||
}
|
||||
|
||||
if rel := info.Release; rel != "" {
|
||||
if !strings.HasPrefix(rel, "r") {
|
||||
rel = "r" + rel
|
||||
}
|
||||
version += "-" + rel
|
||||
}
|
||||
if meta := info.VersionMetadata; meta != "" {
|
||||
if !strings.HasPrefix(meta, "p") &&
|
||||
!strings.HasPrefix(meta, "cvs") &&
|
||||
!strings.HasPrefix(meta, "svn") &&
|
||||
!strings.HasPrefix(meta, "git") &&
|
||||
!strings.HasPrefix(meta, "hg") {
|
||||
meta = "p" + meta
|
||||
}
|
||||
version += "-" + meta
|
||||
}
|
||||
return version
|
||||
}
|
||||
|
|
|
@ -477,12 +477,16 @@ func TestAPKConventionalFileName(t *testing.T) {
|
|||
Expect: "default_1.2.3_x86_64.apk",
|
||||
},
|
||||
{
|
||||
Arch: "386", Version: "1.2.3", Prerelease: "git",
|
||||
Expect: "default_1.2.3_git_x86.apk",
|
||||
Arch: "386", Version: "1.2.3", Meta: "git",
|
||||
Expect: "default_1.2.3-git_x86.apk",
|
||||
},
|
||||
{
|
||||
Arch: "386", Version: "1.2.3", Meta: "1", Release: "10",
|
||||
Expect: "default_1.2.3-r10-p1_x86.apk",
|
||||
},
|
||||
{
|
||||
Arch: "386", Version: "1.2.3", Prerelease: "git", Release: "1",
|
||||
Expect: "default_1.2.3_git_p1_x86.apk",
|
||||
Expect: "default_1.2.3_git-r1_x86.apk",
|
||||
},
|
||||
{
|
||||
Arch: "all", Version: "1.2.3",
|
||||
|
@ -490,7 +494,11 @@ func TestAPKConventionalFileName(t *testing.T) {
|
|||
},
|
||||
{
|
||||
Arch: "386", Version: "1.2.3", Release: "1", Prerelease: "beta1",
|
||||
Expect: "default_1.2.3_beta1_p1_x86.apk",
|
||||
Expect: "default_1.2.3_beta1-r1_x86.apk",
|
||||
},
|
||||
{
|
||||
Arch: "amd64", Version: "1.2.3a", Prerelease: "alpha1", Release: "47", Meta: "git-aaaccc",
|
||||
Expect: "default_1.2.3a_alpha1-r47-git-aaaccc_x86_64.apk",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
pkgname = foo
|
||||
pkgver = 1.0.0beta1-r1
|
||||
pkgver = 1.0.0_beta1-r1
|
||||
arch = amd64
|
||||
size = 10
|
||||
pkgdesc = Foo does things
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
pkgname = foo
|
||||
pkgver = 1.0.0beta1-r1
|
||||
pkgver = 1.0.0_beta1-r1
|
||||
arch = amd64
|
||||
size = 12345
|
||||
pkgdesc = Foo does things
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
pkgname = foo
|
||||
pkgver = 1.0.0beta1-r1
|
||||
pkgver = 1.0.0_beta1-r1
|
||||
arch = amd64
|
||||
size = 12345
|
||||
pkgdesc = Foo does things
|
||||
|
|
Loading…
Reference in New Issue