weldr: bump blueprint version
According to the same rules as lorax-compposer: https://weldr.io/lorax/lorax-composer.html#blueprints
This commit is contained in:
parent
b6307cafd5
commit
94bfcc518c
3 changed files with 55 additions and 1 deletions
|
|
@ -6,11 +6,14 @@ import (
|
|||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
|
@ -330,6 +333,21 @@ func (s *Store) GetBlueprintChanges(name string) []blueprint.Change {
|
|||
return changes
|
||||
}
|
||||
|
||||
func bumpVersion(str string) string {
|
||||
v := [3]uint64{}
|
||||
fields := strings.SplitN(str, ".", 3)
|
||||
for i := 0; i < len(fields); i++ {
|
||||
if n, err := strconv.ParseUint(fields[i], 10, 64); err == nil {
|
||||
v[i] = n
|
||||
} else {
|
||||
// don't touch strings with invalid versions
|
||||
return str
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%d.%d.%d", v[0], v[1], v[2] + 1)
|
||||
}
|
||||
|
||||
func (s *Store) PushBlueprint(bp blueprint.Blueprint, commitMsg string) {
|
||||
s.change(func() error {
|
||||
hash := sha1.New()
|
||||
|
|
@ -352,6 +370,12 @@ func (s *Store) PushBlueprint(bp blueprint.Blueprint, commitMsg string) {
|
|||
s.BlueprintsChanges[bp.Name] = make(map[string]blueprint.Change)
|
||||
}
|
||||
s.BlueprintsChanges[bp.Name][commit] = change
|
||||
|
||||
if old, ok := s.Blueprints[bp.Name]; ok {
|
||||
if bp.Version == "" || bp.Version == old.Version {
|
||||
bp.Version = bumpVersion(old.Version)
|
||||
}
|
||||
}
|
||||
s.Blueprints[bp.Name] = bp
|
||||
return nil
|
||||
})
|
||||
|
|
|
|||
30
internal/store/store_test.go
Normal file
30
internal/store/store_test.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package store
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBumpVersion(t *testing.T) {
|
||||
cases := []struct {
|
||||
Version string
|
||||
Expected string
|
||||
}{
|
||||
{"", ""},
|
||||
{"0", "0.0.1"},
|
||||
{"0.0", "0.0.1"},
|
||||
{"0.0.0", "0.0.1"},
|
||||
{"2.1.3", "2.1.4"},
|
||||
|
||||
// don't touch invalid version strings
|
||||
{"0.0.0.0", "0.0.0.0"},
|
||||
{"0.a.0", "0.a.0"},
|
||||
{"foo", "foo"},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
result := bumpVersion(c.Version)
|
||||
if result != c.Expected {
|
||||
t.Errorf("bumpVersion(%#v) is expected to return %#v, but instead returned %#v", c.Version, c.Expected, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -184,7 +184,7 @@ func TestBlueprintsFreeze(t *testing.T) {
|
|||
ExpectedStatus int
|
||||
ExpectedJSON string
|
||||
}{
|
||||
{rpmmd_mock.BaseFixture, "/api/v0/blueprints/freeze/test", http.StatusOK, `{"blueprints":[{"blueprint":{"name":"test","description":"Test","version":"0.0.0","packages":[{"name":"dep-package1","version":"1.33-2.fc30.x86_64"}],"modules":[],"groups":[]}}],"errors":[]}`},
|
||||
{rpmmd_mock.BaseFixture, "/api/v0/blueprints/freeze/test", http.StatusOK, `{"blueprints":[{"blueprint":{"name":"test","description":"Test","version":"0.0.1","packages":[{"name":"dep-package1","version":"1.33-2.fc30.x86_64"}],"modules":[],"groups":[]}}],"errors":[]}`},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue