From d2f558585726415cf542fa85850af07472c55658 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Mon, 4 Mar 2024 22:56:49 -0300 Subject: [PATCH 1/2] fix(apk): conventional name template closes #793 Signed-off-by: Carlos Alexandro Becker --- apk/apk.go | 17 +++++++++++++++-- apk/apk_test.go | 16 ++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/apk/apk.go b/apk/apk.go index 33304bc4..23a73763 100644 --- a/apk/apk.go +++ b/apk/apk.go @@ -94,8 +94,21 @@ func (a *Apk) ConventionalFileName(info *nfpm.Info) string { version += "_" + info.Prerelease } - if info.Release != "" { - version += "_p" + info.Release + 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 fmt.Sprintf("%s_%s_%s.apk", info.Name, version, info.Arch) diff --git a/apk/apk_test.go b/apk/apk_test.go index a6310112..b3b69005 100644 --- a/apk/apk_test.go +++ b/apk/apk_test.go @@ -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", }, } From 0d2564bdb9d7bbede46be5e763508edcf272b97a Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Fri, 8 Mar 2024 13:26:22 -0300 Subject: [PATCH 2/2] fix: pkginfo Signed-off-by: Carlos Alexandro Becker --- apk/apk.go | 55 ++++++++++--------- apk/testdata/TestControl.golden | 2 +- apk/testdata/TestCreateBuilderControl.golden | 2 +- .../TestCreateBuilderControlScripts.golden | 2 +- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/apk/apk.go b/apk/apk.go index 23a73763..d2c987b4 100644 --- a/apk/apk.go +++ b/apk/apk.go @@ -88,29 +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 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 - } - + version := pkgver(info) return fmt.Sprintf("%s_%s_%s.apk", info.Name, version, info.Arch) } @@ -482,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}} @@ -522,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 +} diff --git a/apk/testdata/TestControl.golden b/apk/testdata/TestControl.golden index b7a41772..6f8901df 100644 --- a/apk/testdata/TestControl.golden +++ b/apk/testdata/TestControl.golden @@ -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 diff --git a/apk/testdata/TestCreateBuilderControl.golden b/apk/testdata/TestCreateBuilderControl.golden index 549e4593..181c72c6 100644 --- a/apk/testdata/TestCreateBuilderControl.golden +++ b/apk/testdata/TestCreateBuilderControl.golden @@ -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 diff --git a/apk/testdata/TestCreateBuilderControlScripts.golden b/apk/testdata/TestCreateBuilderControlScripts.golden index 549e4593..181c72c6 100644 --- a/apk/testdata/TestCreateBuilderControlScripts.golden +++ b/apk/testdata/TestCreateBuilderControlScripts.golden @@ -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