Esempio n. 1
0
func validateVersion(current, requiredMin ver.Version, requiredMax *ver.Version) error {
	if current.Compare(&requiredMin) == -1 {
		return fmt.Errorf("Current version (%s) is less then min version (%s)  ", current.String(), requiredMin.String())
	}

	if requiredMax != nil && current.Compare(requiredMax) == 1 {
		return fmt.Errorf("Current version (%s) is greater then max version (%s)  ", current.String(), (*requiredMax).String())
	}

	return nil
}
Esempio n. 2
0
// GitCloneAndCheckoutVersion ...
func GitCloneAndCheckoutVersion(cloneIntoDir, repositoryURL, checkoutVersion string) (*ver.Version, string, error) {
	if err := gitInitWithRemote(cloneIntoDir, repositoryURL); err != nil {
		return nil, "", err
	}

	var version ver.Version

	if checkoutVersion == "" {
		versionTagList, err := GitVersionTags(cloneIntoDir)
		if err != nil {
			return nil, "", fmt.Errorf("Could not get version tag list, error: %s", err)
		}

		if len(versionTagList) == 0 {
			return nil, "", fmt.Errorf("no version tag found")
		}

		versionPtr := versionTagList[len(versionTagList)-1]
		if versionPtr == nil {
			return nil, "", fmt.Errorf("uninitialized version found")
		}

		version = *versionPtr
	} else {
		versionPtr, err := ver.NewVersion(checkoutVersion)
		if err != nil {
			return nil, "", fmt.Errorf("failed to parse version (%s), error: %s", checkoutVersion, err)
		}

		if versionPtr == nil {
			return nil, "", errors.New("failed to parse version (%s), error: nil version")
		}

		version = *versionPtr
	}

	if err := gitCheckout(cloneIntoDir, version.String()); err != nil {
		return nil, "", fmt.Errorf("Could not checkout, err :%s", err)
	}

	hash, err := commitHashOfTag(cloneIntoDir, version.String())
	if err != nil {
		return nil, "", fmt.Errorf("Could get commit hash of tag (%s), err :%s", version.String(), err)
	}

	return &version, hash, nil
}