Ejemplo n.º 1
0
func isUpdateAvailable(stepInfo stepmanModels.StepInfoModel) bool {
	if stepInfo.Latest == "" {
		return false
	}

	res, err := versions.CompareVersions(stepInfo.Version, stepInfo.Latest)
	if err != nil {
		log.Debugf("Failed to compare versions, err: %s", err)
	}

	return (res == 1)
}
Ejemplo n.º 2
0
func addStepVersionToStepGroup(step models.StepModel, version string, stepGroup models.StepGroupModel) (models.StepGroupModel, error) {
	if stepGroup.LatestVersionNumber != "" {
		r, err := versions.CompareVersions(stepGroup.LatestVersionNumber, version)
		if err != nil {
			return models.StepGroupModel{}, err
		}
		if r == 1 {
			stepGroup.LatestVersionNumber = version
		}
	} else {
		stepGroup.LatestVersionNumber = version
	}
	stepGroup.Versions[version] = step
	return stepGroup, nil
}
Ejemplo n.º 3
0
func addStepVersionToStepGroup(step models.StepModel, version string, stepGroup models.StepGroupModel) (models.StepGroupModel, error) {
	if stepGroup.LatestVersionNumber != "" {
		r, err := versions.CompareVersions(stepGroup.LatestVersionNumber, version)
		if err != nil {
			return models.StepGroupModel{}, err
		}
		if r == 1 {
			stepGroup.LatestVersionNumber = version
		}
	} else {
		stepGroup.LatestVersionNumber = version
	}
	log.Debugf("SetGroup: %#v, versionParam: %#v, stepParam: %#v", stepGroup, version, step)
	stepGroup.Versions[version] = step
	return stepGroup, nil
}
Ejemplo n.º 4
0
// InstallPlugin ...
func InstallPlugin(bitriseVersion, pluginSource, pluginName, pluginType string) (string, error) {
	checkMinMaxVersion := func(requiredMin, requiredMax, current string) (bool, error) {
		if requiredMin != "" {
			// 1 if version 2 is greater then version 1, -1 if not
			greater, err := versions.CompareVersions(current, requiredMin)
			if err != nil {
				return false, err
			}
			if greater == 1 {
				return false, fmt.Errorf("Required min version (%s) - current (%s)", requiredMin, current)
			}
		}

		if requiredMax != "" {
			greater, err := versions.CompareVersions(requiredMax, current)
			if err != nil {
				return false, err
			}
			if greater == 1 {
				return false, fmt.Errorf("Allowed max version (%s) - current (%s)", requiredMax, current)
			}
		}

		return true, nil
	}

	pluginPath, err := GetPluginPath(pluginName, pluginType)
	if err != nil {
		return "", err
	}

	if err := DownloadPluginFromURL(pluginSource, pluginPath); err != nil {
		return "", err
	}

	if err := os.Chmod(pluginPath, 0777); err != nil {
		return "", err
	}

	plugin, err := GetPlugin(pluginName, pluginType)
	if err != nil {
		return "", err
	}

	messageFromPlugin, err := RunPlugin(bitriseVersion, plugin, []string{"requirements"})
	if err != nil {
		return "", err
	}
	if messageFromPlugin != "" {
		log.Infoln("=> Checking plugin requirements...")
		log.Debugf("requirements messageFromPlugin: %s", messageFromPlugin)

		envmanVersion, err := bitrise.EnvmanVersion()
		if err != nil {
			return "", err
		}

		stepmanVersion, err := bitrise.StepmanVersion()
		if err != nil {
			return "", err
		}

		currentVersionMap := map[string]string{
			"bitrise": bitriseVersion,
			"envman":  envmanVersion,
			"stepman": stepmanVersion,
		}

		type Requirement struct {
			ToolName   string
			MinVersion string
			MaxVersion string
		}

		var requirements []Requirement
		if err := json.Unmarshal([]byte(messageFromPlugin), &requirements); err != nil {
			return "", err
		}

		for _, requirement := range requirements {
			toolName := requirement.ToolName
			minVersion := requirement.MinVersion
			maxVersion := requirement.MaxVersion
			currentVersion := currentVersionMap[toolName]

			ok, err := checkMinMaxVersion(minVersion, maxVersion, currentVersion)
			if err != nil {
				return "", fmt.Errorf("%s requirements failed, err: %s", toolName, err)
			}

			if !ok {
				log.Infof(" (i) %s min version: %s / max version: %s - current  version: %s", toolName, minVersion, maxVersion, bitriseVersion)
			}
		}
	}

	printableName := PrintableName(pluginName, pluginType)
	return printableName, nil
}