You've already forked go-semantic-release
2
.dockerignore
Normal file
2
.dockerignore
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!build/
|
||||||
28
.github/workflows/main.yml
vendored
28
.github/workflows/main.yml
vendored
@@ -34,6 +34,34 @@ jobs:
|
|||||||
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/
|
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/
|
||||||
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/
|
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/
|
||||||
|
|
||||||
|
- name: Build Docker image for master
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
if: github.ref == 'refs/heads/master'
|
||||||
|
run: |
|
||||||
|
docker build -t nightapes/go-semantic-release:latest .
|
||||||
|
docker build -t nightapes/go-semantic-release:"$(./go-semantic-release next)" .
|
||||||
|
|
||||||
|
- name: Push Docker image for master
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
if: github.ref == 'refs/heads/master'
|
||||||
|
run: |
|
||||||
|
docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
docker push nightapes/go-semantic-release:latest
|
||||||
|
docker push nightapes/go-semantic-release:"$(./go-semantic-release next)"
|
||||||
|
|
||||||
|
- name: Build Docker image
|
||||||
|
if: github.ref != 'refs/heads/master'
|
||||||
|
run: |
|
||||||
|
docker build -t nightapes/go-semantic-release:development .
|
||||||
|
|
||||||
|
- name: Push Docker image
|
||||||
|
if: github.ref != 'refs/heads/master'
|
||||||
|
run: |
|
||||||
|
docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
docker push nightapes/go-semantic-release:development
|
||||||
|
|
||||||
- name: Release
|
- name: Release
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -17,3 +17,4 @@ go-semantic-release
|
|||||||
CHANGELOG.md
|
CHANGELOG.md
|
||||||
cover.html
|
cover.html
|
||||||
build/
|
build/
|
||||||
|
.idea/
|
||||||
|
|||||||
@@ -10,3 +10,7 @@ assets:
|
|||||||
compress: false
|
compress: false
|
||||||
- name: ./build/go-semantic-release.exe
|
- name: ./build/go-semantic-release.exe
|
||||||
compress: false
|
compress: false
|
||||||
|
changelog:
|
||||||
|
docker:
|
||||||
|
latest: true
|
||||||
|
repository: "nightapes/go-semantic-release"
|
||||||
9
Dockerfile
Normal file
9
Dockerfile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
FROM alpine:3.10.2
|
||||||
|
|
||||||
|
WORKDIR /code
|
||||||
|
|
||||||
|
COPY ./build/go-semantic-release .
|
||||||
|
|
||||||
|
USER 1000
|
||||||
|
|
||||||
|
ENTRYPOINT [ "./go-semantic-release" ]
|
||||||
11
README.md
11
README.md
@@ -110,9 +110,20 @@ assets:
|
|||||||
|
|
||||||
#### Changelog
|
#### Changelog
|
||||||
|
|
||||||
|
Following variables can be used for templates:
|
||||||
|
* `Commits` string
|
||||||
|
* `Version` string
|
||||||
|
* `Now` time.Time
|
||||||
|
* `Backtick` string
|
||||||
|
* `HasDocker` bool
|
||||||
|
* `HasDockerLatest` bool
|
||||||
|
* `DockerRepository` string
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
changelog:
|
changelog:
|
||||||
printAll: false ## Print all valid commits to changelog
|
printAll: false ## Print all valid commits to changelog
|
||||||
|
title: "v{{.Version}} ({{.Now.Format "2006-01-02"}})" ## Used for releases (go template)
|
||||||
|
templatePath: "./examples/changelog.tmpl" ## Path to a template file (go template)
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Docker
|
##### Docker
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
theme: jekyll-theme-cayman
|
theme: jekyll-theme-cayman
|
||||||
|
plugins:
|
||||||
|
- jemoji
|
||||||
|
|||||||
16
examples/changelog.tmpl
Normal file
16
examples/changelog.tmpl
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# My custom release template v{{$.Version}} ({{.Now.Format "2006-01-02"}})
|
||||||
|
{{ .Commits -}}
|
||||||
|
{{ if .HasDocker}}
|
||||||
|
## Docker image
|
||||||
|
|
||||||
|
New docker image is released under {{$.Backtick}}{{.DockerRepository}}:{{.Version}}{{$.Backtick}}
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
|
||||||
|
{{$.Backtick}}docker run {{.DockerRepository}}:{{.Version}}{{$.Backtick}}
|
||||||
|
{{ if .HasDockerLatest}}
|
||||||
|
or
|
||||||
|
|
||||||
|
{{$.Backtick}}docker run {{.DockerRepository}}:latest{{$.Backtick}}
|
||||||
|
{{ end -}}
|
||||||
|
{{ end -}}
|
||||||
@@ -2,6 +2,7 @@ package changelog
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
@@ -13,9 +14,7 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultChangelogTitle string = `v{{.Version}} ({{.Now.Format "2006-01-02"}})`
|
const defaultCommitList string = `{{ range $index,$commit := .BreakingChanges -}}
|
||||||
const defaultChangelog string = `# v{{$.Version}} ({{.Now.Format "2006-01-02"}})
|
|
||||||
{{ range $index,$commit := .BreakingChanges -}}
|
|
||||||
{{ if eq $index 0 }}
|
{{ if eq $index 0 }}
|
||||||
## BREAKING CHANGES
|
## BREAKING CHANGES
|
||||||
{{ end}}
|
{{ end}}
|
||||||
@@ -30,7 +29,10 @@ introduced by commit:
|
|||||||
* **{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}** {{$commit.ParsedMessage}} {{if $.HasURL}} ([{{ printf "%.7s" $commit.Commit.Hash}}]({{ replace $.URL "{{hash}}" $commit.Commit.Hash}})) {{end}}
|
* **{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}** {{$commit.ParsedMessage}} {{if $.HasURL}} ([{{ printf "%.7s" $commit.Commit.Hash}}]({{ replace $.URL "{{hash}}" $commit.Commit.Hash}})) {{end}}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ end -}}
|
{{ end -}}`
|
||||||
|
const defaultChangelogTitle string = `v{{.Version}} ({{.Now.Format "2006-01-02"}})`
|
||||||
|
const defaultChangelog string = `# v{{$.Version}} ({{.Now.Format "2006-01-02"}})
|
||||||
|
{{ .Commits -}}
|
||||||
{{ if .HasDocker}}
|
{{ if .HasDocker}}
|
||||||
## Docker image
|
## Docker image
|
||||||
|
|
||||||
@@ -48,19 +50,26 @@ or
|
|||||||
`
|
`
|
||||||
|
|
||||||
type changelogContent struct {
|
type changelogContent struct {
|
||||||
Commits map[string][]shared.AnalyzedCommit
|
Commits string
|
||||||
BreakingChanges []shared.AnalyzedCommit
|
|
||||||
Order []string
|
|
||||||
Version string
|
Version string
|
||||||
Now time.Time
|
Now time.Time
|
||||||
Backtick string
|
Backtick string
|
||||||
HasURL bool
|
|
||||||
URL string
|
|
||||||
HasDocker bool
|
HasDocker bool
|
||||||
HasDockerLatest bool
|
HasDockerLatest bool
|
||||||
DockerRepository string
|
DockerRepository string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type commitsContent struct {
|
||||||
|
Commits map[string][]shared.AnalyzedCommit
|
||||||
|
BreakingChanges []shared.AnalyzedCommit
|
||||||
|
Order []string
|
||||||
|
Version string
|
||||||
|
Now time.Time
|
||||||
|
Backtick string
|
||||||
|
HasURL bool
|
||||||
|
URL string
|
||||||
|
}
|
||||||
|
|
||||||
//Changelog struct
|
//Changelog struct
|
||||||
type Changelog struct {
|
type Changelog struct {
|
||||||
config *config.ReleaseConfig
|
config *config.ReleaseConfig
|
||||||
@@ -108,30 +117,61 @@ func (c *Changelog) GenerateChanglog(templateConfig shared.ChangelogTemplateConf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commitsContent := commitsContent{
|
||||||
|
Version: templateConfig.Version,
|
||||||
|
Commits: commitsPerScope,
|
||||||
|
Now: c.releaseTime,
|
||||||
|
BreakingChanges: commitsBreakingChange,
|
||||||
|
Backtick: "`",
|
||||||
|
Order: order,
|
||||||
|
HasURL: templateConfig.CommitURL != "",
|
||||||
|
URL: templateConfig.CommitURL,
|
||||||
|
}
|
||||||
|
|
||||||
changelogContent := changelogContent{
|
changelogContent := changelogContent{
|
||||||
Version: templateConfig.Version,
|
Version: templateConfig.Version,
|
||||||
Commits: commitsPerScope,
|
|
||||||
Now: c.releaseTime,
|
Now: c.releaseTime,
|
||||||
BreakingChanges: commitsBreakingChange,
|
|
||||||
Backtick: "`",
|
Backtick: "`",
|
||||||
Order: order,
|
|
||||||
HasURL: templateConfig.CommitURL != "",
|
|
||||||
URL: templateConfig.CommitURL,
|
|
||||||
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,
|
||||||
}
|
}
|
||||||
|
template := defaultChangelog
|
||||||
|
if c.config.Changelog.TemplatePath != "" {
|
||||||
|
content, err := ioutil.ReadFile(c.config.Changelog.TemplatePath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
template = string(content)
|
||||||
|
}
|
||||||
|
|
||||||
title, err := generateTemplate(defaultChangelogTitle, changelogContent)
|
templateTitle := defaultChangelogTitle
|
||||||
|
if c.config.Changelog.TemplateTitle != "" {
|
||||||
|
templateTitle = c.config.Changelog.TemplateTitle
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("Render title")
|
||||||
|
renderedTitle, err := generateTemplate(templateTitle, changelogContent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
content, err := generateTemplate(defaultChangelog, changelogContent)
|
|
||||||
|
|
||||||
return &shared.GeneratedChangelog{Title: title, Content: content}, err
|
log.Debugf("Render commits")
|
||||||
|
renderedCommitList, err := generateTemplate(defaultCommitList, commitsContent)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Tracef("Commits %s", renderedCommitList)
|
||||||
|
|
||||||
|
changelogContent.Commits = renderedCommitList
|
||||||
|
log.Debugf("Render changelog")
|
||||||
|
renderedContent, err := generateTemplate(template, changelogContent)
|
||||||
|
|
||||||
|
return &shared.GeneratedChangelog{Title: renderedTitle, Content: renderedContent}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateTemplate(text string, values changelogContent) (string, error) {
|
func generateTemplate(text string, values interface{}) (string, error) {
|
||||||
|
|
||||||
funcMap := template.FuncMap{
|
funcMap := template.FuncMap{
|
||||||
"replace": replace,
|
"replace": replace,
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ import (
|
|||||||
|
|
||||||
// ChangelogConfig struct
|
// ChangelogConfig struct
|
||||||
type ChangelogConfig struct {
|
type ChangelogConfig struct {
|
||||||
PrintAll bool `yaml:"printAll,omitempty"`
|
PrintAll bool `yaml:"printAll,omitempty"`
|
||||||
Template string `yaml:"template,omitempty"`
|
TemplateTitle string `yaml:"title,omitempty"`
|
||||||
TemplatePath string `yaml:"templatePath,omitempty"`
|
TemplatePath string `yaml:"templatePath,omitempty"`
|
||||||
Docker ChangelogDocker `yaml:"docker,omitempty"`
|
Docker ChangelogDocker `yaml:"docker,omitempty"`
|
||||||
NPM ChangelogNPM `yaml:"npm,omitempty"`
|
NPM ChangelogNPM `yaml:"npm,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//ChangelogDocker type struct
|
//ChangelogDocker type struct
|
||||||
|
|||||||
@@ -74,9 +74,9 @@ github:
|
|||||||
CommitFormat: "angular",
|
CommitFormat: "angular",
|
||||||
Branch: map[string]string{"add_git_releases": "alpha", "alpha": "alpha", "beta": "beta", "master": "release", "rc": "rc"},
|
Branch: map[string]string{"add_git_releases": "alpha", "alpha": "alpha", "beta": "beta", "master": "release", "rc": "rc"},
|
||||||
Changelog: config.ChangelogConfig{
|
Changelog: config.ChangelogConfig{
|
||||||
PrintAll: false,
|
PrintAll: false,
|
||||||
Template: "",
|
TemplateTitle: "",
|
||||||
TemplatePath: ""},
|
TemplatePath: ""},
|
||||||
Release: "github",
|
Release: "github",
|
||||||
GitHubProvider: config.GitHubProvider{
|
GitHubProvider: config.GitHubProvider{
|
||||||
Repo: "go-semantic-release",
|
Repo: "go-semantic-release",
|
||||||
@@ -92,20 +92,3 @@ github:
|
|||||||
}, result)
|
}, result)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// func TestWriteNotFound(t *testing.T) {
|
|
||||||
|
|
||||||
// err := cache.Write("notfound/dir", shared.ReleaseVersion{
|
|
||||||
// Last: shared.ReleaseVersionEntry{
|
|
||||||
// Commit: "12345",
|
|
||||||
// Version: createVersion("1.0.0"),
|
|
||||||
// },
|
|
||||||
// Next: shared.ReleaseVersionEntry{
|
|
||||||
// Commit: "12346",
|
|
||||||
// Version: createVersion("1.1.0"),
|
|
||||||
// },
|
|
||||||
// Branch: "master",
|
|
||||||
// })
|
|
||||||
// assert.Errorf(t, err, "Write non exsiting file")
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|||||||
Reference in New Issue
Block a user