You've already forked go-semantic-release
feat(changelog): prepend a changelog to a file as default, use --overwrite to overwrite the whole file
BREAKING CHANGE: changelog command will now prepend changelogs to the changelog-file
This commit is contained in:
committed by
Felix Wiedmann
parent
155a16ddd5
commit
a054cf9a60
@@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
changelogCmd.Flags().Bool("checks", false, "Check for missing values and envs")
|
changelogCmd.Flags().Bool("checks", false, "Check for missing values and envs")
|
||||||
|
changelogCmd.Flags().Bool("overwrite", false, "Overwrite the content of the changelog. Default is to prepend the new changelog to the existing file.")
|
||||||
changelogCmd.Flags().StringP("out", "o", "CHANGELOG.md", "Name of the file")
|
changelogCmd.Flags().StringP("out", "o", "CHANGELOG.md", "Name of the file")
|
||||||
rootCmd.AddCommand(changelogCmd)
|
rootCmd.AddCommand(changelogCmd)
|
||||||
}
|
}
|
||||||
@@ -31,6 +32,11 @@ var changelogCmd = &cobra.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
overwrite, err := cmd.Flags().GetBool("overwrite")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
file, err := cmd.Flags().GetString("out")
|
file, err := cmd.Flags().GetString("out")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -61,7 +67,6 @@ var changelogCmd = &cobra.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
return s.WriteChangeLog(generatedChangelog.Content, file, overwrite)
|
||||||
return s.WriteChangeLog(generatedChangelog.Content, file)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ package semanticrelease
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Nightapes/go-semantic-release/internal/integrations"
|
"os"
|
||||||
"io/ioutil"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/integrations"
|
||||||
|
|
||||||
"github.com/Masterminds/semver"
|
"github.com/Masterminds/semver"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
@@ -194,8 +195,21 @@ func (s *SemanticRelease) GetChangelog(releaseVersion *shared.ReleaseVersion) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WriteChangeLog writes changelog content to the given file
|
// WriteChangeLog writes changelog content to the given file
|
||||||
func (s *SemanticRelease) WriteChangeLog(changelogContent, file string) error {
|
func (s *SemanticRelease) WriteChangeLog(changelogContent, file string, overwrite bool) error {
|
||||||
return ioutil.WriteFile(file, []byte(changelogContent), 0644)
|
newContent := make([]byte, 0)
|
||||||
|
newContent = append(newContent, []byte(changelogContent)...)
|
||||||
|
|
||||||
|
// only prepend the new changelog content if the the given file already exists
|
||||||
|
_, err := os.Stat(file)
|
||||||
|
if !overwrite && err == nil {
|
||||||
|
content, err := os.ReadFile(file)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
newContent = append(newContent, []byte("\n---\n\n")...)
|
||||||
|
newContent = append(newContent, content...)
|
||||||
|
}
|
||||||
|
return os.WriteFile(file, newContent, 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release publish release to provider
|
// Release publish release to provider
|
||||||
|
|||||||
Reference in New Issue
Block a user