Skip to content
Commits on Source (22)
......@@ -12,7 +12,7 @@ tests:
linting:
stage: verify
image: golangci/golangci-lint:v1.55-alpine
image: golangci/golangci-lint:v1.56-alpine
script:
- golangci-lint run -v
tags:
......
......@@ -2,14 +2,19 @@
All notable changes to this project will be documented in this file.
## [0.9.0] - 2024-01-17
## [0.10.0] - 2024-03-04
### docs
- Add packages repository to list of projects using this
### version
### Dependencies
- Implement Stringer for token
- Add function to validate versions
- Add version specification
- Update golang.org/x/exp digest to 9212866
- Update golang.org/x/exp digest to 3e424a5
- Update golangci/golangci-lint Docker tag to v1.55
- Update golang.org/x/exp digest to db7319d
## [0.9.0] - 2024-01-17
### repository
......@@ -18,17 +23,6 @@ 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
......@@ -92,11 +86,6 @@ All notable changes to this project will be documented in this file.
## [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
......
......@@ -61,6 +61,7 @@ apk-tools uses.
|----------------------------------------------------------------------|-------------------------------------------------------------------|
| [apkcirkledep](https://gitlab.alpinelinux.org/ptrcnull/apkcircledep) | Report circular dependencies between packages in aports |
| [apkgquery](https://gitlab.alpinelinux.org/kdaudt/apkgquery) | Query aports using an expression language |
| [packages](https://github.com/atlascloud/packages) | Host Alpine package repositories |
## License
......
......@@ -51,7 +51,7 @@ commit_preprocessors = [
commit_parsers = [
{ message = "^(ci|renovate|release):", skip = true },
{ message = "^merge:", skip = true },
{ message = "^deps:", group = "Dependencies" },
{ message = "^deps:", skip = true },
]
# protect breaking changes from being skipped due to matching a skipping commit_parser
protect_breaking_commits = false
......
module gitlab.alpinelinux.org/alpine/go
go 1.19
go 1.21
toolchain go1.21.6
require (
github.com/MakeNowJust/heredoc/v2 v2.0.1
github.com/stretchr/testify v1.8.4
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3
github.com/stretchr/testify v1.9.0
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225
gopkg.in/ini.v1 v1.67.0
gopkg.in/yaml.v3 v3.0.1
mvdan.cc/sh/v3 v3.7.0
mvdan.cc/sh/v3 v3.8.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.2.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
)
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/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0=
github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
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.5 h1:dfYrrRyLtiqT9GyKXgdh+k4inNeTvmGbuSgZ3lx3GhA=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
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.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-20240112132812-db7319d0e0e3 h1:hNQpMuAJe5CtcUqCXaWga3FHu+kQvCqcsoVaQgSV60o=
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08=
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.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.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=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
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.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.7.0 h1:lSTjdP/1xsddtaKfGg7Myu7DnlHItd3/M2tomOcNNBg=
mvdan.cc/sh/v3 v3.7.0/go.mod h1:K2gwkaesF/D7av7Kxl0HbF5kGOd2ArupNTX3X44+8l8=
mvdan.cc/sh/v3 v3.8.0 h1:ZxuJipLZwr/HLbASonmXtcvvC9HXY9d2lXZHnKGjFc8=
mvdan.cc/sh/v3 v3.8.0/go.mod h1:w04623xkgBVo7/IUK89E0g8hBykgEpN0vgOj3RJr6MY=
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["regexManagers:dockerfileVersions"],
"semanticCommits": "disabled",
"commitMessagePrefix": "deps:",
"commitMessageAction": "update",
"postUpdateOptions": [
"gomodTidy",
"gomodUpdateImportPaths"
"prConcurrentLimit": 2,
"postUpdateOptions": ["gomodTidy", "gomodUpdateImportPaths"],
"packageRules": [
{
"matchManagers": ["gomod"],
"matchDepTypes": ["golang"],
"enabled": false
}
]
}
// Package version tokenizes a apk package version using the same algorithm as
// apk-tools uses.
//
// A valid version can be described by the following EBNF specificion:
//
// version = digits , { "." , digits } , [ letter, digits ] , { suffix } , [ revision ] ;
//
// digit = "0" | "1" | "2" | "3"| "4" | "5" | "6" | "7" | "8" | "9" ;
// digits = { digit } ;
// revision = "-r", digit, digits ;
//
// letter = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m"
// | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" ;
//
// suffix = "_" , ( pre-suffix | post-suffix ) , digits ;
//
// pre-suffix = "alpha" | "beta" | "pre" | "rc" ;
// post-suffix = "cvc" | "svn" | "git" | "hg" | "p" ;
package version
// Code generated by "stringer -type=Token"; DO NOT EDIT.
package version
import "strconv"
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[Invalid - -1]
_ = x[DigitOrZero-0]
_ = x[Digit-1]
_ = x[Letter-2]
_ = x[Suffix-3]
_ = x[SuffixDigit-4]
_ = x[RevisionDigit-5]
_ = x[End-6]
}
const _Token_name = "InvalidDigitOrZeroDigitLetterSuffixSuffixDigitRevisionDigitEnd"
var _Token_index = [...]uint8{0, 7, 18, 23, 29, 35, 46, 59, 62}
func (i Token) String() string {
i -= -1
if i < 0 || i >= Token(len(_Token_index)-1) {
return "Token(" + strconv.FormatInt(int64(i+-1), 10) + ")"
}
return _Token_name[_Token_index[i]:_Token_index[i+1]]
}
package version
import (
"bytes"
"slices"
"unicode"
)
var validStateTransitions = map[Token][]Token{
Digit: {Digit, DigitOrZero, Letter, Suffix, End},
DigitOrZero: {DigitOrZero, Letter, Suffix, End},
Suffix: {SuffixDigit, End},
SuffixDigit: {SuffixDigit, End},
Letter: {Digit, Suffix, End},
}
// IsValidWithoutRevision validates the provided version without a revision component.
func IsValidWithoutRevision(version string) bool {
v := Version(version)
nv := &v
t := Digit
var pt Token
componentLength := 0
for t != End {
pt = t
t, nv = nv.NextToken(t)
tokenRune := []rune(*nv)
switch t {
case Digit:
// '-' is considered to be a digit, but only valid when part of the revision
if (*nv)[0] == '-' {
return false
}
componentLength++
case Suffix:
var suffix bytes.Buffer
for _, r := range tokenRune {
if unicode.IsLower(r) {
suffix.WriteRune(r)
} else {
pt, t = Suffix, SuffixDigit
break
}
}
ov := Version(tokenRune[suffix.Len():])
nv = &ov
if !isValidSuffix(suffix.String()) {
return false
}
}
if !slices.Contains(validStateTransitions[pt], t) {
return false
}
if pt == Digit && t != Digit {
if componentLength >= 18 {
return false
}
componentLength = 0
}
if len(*nv) > 0 &&
t != DigitOrZero &&
t != RevisionDigit &&
!(pt == Suffix && t == SuffixDigit) {
a := Version((*nv)[1:])
nv = &a
}
}
return true
}
func isValidSuffix(suffix string) bool {
if len(suffix) == 0 {
return false
}
if !slices.Contains(preSuffixes, suffix) && !slices.Contains(postSuffixes, suffix) {
return false
}
return true
}
package version
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
var validVersions = [][]string{
{"1.2.3_git12341233", "GitSuffix"},
{"0.01", "LeadingZero"},
{"0", "SingleNumber"},
{"0.0", "TwoComponents"},
{"0.0.0", "ThreeComponents"},
{"0.0.0.0", "FourComponents"},
{"1.02.3", "LeadingZero"},
{"1.2.345123", "LongerComponent"},
{"1.2.3_hg1212321", "HGSuffix"},
{"1.2.3_svn1231231", "SVNSuffix"},
{"1.2.3_p4", "PatchSuffix"},
{"1.2.3a", "SuffiXLetter"},
{"1.2.3c1", "SuffixLetterWithNumber"},
{"1.2.3_rc1", "RCSuffixWithNumber"},
{"1.2.3_alpha", "SuffixWithoutNumber"},
{"1.2.3_alpha3", "AlphaSuffixWithNumber"},
{"1.2.3_beta5", "BetaSuffixWithNumber"},
{"1.2.3_pre2", "PreSuffixWithNumber"},
{"a", "SingleLetter"},
{"_pre0", "StartWithSuffix"},
}
var invalidVersions = [][]string{
{"ab", "TwoConsecutiveLetters"},
{"1git", "SufixWithoutUnderscore"},
{"1_2", "SuffixWithoutType"},
{"1-2", "RevisionWithoutLetter"},
{"1_a", "LetterWithUnderscoreSeparator"},
{"1__pre", "DoubleUnderscore"},
{"1_pre_3", "UnderscoreSuffixSeparator"},
{"1_pre.3", "SuffixInBetween"},
{"123123123123123122", "SingleNumericComponentTooLong"},
{"1.2a.3", "LetterInBetween"},
}
func TestIsValidWithValidCases(t *testing.T) {
for _, subtest := range validVersions {
t.Run(subtest[1], func(t *testing.T) {
require.True(t, IsValidWithoutRevision(subtest[0]), fmt.Sprintf("'%s' should be a valid version", subtest[0]))
})
}
}
func TestIsValidWithInvalidCases(t *testing.T) {
for _, subtest := range invalidVersions {
t.Run(subtest[1], func(t *testing.T) {
require.False(t, IsValidWithoutRevision(subtest[0]), fmt.Sprintf("'%s' is not a valid version", subtest[0]))
})
}
}
func ExampleIsValidWithoutRevision_valid() {
fmt.Println(IsValidWithoutRevision("1.2.4_git123"))
// Output: true
}
func ExampleIsValidWithoutRevision_invalid() {
fmt.Println(IsValidWithoutRevision("1.2.4_5"))
// Output: false
}
// Package version tokenizes a apk package version using the same algorithm as
// apk-tools uses.
//
// The version specification is based on what
package version
import (
......@@ -9,6 +5,8 @@ import (
"unicode"
)
//go:generate go run golang.org/x/tools/cmd/stringer@latest -type=Token
type Token int
const (
......