Example #1
0
func semverEqual(a, b string) (bool, error) {
	if a == b {
		return true, nil
	}
	aVer, err := semv.Parse(a)
	if err != nil {
		return false, err
	}
	bVer, err := semv.Parse(b)
	if err != nil {
		return false, err
	}
	return aVer.Equals(bVer), nil
}
Example #2
0
func nearestVersion(tags []Tag) semv.Version {
	for _, t := range tags {
		v, err := semv.Parse(t.Name)
		if err == nil {
			return v
		}
	}
	return semv.MustParse("0.0.0-unversioned")
}
Example #3
0
// NewSourceID attempts to create a new SourceID from strings representing the
// separate components.
func NewSourceID(repo, offset, version string) (SourceID, error) {
	v, err := semv.Parse(version)
	if err != nil {
		return SourceID{}, err
	}
	return SourceID{
		Location: SourceLocation{
			Repo: repo, Dir: offset,
		},
		Version: v,
	}, nil
}
Example #4
0
func TestCanonName(t *testing.T) {
	assert := assert.New(t)

	vers, _ := semv.Parse("1.2.3-test+thing")
	dep := Deployment{
		SourceID: SourceID{
			Location: SourceLocation{
				Repo: "one",
				Dir:  "two",
			},
			Version: vers,
		},
	}
	str := dep.SourceID.Location.String()
	assert.Regexp("one", str)
	assert.Regexp("two", str)
}
Example #5
0
// Version returns the SourceID.
func (sc *SourceContext) Version() SourceID {
	v, err := semv.Parse(sc.NearestTagName)
	if err != nil {
		v = nearestVersion(sc.Tags)
	}
	// Append revision ID.
	v = semv.MustParse(v.Format("M.m.p-?") + "+" + sc.Revision)
	sv := SourceID{
		Location: SourceLocation{
			Repo: sc.RemoteURL,
			Dir:  sc.OffsetDir,
		},
		Version: v,
	}
	Log.Debug.Printf("Version: % #v", sv)
	return sv
}
Example #6
0
func sourceIDFromChunks(source string, chunks []string) (SourceID, error) {
	if len(chunks[0]) == 0 {
		return SourceID{}, &MissingRepo{source}
	}
	repoURL := chunks[0]
	version, err := semv.Parse(string(chunks[1]))
	if err != nil {
		return SourceID{}, err
	}
	repoOffset := ""
	if len(chunks) > 2 {
		repoOffset = chunks[2]
	}
	return SourceID{
		Location: SourceLocation{
			Dir:  repoOffset,
			Repo: repoURL,
		},
		Version: version,
	}, nil
}
Example #7
0
func makeDepl(repo string, num int) *Deployment {
	version, _ := semv.Parse("1.1.1-latest")
	owners := OwnerSet{}
	owners.Add("judson")
	return &Deployment{
		SourceID: SourceID{
			Location: SourceLocation{
				Repo: repo,
			},
			Version: version,
		},
		DeployConfig: DeployConfig{
			NumInstances: num,
			Env:          map[string]string{},
			Resources: map[string]string{
				"cpu":    ".1",
				"memory": "100",
				"ports":  "1",
			},
		},
		Owners: owners,
	}
}
Example #8
0
func sourceIDFromValues(qv *QueryValues) (sous.SourceID, error) {
	var r, o, vs string
	var v semv.Version
	var err error
	var sid sous.SourceID

	return sid, firsterr.Returned(
		func() error { r, err = qv.Single("repo"); return err },
		func() error { o, err = qv.Single("offset", ""); return err },
		func() error { vs, err = qv.Single("version", ""); return err },
		func() error { v, err = semv.Parse(vs); return err },
		func() error {
			sid = sous.SourceID{
				Location: sous.SourceLocation{
					Repo: r,
					Dir:  o,
				},
				Version: v,
			}
			return nil
		},
	)
}
Example #9
0
// Validate checks that the Config is well formed
func (c *BuildConfig) Validate() error {
	if _, ve := semv.Parse(c.Tag); ve != nil {
		return fmt.Errorf("semver git tag required.  invalid tag: %q", c.Tag)
	}
	return nil
}