Skip to content
Commits on Source (26)
......@@ -12,7 +12,7 @@ tests:
linting:
stage: verify
image: golangci/golangci-lint:v1.46-alpine
image: golangci/golangci-lint:v1.54-alpine
script:
- golangci-lint run -v
tags:
......
# Changelog
All notable changes to this project will be documented in this file.
## [0.8.0] - 2023-09-03
### Dependencies
- Add renovate.json
- Update module github.com/stretchr/testify to v1.8.4
- Update golangci/golangci-lint Docker tag to v1.54
- Update module github.com/MakeNowJust/heredoc to v2
- Update module gopkg.in/yaml.v2 to v3
- Update module github.com/MakeNowJust/heredoc to v2
- Update golang.org/x/exp digest to d852ddb
- Update module mvdan.cc/sh/v3 to v3.7.0
### apkbuild
- Switch to gopkg.in/yaml.v3
### parser
- Switch to interp.ExecHandlers
### pkg
- [**breaking**] Remove backwards compatibility package
## [0.7.0] - 2023-04-30
### apkindex
- Parse replaces lines from apk indexes
### go.mod
- Bump go version to 1.19
### package
- Parse replaces data from the PKGINFO block
### readme
- Update example import statements
- Improve package descriptions
- Add list of community projects
### releases
- Include information about keys
### version
- Add package with version parsing routines
- Fix up some tokenization edge cases
- Add tokenizer tests
- Add documentation
## [0.6.0] - 2022-09-07
### apkbuild
- Add builddir parsing
- Add Source#IsRemote method
- Expose shell functions
## [0.5.1] - 2022-07-26
### apkbuild
- Treat z as a letter in pkgspec parsing
### go.mod
- Bump testify to v1.8.0
## [0.5.0] - 2022-06-13
### Dependencies
- Upgrade mvdan.cc.sh/v3 to v3.5.1
- Upgrade github.com/stretchr/testify to v1.7.2
### apbuild
- Parse basic information
- Move out of pkg
### apkbuild
- Parse options
- Support parsing package specs
- Parse dependency related fields
- Parse arch
- Parse sources
- Parse subpackages
- Parse sha512sums
- Parse install related fields
- Parse triggers
- Add documentation
- Add acceptance tests
- Check runner.Run return value
- Address gocritic ifElseChain
### pkg/apkbuild
- Remove left-behind file
### releases
- Move out of pkg
### repository
- Move out of pkg
- Remove extra whitespace
### secfixes
- Fix panic due to non-string keys
### various
- Address commentFormatting linting
## [0.4.0] - 2022-03-23
### readme
- Fix some typos and old data
### repository
- Allow using plain io.Reader in ParsePackageIndex
- Move deferred close after err check
- Use lowercase error messages
### secfixes
- Restructure to support line numbers
## [0.3.1] - 2022-03-10
## [0.3.0] - 2021-11-27
### repository
- Rename from apkindex package
- Extract package struct to separate file
- Add structs to work with entire repositories
## [0.2.1] - 2021-04-27
### module
- Improve documentation
### releases
- Split fetch function
## [0.2.0] - 2021-04-26
### releases
- Package to fetch and parse alpine releasedata
## [0.1.2] - 2021-04-26
### secfixes
- Properly break out of loop
## [0.1.1] - 2021-04-25
### secfixes
- Handle lines with only a '#'
## [0.1.0] - 2021-04-25
### apkbuild
- A package to parse APBUILD files
### apkindex
- Add package to parse index files
### go.mod
- Rename module to match upstream repo
### readme
- Add documentation for the apkindex package
<!-- generated by git-cliff -->
......@@ -6,7 +6,7 @@ import (
"fmt"
"strings"
"github.com/MakeNowJust/heredoc"
"github.com/MakeNowJust/heredoc/v2"
"gitlab.alpinelinux.org/alpine/go/apkbuild"
"mvdan.cc/sh/v3/expand"
)
......
......@@ -43,9 +43,11 @@ func Parse(file ApkbuildFile, env expand.Environ) (apkbuild Apkbuild, err error)
runner, err := interp.New(
interp.Env(env),
interp.ExecHandler(func(ctx context.Context, args []string) error {
log.Printf("Warning: package %s tries to execute '%s'", file.PackageName, strings.Join(args, " "))
return nil
interp.ExecHandlers(func(next interp.ExecHandlerFunc) interp.ExecHandlerFunc {
return func(ctx context.Context, args []string) error {
log.Printf("Warning: package %s tries to execute '%s'", file.PackageName, strings.Join(args, " "))
return next(ctx, args)
}
}),
)
......
......@@ -4,7 +4,7 @@ import (
"strings"
"testing"
"github.com/MakeNowJust/heredoc"
"github.com/MakeNowJust/heredoc/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"mvdan.cc/sh/v3/expand"
......
......@@ -7,11 +7,50 @@ import (
"io"
"strings"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)
type secfixesData struct {
Secfixes yaml.MapSlice
Secfixes Secfixes
lineOffset uint
}
var _ yaml.Unmarshaler = (*secfixesData)(nil)
func (s *secfixesData) UnmarshalYAML(node *yaml.Node) error {
if node.Kind != yaml.MappingNode {
return fmt.Errorf("expected node to be a '!!map', received %s", node.Tag)
}
if len(node.Content) < 2 {
return fmt.Errorf("expected node to have 2 elements, but has %d", len(node.Content))
}
if node.Content[1].Kind != yaml.MappingNode {
return fmt.Errorf("expected node to contain a !!map, received %s", node.Content[1].Tag)
}
var fixedVersion *FixedVersion
for _, child := range node.Content[1].Content {
switch child.Kind {
case yaml.ScalarNode:
fixedVersion = new(FixedVersion)
fixedVersion.Version = child.Value
fixedVersion.LineNr = uint(child.Line) + s.lineOffset
case yaml.SequenceNode:
var fixes []Fix
err := child.Decode(&fixes)
if err != nil {
return err
}
for i := range fixes {
fixes[i].LineNr += s.lineOffset
}
fixedVersion.Fixes = fixes
s.Secfixes = append(s.Secfixes, *fixedVersion)
}
}
return nil
}
type FixedVersion struct {
......@@ -25,6 +64,12 @@ type Fix struct {
LineNr uint
}
func (f *Fix) UnmarshalYAML(node *yaml.Node) error {
f.Identifiers = strings.Split(node.Value, " ")
f.LineNr = uint(node.Line)
return nil
}
type Secfixes []FixedVersion
func (s Secfixes) Get(version string) *FixedVersion {
......@@ -67,31 +112,8 @@ scanLoop:
}
secfixesData := secfixesData{}
secfixesData.lineOffset = lineNr - 1
err = yaml.Unmarshal(secfixYaml.Bytes(), &secfixesData)
if err != nil {
return
}
for _, entry := range secfixesData.Secfixes {
lineNr++
secfixVersion := FixedVersion{
Version: fmt.Sprintf("%v", entry.Key),
LineNr: lineNr,
}
fixEntries := entry.Value.([]interface{})
for _, entry := range fixEntries {
lineNr++
secfix := Fix{
Identifiers: strings.Split(entry.(string), " "),
LineNr: lineNr,
}
secfixVersion.Fixes = append(secfixVersion.Fixes, secfix)
}
secfixes = append(secfixes, secfixVersion)
}
return
return secfixesData.Secfixes, err
}
......@@ -24,7 +24,7 @@ func (suite *SecfixesTestSuite) TestAllElementsAreParsed() {
secfixes, err := ParseSecfixes(suite.apkbuild)
suite.Require().Nil(err, "Error parsing secfixes")
suite.Require().Len(secfixes, 3)
suite.Require().Len(secfixes, 3, "secfixes section has 3 entries")
suite.Assert().Len(secfixes[0].Fixes, 2)
suite.Assert().Len(secfixes[1].Fixes, 1)
suite.Assert().Len(secfixes[2].Fixes, 1)
......@@ -49,11 +49,11 @@ func (suite *SecfixesTestSuite) TestLineNumbersAreCorrect() {
secfixes, err := ParseSecfixes(suite.apkbuild)
suite.Require().Nil(err, "Error parsing secfixes")
suite.Assert().EqualValues(6, secfixes[0].LineNr)
suite.Assert().EqualValues(7, secfixes[0].Fixes[0].LineNr)
suite.Assert().EqualValues(8, secfixes[0].Fixes[1].LineNr)
suite.Assert().EqualValues(9, secfixes[1].LineNr)
suite.Assert().EqualValues(10, secfixes[1].Fixes[0].LineNr)
suite.Assert().EqualValues(6, int(secfixes[0].LineNr))
suite.Assert().EqualValues(7, int(secfixes[0].Fixes[0].LineNr))
suite.Assert().EqualValues(8, int(secfixes[0].Fixes[1].LineNr))
suite.Assert().EqualValues(9, int(secfixes[1].LineNr))
suite.Assert().EqualValues(10, int(secfixes[1].Fixes[0].LineNr))
}
func (suite *SecfixesTestSuite) TestIdentifiersAreSplitCorrectly() {
......
# git-cliff ~ default configuration file
# https://git-cliff.org/docs/configuration
#
# Lines starting with "#" are comments.
# Configuration options are organized into tables and keys.
# See documentation for more information on available options.
[changelog]
# changelog header
header = """
# Changelog\n
All notable changes to this project will be documented in this file.\n
"""
# template for the changelog body
# https://tera.netlify.app/docs
body = """
{% if version %}\
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
{% else %}\
## [unreleased]
{% endif %}\
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group }}
{% for commit in commits %}
- {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first }}\
{% endfor %}
{% endfor %}\n
"""
# remove the leading and trailing whitespace from the template
trim = true
# changelog footer
footer = """
<!-- generated by git-cliff -->
"""
# postprocessors
postprocessors = [
# { pattern = '<REPO>', replace = "https://github.com/orhun/git-cliff" }, # replace repository URL
]
[git]
# parse the commits based on https://www.conventionalcommits.org
conventional_commits = true
# filter out the commits that are not conventional
filter_unconventional = false
# process each line of a commit as an individual commit
split_commits = false
# regex for preprocessing the commit messages
commit_preprocessors = [
# { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](<REPO>/issues/${2}))"}, # replace issue numbers
]
# regex for parsing and grouping commits
commit_parsers = [
{ message = "^(ci|renovate|release):", skip = true },
{ message = "^merge:", skip = true },
{ message = "^deps:", group = "Dependencies" },
]
# protect breaking changes from being skipped due to matching a skipping commit_parser
protect_breaking_commits = false
# filter out the commits that are not matched by commit parsers
filter_commits = false
# glob pattern for matching git tags
tag_pattern = "v[0-9]*"
# sort the tags topologically
topo_order = false
# sort the commits inside sections by oldest/newest order
sort_commits = "oldest"
......@@ -3,19 +3,18 @@ module gitlab.alpinelinux.org/alpine/go
go 1.19
require (
github.com/MakeNowJust/heredoc v1.0.0
github.com/stretchr/testify v1.8.0
golang.org/x/exp v0.0.0-20221212164502-fae10dda9338
github.com/MakeNowJust/heredoc/v2 v2.0.1
github.com/stretchr/testify v1.8.4
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63
gopkg.in/ini.v1 v1.67.0
gopkg.in/yaml.v2 v2.4.0
mvdan.cc/sh/v3 v3.5.1
gopkg.in/yaml.v3 v3.0.1
mvdan.cc/sh/v3 v3.7.0
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.8.0 // indirect
)
github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ=
github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE=
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/MakeNowJust/heredoc/v2 v2.0.1 h1:rlCHh70XXXv7toz95ajQWOWQnN4WNLt0TdpZYIR/J6A=
github.com/MakeNowJust/heredoc/v2 v2.0.1/go.mod h1:6/2Abh5s+hc3g9nbWLe9ObDIOhaRrqsyY9MWy+4JdRM=
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/frankban/quicktest v1.14.0 h1:+cqqvzZV87b4adx/5ayVOaYZ2CrvM4ejQvUdBzPPUss=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/frankban/quicktest v1.14.5 h1:dfYrrRyLtiqT9GyKXgdh+k4inNeTvmGbuSgZ3lx3GhA=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
golang.org/x/exp v0.0.0-20221212164502-fae10dda9338 h1:OvjRkcNHnf6/W5FZXSxODbxwD+X7fspczG7Jn/xQVD4=
golang.org/x/exp v0.0.0-20221212164502-fae10dda9338/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
github.com/rogpeppe/go-internal v1.10.1-0.20230524175051-ec119421bb97 h1:3RPlVWzZ/PDqmVuf/FKHARG5EMid/tl7cv54Sw/QRVY=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 h1:m64FZMko/V45gv0bNmrNYoDEq8U5YUhetc9cBWKS1TQ=
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63/go.mod h1:0v4NqG35kSWCMzLaMeX+IQrlSnVE/bqGSyC2cz/9Le8=
golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI=
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
mvdan.cc/sh/v3 v3.5.1 h1:hmP3UOw4f+EYexsJjFxvU38+kn+V/s2CclXHanIBkmQ=
mvdan.cc/sh/v3 v3.5.1/go.mod h1:1JcoyAKm1lZw/2bZje/iYKWicU/KMd0rsyJeKHnsK4E=
mvdan.cc/sh/v3 v3.7.0 h1:lSTjdP/1xsddtaKfGg7Myu7DnlHItd3/M2tomOcNNBg=
mvdan.cc/sh/v3 v3.7.0/go.mod h1:K2gwkaesF/D7av7Kxl0HbF5kGOd2ArupNTX3X44+8l8=
// This package is for backwards compatibility. Use
// gitlab.alpinelinux.org/alpine/go/releases instead.
package apkbuild
import "gitlab.alpinelinux.org/alpine/go/apkbuild"
type (
Fix = apkbuild.Fix
FixedVersion = apkbuild.FixedVersion
Secfixes = apkbuild.Secfixes
)
var (
ParseSecfixes = apkbuild.ParseSecfixes
)
// This package is for backwards compatibility. Use
// gitlab.alpinelinux.org/alpine/go/releases instead.
package releases
import "gitlab.alpinelinux.org/alpine/go/releases"
type (
Repo = releases.Repo
Release = releases.Release
ReleaseBranch = releases.ReleaseBranch
Releases = releases.Releases
)
var (
NewFromBuffer = releases.NewFromBuffer
NewFromURL = releases.NewFromURL
Fetch = releases.Fetch
)
// This package is for backwards compatibility. Use
// gitlab.alpinelinux.org/alpine/go/repository instead.
package repository
import "gitlab.alpinelinux.org/alpine/go/repository"
type (
ApkIndex = repository.ApkIndex
Package = repository.Package
Repository = repository.Repository
RepositoryPackage = repository.RepositoryPackage
RepositoryWithIndex = repository.RepositoryWithIndex
)
var (
IndexFromArchive = repository.IndexFromArchive
NewRepositoryFromComponents = repository.NewRepositoryFromComponents
NewRepositoryPackage = repository.NewRepositoryPackage
ParsePackageIndex = repository.ParsePackageIndex
)
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"semanticCommits": "disabled",
"commitMessagePrefix": "deps:",
"commitMessageAction": "update",
"postUpdateOptions": [
"gomodTidy",
"gomodUpdateImportPaths"
]
}
......@@ -14,7 +14,7 @@ import (
"text/template"
"time"
"github.com/MakeNowJust/heredoc"
"github.com/MakeNowJust/heredoc/v2"
)
const apkIndexFilename = "APKINDEX"
......@@ -141,7 +141,7 @@ func ParsePackageIndex(apkIndexUnpacked io.Reader) (packages []*Package, err err
if err != nil {
return nil, fmt.Errorf("cannot parse build time %s: %w", val, err)
}
pkg.BuildTime = time.Unix(i, 0)
pkg.BuildTime = time.Unix(i, 0).UTC()
case "i":
pkg.InstallIf = strings.Split(val, " ")
case "S":
......
......@@ -9,7 +9,7 @@ import (
"strings"
"testing"
"github.com/MakeNowJust/heredoc"
"github.com/MakeNowJust/heredoc/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
......
......@@ -99,6 +99,7 @@ func ParsePackage(apkPackage io.Reader) (*Package, error) {
Size: uint64(expanded.Size),
InstalledSize: uint64(info.Size),
RepoCommit: info.Commit,
BuildTime: time.Unix(info.BuildDate, 0).UTC(),
Replaces: info.Replaces,
}, nil
}
......@@ -113,6 +114,7 @@ type apkInfo struct {
Arch string `ini:"arch"`
Origin string `ini:"origin"`
Commit string `ini:"commit"`
BuildDate int64 `ini:"builddate"`
Maintainer string `ini:"maintainer"`
License string `ini:"license"`
Replaces string `ini:"replaces"`
......
......@@ -3,6 +3,7 @@ package repository
import (
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
......@@ -36,3 +37,24 @@ func TestParsePackage(t *testing.T) {
0x25, 0xe7, 0x4b, 0xa5, 0x83, 0x3c, 0xc8, 0x1b, 0xe6,
0x9c, 0x63}, apk.Checksum)
}
func TestParsePackageWithBuildDate(t *testing.T) {
f, err := os.Open("testdata/hello-wolfi-2.12.1-r0.apk")
require.Nil(t, err)
apk, err := ParsePackage(f)
require.Nil(t, err)
require.Equal(t, "hello-wolfi", apk.Name)
require.Equal(t, "2.12.1-r0", apk.Version)
require.Equal(t, "x86_64", apk.Arch)
require.Equal(t, "the GNU hello world program", apk.Description)
require.Equal(t, "GPL-3.0-or-later", apk.License)
require.Equal(t, time.Unix(12345678, 0).UTC(), apk.BuildTime)
require.Equal(t, []string{"so:ld-linux-x86-64.so.2", "so:libc.so.6"}, apk.Dependencies)
require.Equal(t, uint64(0x11c57), apk.Size)
require.Equal(t, uint64(0x9c45b), apk.InstalledSize)
require.Equal(t, "Q1j9huCmxqWKDR+abKskcY8e/aZMo=", apk.ChecksumString())
require.Equal(t, []byte{
0x8f, 0xd8, 0x6e, 0xa, 0x6c, 0x6a, 0x58, 0xa0, 0xd1, 0xf9,
0xa6, 0xca, 0xb2, 0x47, 0x18, 0xf1, 0xef, 0xda, 0x64, 0xca,
}, apk.Checksum)
}