Skip to content

Commit 8c51720

Browse files
feat(cmd): add changelog flag for saving the generated changelog
1 parent eb86a0c commit 8c51720

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

cmd/semantic-release/main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func loadConfig() *SemRelConfig {
4444
func main() {
4545
token := flag.String("token", os.Getenv("GITHUB_TOKEN"), "github token")
4646
slug := flag.String("slug", os.Getenv("TRAVIS_REPO_SLUG"), "slug of the repository")
47+
changelogFile := flag.String("changelog", "", "creates a changelog file")
4748
ghr := flag.Bool("ghr", false, "create a .ghr file with the parameters for ghr")
4849
noci := flag.Bool("noci", false, "run semantic-release locally")
4950
dry := flag.Bool("dry", false, "do not create release")
@@ -124,8 +125,14 @@ func main() {
124125
exitIfError(errors.New("DRY RUN: no release was created"))
125126
}
126127

128+
logger.Println("generating changelog...")
129+
changelog := semrel.GetChangelog(commits, release, newVer)
130+
if *changelogFile != "" {
131+
exitIfError(ioutil.WriteFile(*changelogFile, []byte(changelog), 0644))
132+
}
133+
127134
logger.Println("creating release...")
128-
exitIfError(repo.CreateRelease(commits, release, newVer, currentBranch))
135+
exitIfError(repo.CreateRelease(changelog, newVer, currentBranch))
129136

130137
if *ghr {
131138
exitIfError(ioutil.WriteFile(".ghr", []byte(fmt.Sprintf("-u %s -r %s v%s", repo.Owner, repo.Repo, newVer.String())), 0644))

semrel.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,8 @@ func (repo *Repository) GetLatestRelease(vrange string) (*Release, error) {
181181
return &Release{lastRelease.SHA, &npver}, nil
182182
}
183183

184-
func (repo *Repository) CreateRelease(commits []*Commit, latestRelease *Release, newVersion *semver.Version, branch string) error {
184+
func (repo *Repository) CreateRelease(changelog string, newVersion *semver.Version, branch string) error {
185185
tag := fmt.Sprintf("v%s", newVersion.String())
186-
changelog := GetChangelog(commits, latestRelease, newVersion)
187186
hasPrerelease := newVersion.Prerelease() != ""
188187
opts := &github.RepositoryRelease{
189188
TagName: &tag,

semrel_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func TestCreateRelease(t *testing.T) {
176176
repo, ts := getNewTestRepo(t)
177177
defer ts.Close()
178178
newVersion, _ := semver.NewVersion("2.0.0")
179-
err := repo.CreateRelease([]*Commit{}, &Release{}, newVersion, "")
179+
err := repo.CreateRelease("", newVersion, "")
180180
if err != nil {
181181
t.Fatal(err)
182182
}

0 commit comments

Comments
 (0)