func generateRelease(config releaseman.Config) {
	fmt.Println()
	log.Infof("=> Adding changes to git...")
	changes, err := git.GetChangedFiles()
	if err != nil {
		log.Fatalf("Failed to get changes, error: %s", err)
	}
	if err := git.Add(changes); err != nil {
		log.Fatalf("Failed to git add, error: %s", err)
	}
	if err := git.Commit(fmt.Sprintf("v%s", config.Release.Version)); err != nil {
		log.Fatalf("Failed to git commit, error: %s", err)
	}

	fmt.Println()
	log.Infof("=> Merging changes into release branch...")
	if err := git.CheckoutBranch(config.Release.ReleaseBranch); err != nil {
		log.Fatalf("Failed to git checkout, error: %s", err)
	}
	mergeCommitMessage := fmt.Sprintf("Merge %s into %s, release: v%s", config.Release.DevelopmentBranch, config.Release.ReleaseBranch, config.Release.Version)
	if err := git.Merge(config.Release.DevelopmentBranch, mergeCommitMessage); err != nil {
		log.Fatalf("Failed to git merge, error: %s", err)
	}

	fmt.Println()
	log.Infof("=> Tagging release branch...")
	if err := git.Tag(config.Release.Version); err != nil {
		log.Fatalf("Failed to git tag, error: %s", err)
	}
	if err := git.CheckoutBranch(config.Release.DevelopmentBranch); err != nil {
		log.Fatalf("Failed to git checkout, error: %s", err)
	}
}
示例#2
0
func ensureCurrentBranch(config releaseman.Config) error {
	currentBranch, err := git.CurrentBranchName()
	if err != nil {
		return err
	}

	if config.Release.DevelopmentBranch != currentBranch {
		if releaseman.IsCIMode {
			return fmt.Errorf("Your current branch (%s), should be the development branch (%s)!", currentBranch, config.Release.DevelopmentBranch)
		}

		log.Warnf("Your current branch (%s), should be the development branch (%s)!", currentBranch, config.Release.DevelopmentBranch)

		fmt.Println()
		checkout, err := goinp.AskForBoolWithDefault(fmt.Sprintf("Would you like to checkout development branch (%s)?", config.Release.DevelopmentBranch), true)
		if err != nil {
			return err
		}

		if !checkout {
			return fmt.Errorf("Current branch should be the development branch (%s)!", config.Release.DevelopmentBranch)
		}

		if err := git.CheckoutBranch(config.Release.DevelopmentBranch); err != nil {
			return err
		}
	}

	return nil
}