Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 272a9b6

Browse files
authoredSep 24, 2019
Merge pull request #25 from Nightapes/improvements
Improvements
2 parents b5551d8 + 07b606a commit 272a9b6

File tree

11 files changed

+142
-46
lines changed

11 files changed

+142
-46
lines changed
 

‎.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!build/

‎.github/workflows/main.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,34 @@ jobs:
3434
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o build/go-semantic-release -ldflags "-w -s --X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
3535
GOOS=windows GOARCH=386 CGO_ENABLED=0 go build -o build/go-semantic-release.exe -ldflags "-w -s -X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
3636
37+
- name: Build Docker image for master
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
if: github.ref == 'refs/heads/master'
41+
run: |
42+
docker build -t nightapes/go-semantic-release:latest .
43+
docker build -t nightapes/go-semantic-release:"$(./go-semantic-release next)" .
44+
45+
- name: Push Docker image for master
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
if: github.ref == 'refs/heads/master'
49+
run: |
50+
docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }}
51+
docker push nightapes/go-semantic-release:latest
52+
docker push nightapes/go-semantic-release:"$(./go-semantic-release next)"
53+
54+
- name: Build Docker image
55+
if: github.ref != 'refs/heads/master'
56+
run: |
57+
docker build -t nightapes/go-semantic-release:development .
58+
59+
- name: Push Docker image
60+
if: github.ref != 'refs/heads/master'
61+
run: |
62+
docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }}
63+
docker push nightapes/go-semantic-release:development
64+
3765
- name: Release
3866
env:
3967
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

‎.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ go-semantic-release
1616
.vscode/settings.json
1717
CHANGELOG.md
1818
cover.html
19-
build/
19+
build/
20+
.idea/

‎.release.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ assets:
99
- name: ./build/go-semantic-release
1010
compress: false
1111
- name: ./build/go-semantic-release.exe
12-
compress: false
12+
compress: false
13+
changelog:
14+
docker:
15+
latest: true
16+
repository: "nightapes/go-semantic-release"

‎Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM alpine:3.10.2
2+
3+
WORKDIR /code
4+
5+
COPY ./build/go-semantic-release .
6+
7+
USER 1000
8+
9+
ENTRYPOINT [ "./go-semantic-release" ]

‎README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,20 @@ assets:
110110

111111
#### Changelog
112112

113+
Following variables can be used for templates:
114+
* `Commits` string
115+
* `Version` string
116+
* `Now` time.Time
117+
* `Backtick` string
118+
* `HasDocker` bool
119+
* `HasDockerLatest` bool
120+
* `DockerRepository` string
121+
113122
```yml
114123
changelog:
115124
printAll: false ## Print all valid commits to changelog
125+
title: "v{{.Version}} ({{.Now.Format "2006-01-02"}})" ## Used for releases (go template)
126+
templatePath: "./examples/changelog.tmpl" ## Path to a template file (go template)
116127
```
117128

118129
##### Docker

‎_config.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
theme: jekyll-theme-cayman
1+
theme: jekyll-theme-cayman
2+
plugins:
3+
- jemoji

‎examples/changelog.tmpl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# My custom release template v{{$.Version}} ({{.Now.Format "2006-01-02"}})
2+
{{ .Commits -}}
3+
{{ if .HasDocker}}
4+
## Docker image
5+
6+
New docker image is released under {{$.Backtick}}{{.DockerRepository}}:{{.Version}}{{$.Backtick}}
7+
8+
### Usage
9+
10+
{{$.Backtick}}docker run {{.DockerRepository}}:{{.Version}}{{$.Backtick}}
11+
{{ if .HasDockerLatest}}
12+
or
13+
14+
{{$.Backtick}}docker run {{.DockerRepository}}:latest{{$.Backtick}}
15+
{{ end -}}
16+
{{ end -}}

‎internal/changelog/changelog.go

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package changelog
22

33
import (
44
"bytes"
5+
"io/ioutil"
56
"strings"
67
"text/template"
78
"time"
@@ -13,9 +14,7 @@ import (
1314
log "github.com/sirupsen/logrus"
1415
)
1516

16-
const defaultChangelogTitle string = `v{{.Version}} ({{.Now.Format "2006-01-02"}})`
17-
const defaultChangelog string = `# v{{$.Version}} ({{.Now.Format "2006-01-02"}})
18-
{{ range $index,$commit := .BreakingChanges -}}
17+
const defaultCommitList string = `{{ range $index,$commit := .BreakingChanges -}}
1918
{{ if eq $index 0 }}
2019
## BREAKING CHANGES
2120
{{ end}}
@@ -30,7 +29,10 @@ introduced by commit:
3029
* **{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}** {{$commit.ParsedMessage}} {{if $.HasURL}} ([{{ printf "%.7s" $commit.Commit.Hash}}]({{ replace $.URL "{{hash}}" $commit.Commit.Hash}})) {{end}}
3130
{{ end -}}
3231
{{ end -}}
33-
{{ end -}}
32+
{{ end -}}`
33+
const defaultChangelogTitle string = `v{{.Version}} ({{.Now.Format "2006-01-02"}})`
34+
const defaultChangelog string = `# v{{$.Version}} ({{.Now.Format "2006-01-02"}})
35+
{{ .Commits -}}
3436
{{ if .HasDocker}}
3537
## Docker image
3638
@@ -48,19 +50,26 @@ or
4850
`
4951

5052
type changelogContent struct {
51-
Commits map[string][]shared.AnalyzedCommit
52-
BreakingChanges []shared.AnalyzedCommit
53-
Order []string
53+
Commits string
5454
Version string
5555
Now time.Time
5656
Backtick string
57-
HasURL bool
58-
URL string
5957
HasDocker bool
6058
HasDockerLatest bool
6159
DockerRepository string
6260
}
6361

62+
type commitsContent struct {
63+
Commits map[string][]shared.AnalyzedCommit
64+
BreakingChanges []shared.AnalyzedCommit
65+
Order []string
66+
Version string
67+
Now time.Time
68+
Backtick string
69+
HasURL bool
70+
URL string
71+
}
72+
6473
//Changelog struct
6574
type Changelog struct {
6675
config *config.ReleaseConfig
@@ -108,30 +117,61 @@ func (c *Changelog) GenerateChanglog(templateConfig shared.ChangelogTemplateConf
108117
}
109118
}
110119

120+
commitsContent := commitsContent{
121+
Version: templateConfig.Version,
122+
Commits: commitsPerScope,
123+
Now: c.releaseTime,
124+
BreakingChanges: commitsBreakingChange,
125+
Backtick: "`",
126+
Order: order,
127+
HasURL: templateConfig.CommitURL != "",
128+
URL: templateConfig.CommitURL,
129+
}
130+
111131
changelogContent := changelogContent{
112132
Version: templateConfig.Version,
113-
Commits: commitsPerScope,
114133
Now: c.releaseTime,
115-
BreakingChanges: commitsBreakingChange,
116134
Backtick: "`",
117-
Order: order,
118-
HasURL: templateConfig.CommitURL != "",
119-
URL: templateConfig.CommitURL,
120135
HasDocker: c.config.Changelog.Docker.Repository != "",
121136
HasDockerLatest: c.config.Changelog.Docker.Latest,
122137
DockerRepository: c.config.Changelog.Docker.Repository,
123138
}
139+
template := defaultChangelog
140+
if c.config.Changelog.TemplatePath != "" {
141+
content, err := ioutil.ReadFile(c.config.Changelog.TemplatePath)
142+
if err != nil {
143+
return nil, err
144+
}
145+
template = string(content)
146+
}
147+
148+
templateTitle := defaultChangelogTitle
149+
if c.config.Changelog.TemplateTitle != "" {
150+
templateTitle = c.config.Changelog.TemplateTitle
151+
}
124152

125-
title, err := generateTemplate(defaultChangelogTitle, changelogContent)
153+
log.Debugf("Render title")
154+
renderedTitle, err := generateTemplate(templateTitle, changelogContent)
126155
if err != nil {
127156
return nil, err
128157
}
129-
content, err := generateTemplate(defaultChangelog, changelogContent)
130158

131-
return &shared.GeneratedChangelog{Title: title, Content: content}, err
159+
log.Debugf("Render commits")
160+
renderedCommitList, err := generateTemplate(defaultCommitList, commitsContent)
161+
if err != nil {
162+
return nil, err
163+
}
164+
165+
log.Tracef("Commits %s", renderedCommitList)
166+
167+
changelogContent.Commits = renderedCommitList
168+
log.Debugf("Render changelog")
169+
renderedContent, err := generateTemplate(template, changelogContent)
170+
171+
return &shared.GeneratedChangelog{Title: renderedTitle, Content: renderedContent}, err
132172
}
133173

134-
func generateTemplate(text string, values changelogContent) (string, error) {
174+
func generateTemplate(text string, values interface{}) (string, error) {
135175

136176
funcMap := template.FuncMap{
137177
"replace": replace,

‎pkg/config/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010

1111
// ChangelogConfig struct
1212
type ChangelogConfig struct {
13-
PrintAll bool `yaml:"printAll,omitempty"`
14-
Template string `yaml:"template,omitempty"`
15-
TemplatePath string `yaml:"templatePath,omitempty"`
16-
Docker ChangelogDocker `yaml:"docker,omitempty"`
17-
NPM ChangelogNPM `yaml:"npm,omitempty"`
13+
PrintAll bool `yaml:"printAll,omitempty"`
14+
TemplateTitle string `yaml:"title,omitempty"`
15+
TemplatePath string `yaml:"templatePath,omitempty"`
16+
Docker ChangelogDocker `yaml:"docker,omitempty"`
17+
NPM ChangelogNPM `yaml:"npm,omitempty"`
1818
}
1919

2020
//ChangelogDocker type struct

‎pkg/config/config_test.go

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ github:
7474
CommitFormat: "angular",
7575
Branch: map[string]string{"add_git_releases": "alpha", "alpha": "alpha", "beta": "beta", "master": "release", "rc": "rc"},
7676
Changelog: config.ChangelogConfig{
77-
PrintAll: false,
78-
Template: "",
79-
TemplatePath: ""},
77+
PrintAll: false,
78+
TemplateTitle: "",
79+
TemplatePath: ""},
8080
Release: "github",
8181
GitHubProvider: config.GitHubProvider{
8282
Repo: "go-semantic-release",
@@ -92,20 +92,3 @@ github:
9292
}, result)
9393

9494
}
95-
96-
// func TestWriteNotFound(t *testing.T) {
97-
98-
// err := cache.Write("notfound/dir", shared.ReleaseVersion{
99-
// Last: shared.ReleaseVersionEntry{
100-
// Commit: "12345",
101-
// Version: createVersion("1.0.0"),
102-
// },
103-
// Next: shared.ReleaseVersionEntry{
104-
// Commit: "12346",
105-
// Version: createVersion("1.1.0"),
106-
// },
107-
// Branch: "master",
108-
// })
109-
// assert.Errorf(t, err, "Write non exsiting file")
110-
111-
// }

0 commit comments

Comments
 (0)
Please sign in to comment.