mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 12:08:58 +01:00
docs: Bug fix: Sorting semantic versions
This commit is contained in:
parent
189519b1f0
commit
40847259c8
41
_docs/gen.go
41
_docs/gen.go
@ -25,6 +25,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
@ -48,14 +49,50 @@ func majorMinor(ver string) string {
|
|||||||
return t[0] + "." + t[1]
|
return t[0] + "." + t[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reSemVer indicates the regexp for semantic versioning (https://semver.org/)
|
||||||
|
//
|
||||||
|
// reSemVer ignores periods in pre-release version so far.
|
||||||
|
var reSemVer = regexp.MustCompile(`^v(\d+)\.(\d+)\.(\d+)(-[0-9a-zA-Z-]+)?$`)
|
||||||
|
|
||||||
|
func mustAtoi(str string) int {
|
||||||
|
v, err := strconv.Atoi(str)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
b, err := exec.Command("git", "tag").Output()
|
b, err := exec.Command("git", "tag").Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
vers := strings.Split(strings.TrimSpace(string(b)), "\n")
|
vers := strings.Split(strings.TrimSpace(string(b)), "\n")
|
||||||
// TODO: Sort by a semantic version lib
|
sort.Slice(vers, func(a, b int) bool {
|
||||||
sort.Strings(vers)
|
ma := reSemVer.FindStringSubmatch(vers[a])
|
||||||
|
mb := reSemVer.FindStringSubmatch(vers[b])
|
||||||
|
|
||||||
|
if majorA, majorB := mustAtoi(ma[1]), mustAtoi(mb[1]); majorA != majorB {
|
||||||
|
return majorA < majorB
|
||||||
|
}
|
||||||
|
if minorA, minorB := mustAtoi(ma[2]), mustAtoi(mb[2]); minorA != minorB {
|
||||||
|
return minorA < minorB
|
||||||
|
}
|
||||||
|
if patchA, patchB := mustAtoi(ma[3]), mustAtoi(mb[3]); patchA != patchB {
|
||||||
|
return patchA < patchB
|
||||||
|
}
|
||||||
|
if len(ma) == 4 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if len(mb) == 4 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// To be exact, sorting pre-release tokens must consider numerics identifiers, but we ignore this
|
||||||
|
// here. See https://semver.org/#spec-item-11
|
||||||
|
preA, preB := ma[4], mb[4]
|
||||||
|
return preA < preB
|
||||||
|
})
|
||||||
|
|
||||||
devVers := []string{}
|
devVers := []string{}
|
||||||
rcVers := []string{}
|
rcVers := []string{}
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
<dd class="col-9">v1.9.0-rc1</dd>
|
<dd class="col-9">v1.9.0-rc1</dd>
|
||||||
|
|
||||||
<dt class="col-3 text-right">Development Version</dt>
|
<dt class="col-3 text-right">Development Version</dt>
|
||||||
<dd class="col-9">v1.9.0-alpha</dd>
|
<dd class="col-9">v1.10.0-alpha</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
<h2>Featured Projects</h2>
|
<h2>Featured Projects</h2>
|
||||||
|
Loading…
Reference in New Issue
Block a user