Handle rc versions

Versions like `1.2.3-rc.4` will now be properly handled by the Genesis
Index, allowing CI pipelines to push things out for Genesis pipelines to
consume and exercise.

Fixes #7
This commit is contained in:
James Hunt 2016-10-29 16:39:09 -04:00 committed by James Hunt
parent f60b5cc335
commit c4e5ab5ada
2 changed files with 40 additions and 26 deletions

View File

@ -74,30 +74,7 @@ func Database(driver, dsn string) (*db.DB, error) {
return nil
}) // }}}
s.Version(2, func(d *db.DB) error { // {{{
tables := []string{"release_versions", "stemcell_versions"}
for _, table := range tables {
r, err := d.Query(fmt.Sprintf(`SELECT name, version FROM %s`, table))
if err != nil {
return err
}
for r.Next() {
var name, version string
if err = r.Scan(&name, &version); err != nil {
return err
}
n, err := vnum(version)
if err != nil {
return err
}
err = d.Exec(fmt.Sprintf(`UPDATE %s SET vnum = $1 WHERE name = $2 AND version = $3`, table),
n, name, version)
if err != nil {
return err
}
}
}
/* this migration is now done every time, since its idempotent */
return nil
}) // }}}
@ -106,5 +83,29 @@ func Database(driver, dsn string) (*db.DB, error) {
return nil, err
}
// Always recalculate vnums because it's cheap and easy
tables := []string{"release_versions", "stemcell_versions"}
for _, table := range tables {
r, err := d.Query(fmt.Sprintf(`SELECT name, version FROM %s`, table))
if err != nil {
return nil, err
}
for r.Next() {
var name, version string
if err = r.Scan(&name, &version); err != nil {
return nil, err
}
n, err := vnum(version)
if err != nil {
return nil, err
}
err = d.Exec(fmt.Sprintf(`UPDATE %s SET vnum = $1 WHERE name = $2 AND version = $3`, table),
n, name, version)
if err != nil {
return nil, err
}
}
}
return d, nil
}

17
util.go
View File

@ -110,20 +110,33 @@ func authed(w http.ResponseWriter, r *http.Request) bool {
}
func vnum(v string) (uint64, error) {
var rc, n uint64
var err error
re := regexp.MustCompile(`^(.+)[-.]rc\.(\d+)$`)
if m := re.FindStringSubmatch(v); len(m) == 3 {
v = m[1]
rc, err = strconv.ParseUint(m[2], 10, 64)
if err != nil {
log.Debugf("vnum had an issue with '%s': %s", v, err)
return n, err
}
}
sem := strings.Split(v, ".")
for len(sem) < 3 {
sem = append(sem, "0")
}
var n uint64 = 0
for i := 0; i < 3; i++ {
u, err := strconv.ParseUint(sem[i], 10, 64)
if err != nil {
log.Debugf("vnum had an issue with '%s': %s", v, err)
return n, err
}
n = n*1000000 + u
n = n*10000 + u
}
n = n*10000 + rc
return n, nil
}