Skip to content

Commit

Permalink
fix: apk versioning (#514)
Browse files Browse the repository at this point in the history
* Fix apk versioning

* Update acceptance test for apk
  • Loading branch information
kpenfound committed May 30, 2022
1 parent 1e26cfc commit eb26ce3
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 19 deletions.
14 changes: 5 additions & 9 deletions apk/apk.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,13 @@ type Apk struct{}
func (a *Apk) ConventionalFileName(info *nfpm.Info) string {
info = ensureValidArch(info)
version := info.Version
if info.Release != "" {
version += "-" + info.Release
}

if info.Prerelease != "" {
version += "~" + info.Prerelease
version += "" + info.Prerelease
}

if info.VersionMetadata != "" {
version += "+" + info.VersionMetadata
if info.Release != "" {
version += "-" + info.Release
}

return fmt.Sprintf("%s_%s_%s.apk", info.Name, version, info.Arch)
Expand Down Expand Up @@ -559,10 +556,9 @@ func pathsToCreate(dst string) []string {
const controlTemplate = `
{{- /* Mandatory fields */ -}}
pkgname = {{.Info.Name}}
pkgver = {{ if .Info.Epoch}}{{ .Info.Epoch }}:{{ end }}{{.Info.Version}}
pkgver = {{.Info.Version}}
{{- if .Info.Prerelease}}{{ .Info.Prerelease }}{{- end }}
{{- if .Info.Release}}-{{ .Info.Release }}{{- end }}
{{- if .Info.Prerelease}}~{{ .Info.Prerelease }}{{- end }}
{{- if .Info.VersionMetadata}}+{{ .Info.VersionMetadata }}{{- end }}
arch = {{.Info.Arch}}
size = {{.InstalledSize}}
pkgdesc = {{multiline .Info.Description}}
Expand Down
13 changes: 7 additions & 6 deletions apk/apk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func exampleInfo() *nfpm.Info {
Priority: "extra",
Maintainer: "Carlos A Becker <pkg@carlosbecker.com>",
Version: "v1.0.0",
Prerelease: "beta1",
Release: "r1",
Section: "default",
Homepage: "http://carlosbecker.com",
Expand Down Expand Up @@ -444,20 +445,20 @@ func TestAPKConventionalFileName(t *testing.T) {
Expect: "default_1.2.3_x86_64.apk",
},
{
Arch: "386", Version: "1.2.3", Meta: "git",
Expect: "default_1.2.3+git_x86.apk",
Arch: "386", Version: "1.2.3", Prerelease: "git",
Expect: "default_1.2.3git_x86.apk",
},
{
Arch: "386", Version: "1.2.3", Meta: "git", Release: "1",
Expect: "default_1.2.3-1+git_x86.apk",
Arch: "386", Version: "1.2.3", Prerelease: "git", Release: "1",
Expect: "default_1.2.3git-1_x86.apk",
},
{
Arch: "all", Version: "1.2.3",
Expect: "default_1.2.3_all.apk",
},
{
Arch: "386", Version: "1.2.3", Release: "1", Prerelease: "5",
Expect: "default_1.2.3-1~5_x86.apk",
Arch: "386", Version: "1.2.3", Release: "1", Prerelease: "beta",
Expect: "default_1.2.3beta-1_x86.apk",
},
}

Expand Down
2 changes: 1 addition & 1 deletion apk/testdata/TestControl.golden
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pkgname = foo
pkgver = 1.0.0-r1
pkgver = 1.0.0beta1-r1
arch = amd64
size = 10
pkgdesc = Foo does things
Expand Down
2 changes: 1 addition & 1 deletion apk/testdata/TestCreateBuilderControl.golden
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pkgname = foo
pkgver = 1.0.0-r1
pkgver = 1.0.0beta1-r1
arch = amd64
size = 12345
pkgdesc = Foo does things
Expand Down
2 changes: 1 addition & 1 deletion apk/testdata/TestCreateBuilderControlScripts.golden
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pkgname = foo
pkgver = 1.0.0-r1
pkgver = 1.0.0beta1-r1
arch = amd64
size = 12345
pkgdesc = Foo does things
Expand Down
2 changes: 1 addition & 1 deletion testdata/acceptance/apk.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ RUN command -v zsh

# ---- env-var-version test ----
FROM min AS env-var-version
ENV EXPECTVER="foo-1.0.0~0.1.b1+git.abcdefgh description:"
ENV EXPECTVER="foo-1.0.00.1.b1 description:"
RUN apk info foo | grep "foo-" | grep " description:" > found
RUN export FOUND_VER="$(cat found)" && \
echo "Expected: '${EXPECTVER}' :: Found: '${FOUND_VER}'" && \
Expand Down

0 comments on commit eb26ce3

Please sign in to comment.