func generateChangelog(config releaseman.Config) {
	taggedCommits, err := git.VersionTaggedCommits()
	if err != nil {
		log.Fatalf("Failed to get tagged commits, error: %#v", err)
	}

	var startCommitPtr *git.CommitModel
	if len(taggedCommits) > 0 {
		startCommitPtr = &(taggedCommits[0])
	}

	relevantTags := taggedCommits

	appendChangelog := false

	if config.Changelog.Path != "" {
		if exist, err := pathutil.IsPathExists(config.Changelog.Path); err != nil {
			log.Fatalf("Failed to check if path exist, error: %#v", err)
		} else if exist {
			if len(taggedCommits) > 0 {
				lastTaggedCommit := taggedCommits[len(taggedCommits)-1]

				startCommitPtr = &lastTaggedCommit

				relevantTags = []git.CommitModel{lastTaggedCommit}

				appendChangelog = true
			}
		}
	}

	printCollectingCommits(startCommitPtr, config.Release.Version)

	fmt.Println()
	log.Infof("=> Generating Changelog...")
	commits, err := git.GetCommitsFrom(startCommitPtr)
	if err != nil {
		log.Fatalf("Failed to get commits, error: %#v", err)
	}
	if err := releaseman.WriteChangelog(commits, relevantTags, config, appendChangelog); err != nil {
		log.Fatalf("Failed to write Changelog, error: %#v", err)
	}
}
Beispiel #2
0
func fillVersion(config releaseman.Config, c *cli.Context) (releaseman.Config, error) {
	var err error

	tags, err := git.VersionTaggedCommits()
	if err != nil {
		return releaseman.Config{}, err
	}

	currentVersion := ""
	if c.IsSet(GetVersionScriptKey) {
		log.Infof("Get version script provided")
		versionScript := c.String(GetVersionScriptKey)
		parts := strings.Fields(versionScript)
		head := parts[0]
		parts = parts[1:len(parts)]

		outBytes, err := exec.Command(head, parts...).CombinedOutput()
		if err != nil {
			return releaseman.Config{}, fmt.Errorf("Failed to run bump script, out: %s, error: %#v", string(outBytes), err)
		}
		versionStr := string(outBytes)
		versionStr = git.Strip(versionStr)

		currentVersion = versionStr

	} else if len(tags) > 0 {
		currentVersion = tags[len(tags)-1].Tag
	}

	if currentVersion != "" {
		log.Infof("Current version: %s", currentVersion)

		segmentIdx, err := versionSegmentIdx(PatchKey)
		if err != nil {
			return releaseman.Config{}, err
		}

		config.Release.Version, err = bumpedVersion(currentVersion, segmentIdx)
		if err != nil {
			return releaseman.Config{}, err
		}
	}

	if c.IsSet(BumpVersionKey) {
		if currentVersion == "" {
			return releaseman.Config{}, errors.New("Current version not found, nothing to bump")
		}

		segmentIdx, err := versionSegmentIdx(c.String(BumpVersionKey))
		if err != nil {
			return releaseman.Config{}, err
		}

		log.Infof("Bumping version %s part", c.String(BumpVersionKey))

		config.Release.Version, err = bumpedVersion(currentVersion, segmentIdx)
		if err != nil {
			return releaseman.Config{}, err
		}
	} else if c.IsSet(VersionKey) {
		config.Release.Version = c.String(VersionKey)
	}

	if config.Release.Version == "" {
		if releaseman.IsCIMode {
			return releaseman.Config{}, errors.New("Missing required input: release version")
		}

		if len(tags) > 0 {
			fmt.Println()
			log.Infof("Your previous tag: %s", tags[len(tags)-1].Tag)
		}

		version, err := askForReleaseVersion()
		if err != nil {
			return releaseman.Config{}, err
		}

		for _, taggedCommit := range tags {
			if taggedCommit.Tag == version {
				return releaseman.Config{}, fmt.Errorf("Tag (%s) already exist", version)
			}
		}

		config.Release.Version = version
	}

	if config.Release.Version == "" {
		return releaseman.Config{}, errors.New("Missing required input: release version")
	}

	if err := validateVersion(config.Release.Version); err != nil {
		return releaseman.Config{}, err
	}

	return config, nil
}