You've already forked go-semantic-release
feat(changelog): add npm helper text to changelog
This commit is contained in:
committed by
Felix Wiedmann
parent
c7d6c7cc7b
commit
3bc68d9794
@@ -32,9 +32,9 @@ introduced by commit:
|
|||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ end -}}`
|
{{ end -}}`
|
||||||
const defaultCommitListSubTemplate string = `{{ define "commitList" }}` + defaultCommitList + "{{ end }}"
|
const defaultCommitListSubTemplate = `{{ define "commitList" }}` + defaultCommitList + "{{ end }}"
|
||||||
const defaultChangelogTitle string = `v{{.Version}} ({{.Now.Format "2006-01-02"}})`
|
const defaultChangelogTitle = `v{{.Version}} ({{.Now.Format "2006-01-02"}})`
|
||||||
const defaultChangelog string = `# v{{$.Version}} ({{.Now.Format "2006-01-02"}})
|
const defaultChangelog = `# v{{$.Version}} ({{.Now.Format "2006-01-02"}})
|
||||||
{{ template "commitList" .CommitsContent -}}
|
{{ template "commitList" .CommitsContent -}}
|
||||||
|
|
||||||
{{ if .HasDocker}}
|
{{ if .HasDocker}}
|
||||||
@@ -50,11 +50,26 @@ or
|
|||||||
|
|
||||||
{{$.Backtick}}docker run {{.DockerRepository}}:latest{{$.Backtick}}
|
{{$.Backtick}}docker run {{.DockerRepository}}:latest{{$.Backtick}}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
|
{{ end -}}
|
||||||
|
|
||||||
|
{{ if .HasNPM}}
|
||||||
|
## NodeJS Package
|
||||||
|
|
||||||
|
New NodeJS package is released under [{{.NPMPackageName}}]({{.NPMRepository}})
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
|
||||||
|
{{$.Backtick}}yarn add {{.NPMPackageName}}@{{.Version}}{{$.Backtick}}
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
{{$.Backtick}}npm install -save {{.NPMPackageName}}@{{.Version}}{{$.Backtick}}
|
||||||
|
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
`
|
`
|
||||||
|
|
||||||
type changelogContent struct {
|
type changelogContent struct {
|
||||||
Commits string
|
Commits string
|
||||||
CommitsContent commitsContent
|
CommitsContent commitsContent
|
||||||
Version string
|
Version string
|
||||||
Now time.Time
|
Now time.Time
|
||||||
@@ -62,6 +77,10 @@ type changelogContent struct {
|
|||||||
HasDocker bool
|
HasDocker bool
|
||||||
HasDockerLatest bool
|
HasDockerLatest bool
|
||||||
DockerRepository string
|
DockerRepository string
|
||||||
|
HasNPM bool
|
||||||
|
IsYarn bool
|
||||||
|
NPMRepository string
|
||||||
|
NPMPackageName string
|
||||||
}
|
}
|
||||||
|
|
||||||
type commitsContent struct {
|
type commitsContent struct {
|
||||||
@@ -130,13 +149,16 @@ func (c *Changelog) GenerateChangelog(templateConfig shared.ChangelogTemplateCon
|
|||||||
}
|
}
|
||||||
|
|
||||||
changelogContent := changelogContent{
|
changelogContent := changelogContent{
|
||||||
CommitsContent: commitsContent,
|
CommitsContent: commitsContent,
|
||||||
Version: templateConfig.Version,
|
Version: templateConfig.Version,
|
||||||
Now: c.releaseTime,
|
Now: c.releaseTime,
|
||||||
Backtick: "`",
|
Backtick: "`",
|
||||||
HasDocker: c.config.Changelog.Docker.Repository != "",
|
HasDocker: c.config.Changelog.Docker.Repository != "",
|
||||||
HasDockerLatest: c.config.Changelog.Docker.Latest,
|
HasDockerLatest: c.config.Changelog.Docker.Latest,
|
||||||
DockerRepository: c.config.Changelog.Docker.Repository,
|
DockerRepository: c.config.Changelog.Docker.Repository,
|
||||||
|
HasNPM: c.config.Changelog.NPM.PackageName != "",
|
||||||
|
NPMPackageName: c.config.Changelog.NPM.PackageName,
|
||||||
|
NPMRepository: c.config.Changelog.NPM.Repository,
|
||||||
}
|
}
|
||||||
|
|
||||||
chglogTemplate := defaultCommitListSubTemplate + defaultChangelog
|
chglogTemplate := defaultCommitListSubTemplate + defaultChangelog
|
||||||
@@ -168,8 +190,8 @@ func (c *Changelog) GenerateChangelog(templateConfig shared.ChangelogTemplateCon
|
|||||||
log.Tracef("Commits %s", renderedCommitList)
|
log.Tracef("Commits %s", renderedCommitList)
|
||||||
changelogContent.Commits = renderedCommitList
|
changelogContent.Commits = renderedCommitList
|
||||||
|
|
||||||
extraFuncMap := template.FuncMap {
|
extraFuncMap := template.FuncMap{
|
||||||
"commitUrl": func() string {return templateConfig.CommitURL},
|
"commitUrl": func() string { return templateConfig.CommitURL },
|
||||||
}
|
}
|
||||||
log.Debugf("Render changelog")
|
log.Debugf("Render changelog")
|
||||||
renderedContent, err := generateTemplate(chglogTemplate, changelogContent, extraFuncMap)
|
renderedContent, err := generateTemplate(chglogTemplate, changelogContent, extraFuncMap)
|
||||||
@@ -180,10 +202,10 @@ func (c *Changelog) GenerateChangelog(templateConfig shared.ChangelogTemplateCon
|
|||||||
func generateTemplate(text string, values interface{}, extraFuncMap template.FuncMap) (string, error) {
|
func generateTemplate(text string, values interface{}, extraFuncMap template.FuncMap) (string, error) {
|
||||||
|
|
||||||
funcMap := template.FuncMap{
|
funcMap := template.FuncMap{
|
||||||
"replace": replace,
|
"replace": replace,
|
||||||
"lower": lower,
|
"lower": lower,
|
||||||
"upper": upper,
|
"upper": upper,
|
||||||
"capitalize": capitalize,
|
"capitalize": capitalize,
|
||||||
"addPrefixToLines": addPrefixToLines,
|
"addPrefixToLines": addPrefixToLines,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func TestChangelog(t *testing.T) {
|
|||||||
Tag: "feat",
|
Tag: "feat",
|
||||||
TagString: "Features",
|
TagString: "Features",
|
||||||
Print: true,
|
Print: true,
|
||||||
Subject: "my first commit",
|
Subject: "my first commit",
|
||||||
MessageBlocks: map[string][]shared.MessageBlock{},
|
MessageBlocks: map[string][]shared.MessageBlock{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -66,7 +66,7 @@ func TestChangelog(t *testing.T) {
|
|||||||
Tag: "feat",
|
Tag: "feat",
|
||||||
TagString: "Features",
|
TagString: "Features",
|
||||||
Print: true,
|
Print: true,
|
||||||
Subject: "my first commit",
|
Subject: "my first commit",
|
||||||
MessageBlocks: map[string][]shared.MessageBlock{},
|
MessageBlocks: map[string][]shared.MessageBlock{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -92,7 +92,7 @@ func TestChangelog(t *testing.T) {
|
|||||||
Tag: "feat",
|
Tag: "feat",
|
||||||
TagString: "Features",
|
TagString: "Features",
|
||||||
Print: true,
|
Print: true,
|
||||||
Subject: "my first commit",
|
Subject: "my first commit",
|
||||||
MessageBlocks: map[string][]shared.MessageBlock{},
|
MessageBlocks: map[string][]shared.MessageBlock{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -107,10 +107,10 @@ func TestChangelog(t *testing.T) {
|
|||||||
TagString: "Features",
|
TagString: "Features",
|
||||||
Print: true,
|
Print: true,
|
||||||
ParsedBreakingChangeMessage: "change api to v2",
|
ParsedBreakingChangeMessage: "change api to v2",
|
||||||
IsBreaking: true,
|
IsBreaking: true,
|
||||||
Subject: "my first break",
|
Subject: "my first break",
|
||||||
MessageBlocks: map[string][]shared.MessageBlock{
|
MessageBlocks: map[string][]shared.MessageBlock{
|
||||||
"body" : { shared.MessageBlock{
|
"body": {shared.MessageBlock{
|
||||||
Label: "BREAKING CHANGE",
|
Label: "BREAKING CHANGE",
|
||||||
Content: "change api to v2",
|
Content: "change api to v2",
|
||||||
},
|
},
|
||||||
@@ -141,10 +141,10 @@ func TestChangelog(t *testing.T) {
|
|||||||
TagString: "Features",
|
TagString: "Features",
|
||||||
Print: true,
|
Print: true,
|
||||||
ParsedBreakingChangeMessage: "hey from the change",
|
ParsedBreakingChangeMessage: "hey from the change",
|
||||||
IsBreaking: true,
|
IsBreaking: true,
|
||||||
Subject: "my first break",
|
Subject: "my first break",
|
||||||
MessageBlocks: map[string][]shared.MessageBlock{
|
MessageBlocks: map[string][]shared.MessageBlock{
|
||||||
"body" : { shared.MessageBlock{
|
"body": {shared.MessageBlock{
|
||||||
Label: "BREAKING CHANGE",
|
Label: "BREAKING CHANGE",
|
||||||
Content: "hey from the change",
|
Content: "hey from the change",
|
||||||
},
|
},
|
||||||
@@ -162,7 +162,7 @@ func TestChangelog(t *testing.T) {
|
|||||||
Tag: "feat",
|
Tag: "feat",
|
||||||
TagString: "Features",
|
TagString: "Features",
|
||||||
Print: true,
|
Print: true,
|
||||||
Subject: "my first commit",
|
Subject: "my first commit",
|
||||||
MessageBlocks: map[string][]shared.MessageBlock{},
|
MessageBlocks: map[string][]shared.MessageBlock{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -176,7 +176,7 @@ func TestChangelog(t *testing.T) {
|
|||||||
Tag: "feat",
|
Tag: "feat",
|
||||||
TagString: "Features",
|
TagString: "Features",
|
||||||
Print: true,
|
Print: true,
|
||||||
Subject: "my second commit",
|
Subject: "my second commit",
|
||||||
MessageBlocks: map[string][]shared.MessageBlock{},
|
MessageBlocks: map[string][]shared.MessageBlock{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -191,10 +191,10 @@ func TestChangelog(t *testing.T) {
|
|||||||
TagString: "Features",
|
TagString: "Features",
|
||||||
Print: true,
|
Print: true,
|
||||||
ParsedBreakingChangeMessage: "change api to v2",
|
ParsedBreakingChangeMessage: "change api to v2",
|
||||||
IsBreaking: true,
|
IsBreaking: true,
|
||||||
Subject: "my new commit",
|
Subject: "my new commit",
|
||||||
MessageBlocks: map[string][]shared.MessageBlock{
|
MessageBlocks: map[string][]shared.MessageBlock{
|
||||||
"body": { shared.MessageBlock{
|
"body": {shared.MessageBlock{
|
||||||
Label: "BREAKING CHANGE",
|
Label: "BREAKING CHANGE",
|
||||||
Content: "change api to v2",
|
Content: "change api to v2",
|
||||||
}},
|
}},
|
||||||
@@ -212,9 +212,9 @@ func TestChangelog(t *testing.T) {
|
|||||||
TagString: "Features",
|
TagString: "Features",
|
||||||
Print: true,
|
Print: true,
|
||||||
ParsedBreakingChangeMessage: "my next commit",
|
ParsedBreakingChangeMessage: "my next commit",
|
||||||
IsBreaking: true,
|
IsBreaking: true,
|
||||||
Subject: "my next commit",
|
Subject: "my next commit",
|
||||||
MessageBlocks: map[string][]shared.MessageBlock{},
|
MessageBlocks: map[string][]shared.MessageBlock{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -256,3 +256,93 @@ func TestChangelog(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestChangelogExtensions(t *testing.T) {
|
||||||
|
|
||||||
|
testConfigs := []struct {
|
||||||
|
testCase string
|
||||||
|
result *shared.GeneratedChangelog
|
||||||
|
releaseConfig *config.ReleaseConfig
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
testCase: "docker",
|
||||||
|
releaseConfig: &config.ReleaseConfig{
|
||||||
|
Changelog: config.ChangelogConfig{
|
||||||
|
Docker: config.ChangelogDocker{
|
||||||
|
Latest: true,
|
||||||
|
Repository: "mydocker.de",
|
||||||
|
},
|
||||||
|
NPM: config.ChangelogNPM{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
result: &shared.GeneratedChangelog{Title: "v1.0.0 (2019-07-19)", Content: "# v1.0.0 (2019-07-19)\n### Features\n* **`internal/changelog`** my first commit ([1234566](https://commit.url))\n\n## Docker image\n\nNew docker image is released under `mydocker.de:1.0.0`\n\n### Usage\n\n`docker run mydocker.de:1.0.0`\n\nor\n\n`docker run mydocker.de:latest`\n"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "npm",
|
||||||
|
releaseConfig: &config.ReleaseConfig{
|
||||||
|
Changelog: config.ChangelogConfig{
|
||||||
|
Docker: config.ChangelogDocker{},
|
||||||
|
NPM: config.ChangelogNPM{
|
||||||
|
Repository: "https://github.com/Nightapes/ngx-validators/packages/102720",
|
||||||
|
PackageName: "ngx-validators",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
result: &shared.GeneratedChangelog{Title: "v1.0.0 (2019-07-19)", Content: "# v1.0.0 (2019-07-19)\n### Features\n* **`internal/changelog`** my first commit ([1234566](https://commit.url))\n\n## NodeJS Package\n\nNew NodeJS package is released under [ngx-validators](https://github.com/Nightapes/ngx-validators/packages/102720)\n\n### Usage\n\n`yarn add ngx-validators@1.0.0`\n\nor\n\n`npm install -save ngx-validators@1.0.0`\n\n"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
analyzedCommits := map[shared.Release][]shared.AnalyzedCommit{
|
||||||
|
"minor": {
|
||||||
|
{
|
||||||
|
Commit: shared.Commit{
|
||||||
|
Message: "feat(internal/changelog): my first commit",
|
||||||
|
Author: "me",
|
||||||
|
Hash: "12345667",
|
||||||
|
},
|
||||||
|
Scope: "internal/changelog",
|
||||||
|
ParsedMessage: "my first commit",
|
||||||
|
Tag: "feat",
|
||||||
|
TagString: "Features",
|
||||||
|
Print: true,
|
||||||
|
Subject: "my first commit",
|
||||||
|
MessageBlocks: map[string][]shared.MessageBlock{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, config := range testConfigs {
|
||||||
|
t.Run(config.testCase, func(t *testing.T) {
|
||||||
|
templateConfig := shared.ChangelogTemplateConfig{
|
||||||
|
CommitURL: "https://commit.url",
|
||||||
|
CompareURL: "https://compare.url",
|
||||||
|
Hash: "hash",
|
||||||
|
Version: "1.0.0",
|
||||||
|
}
|
||||||
|
cl := changelog.New(config.releaseConfig, []analyzer.Rule{
|
||||||
|
{
|
||||||
|
Tag: "feat",
|
||||||
|
TagString: "Features",
|
||||||
|
Release: "minor",
|
||||||
|
Changelog: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Tag: "fix",
|
||||||
|
TagString: "Bug fixes",
|
||||||
|
Release: "patch",
|
||||||
|
Changelog: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Tag: "build",
|
||||||
|
TagString: "Build",
|
||||||
|
Release: "none",
|
||||||
|
Changelog: false,
|
||||||
|
},
|
||||||
|
}, time.Date(2019, 7, 19, 0, 0, 0, 0, time.UTC))
|
||||||
|
generatedChangelog, err := cl.GenerateChangelog(templateConfig, analyzedCommits)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equalf(t, config.result, generatedChangelog, "Testcase %s should have generated changelog", config.testCase)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package semanticrelease
|
package semanticrelease
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/integrations"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -226,6 +227,12 @@ func (s *SemanticRelease) Release(provider *ci.ProviderConfig, force bool) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
integrations := integrations.New(&s.config.Integrations, releaseVersion)
|
||||||
|
if err := integrations.Run(); err != nil {
|
||||||
|
log.Debugf("Error during integrations run")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
hook := hooks.New(s.config, releaseVersion)
|
hook := hooks.New(s.config, releaseVersion)
|
||||||
if err := hook.PreRelease(); err != nil {
|
if err := hook.PreRelease(); err != nil {
|
||||||
log.Debugf("Error during pre release hook")
|
log.Debugf("Error during pre release hook")
|
||||||
|
|||||||
Reference in New Issue
Block a user