Compare commits

...

15 Commits
1.0.1 ... 1.1.1

Author SHA1 Message Date
Felix Wiedmann
6211095c38 Merge pull request #27 from Nightapes/fix_commits
fix(commits):  don't break if commit is found and error happens on ol…
2019-10-08 21:09:43 +02:00
Nightapes
74e895b5ad fix(commits): don't break if commit is found and error happens on older commits and add better error message when git clone --depth is used 2019-10-08 20:46:57 +02:00
Sebastian
a69da92340 Merge pull request #26 from Nightapes/fix/build
build(workflow): fix call of binary
2019-09-25 10:42:44 +02:00
fwiedmann
ff87725801 build(workflow): fix call of binary 2019-09-25 00:20:41 +02:00
Felix Wiedmann
272a9b6e89 Merge pull request #25 from Nightapes/improvements
Improvements
2019-09-25 00:12:09 +02:00
Sebastian
07b606a21a Merge branch 'master' into improvements 2019-09-22 15:52:45 +02:00
Nightapes
44f95969bf feat(template): allow custom changelog template 2019-09-22 15:50:12 +02:00
Nightapes
399a3515f2 feat(docker): add docker image with go-semantic-release 2019-09-22 15:49:06 +02:00
Nightapes
2074877a3b build(pages): add jemoji plugin 2019-09-22 15:42:08 +02:00
Sebastian
b5551d8432 Set theme jekyll-theme-cayman 2019-09-22 15:34:33 +02:00
Sebastian
c92020d3ac Set theme jekyll-theme-slate 2019-09-22 15:33:05 +02:00
Felix Wiedmann
d9f2b163c7 Merge pull request #24 from Nightapes/fix/gitlab_request
fix(gitlab): fix broken request on release creation
2019-09-17 22:29:17 +02:00
Nightapes
4379551982 fix(gitlab): fix broken request on release creation 2019-09-17 21:01:05 +02:00
Felix Wiedmann
3eb13972ec Merge pull request #23 from Nightapes/fix_readme
docs(README): fix wrong confiig file
2019-09-16 22:36:39 +02:00
Sebastian
8659b40960 docs(README): fix wrong confiig file 2019-09-16 08:23:21 +02:00
16 changed files with 164 additions and 60 deletions

2
.dockerignore Normal file
View File

@@ -0,0 +1,2 @@
*
!build/

View File

@@ -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=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:"$(./build/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:"$(./build/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
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

3
.gitignore vendored
View File

@@ -16,4 +16,5 @@ go-semantic-release
.vscode/settings.json
CHANGELOG.md
cover.html
build/
build/
.idea/

View File

@@ -9,4 +9,8 @@ assets:
- name: ./build/go-semantic-release
compress: false
- name: ./build/go-semantic-release.exe
compress: false
compress: false
changelog:
docker:
latest: true
repository: "nightapes/go-semantic-release"

9
Dockerfile Normal file
View File

@@ -0,0 +1,9 @@
FROM alpine:3.10.2
WORKDIR /code
COPY ./build/go-semantic-release .
USER 1000
ENTRYPOINT [ "./go-semantic-release" ]

View File

@@ -79,7 +79,7 @@ github:
user: "<user/group"
repo: "<repositroyname>"
## Optional, if your not using github.com
customURL: <https://your.github>
customUrl: <https://your.github>
```
##### Gitlab
@@ -92,7 +92,7 @@ release: 'gitlab'
gitlab:
repo: "<repositroyname>" ## Example group/project
## Optional, if your not using gitlab.com
customURL: <https://your.gitlab>
customUrl: <https://your.gitlab>
```
#### Assets
@@ -110,9 +110,20 @@ assets:
#### Changelog
Following variables can be used for templates:
* `Commits` string
* `Version` string
* `Now` time.Time
* `Backtick` string
* `HasDocker` bool
* `HasDockerLatest` bool
* `DockerRepository` string
```yml
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
@@ -181,4 +192,4 @@ go test ./...
```
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.16.0
golangci-lint run ./...
```
```

3
_config.yml Normal file
View File

@@ -0,0 +1,3 @@
theme: jekyll-theme-cayman
plugins:
- jemoji

16
examples/changelog.tmpl Normal file
View 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 -}}

1
go.mod
View File

@@ -8,6 +8,7 @@ require (
github.com/google/go-cmp v0.3.0 // indirect
github.com/google/go-github/v25 v25.1.3
github.com/kevinburke/ssh_config v0.0.0-20190630040420-2e50c441276c // indirect
github.com/pkg/errors v0.8.1
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.5
github.com/stretchr/testify v1.3.0

View File

@@ -2,6 +2,7 @@ package changelog
import (
"bytes"
"io/ioutil"
"strings"
"text/template"
"time"
@@ -13,9 +14,7 @@ import (
log "github.com/sirupsen/logrus"
)
const defaultChangelogTitle string = `v{{.Version}} ({{.Now.Format "2006-01-02"}})`
const defaultChangelog string = `# v{{$.Version}} ({{.Now.Format "2006-01-02"}})
{{ range $index,$commit := .BreakingChanges -}}
const defaultCommitList string = `{{ range $index,$commit := .BreakingChanges -}}
{{ if eq $index 0 }}
## BREAKING CHANGES
{{ 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}}
{{ 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}}
## Docker image
@@ -48,19 +50,26 @@ or
`
type changelogContent struct {
Commits map[string][]shared.AnalyzedCommit
BreakingChanges []shared.AnalyzedCommit
Order []string
Commits string
Version string
Now time.Time
Backtick string
HasURL bool
URL string
HasDocker bool
HasDockerLatest bool
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
type Changelog struct {
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{
Version: templateConfig.Version,
Commits: commitsPerScope,
Now: c.releaseTime,
BreakingChanges: commitsBreakingChange,
Backtick: "`",
Order: order,
HasURL: templateConfig.CommitURL != "",
URL: templateConfig.CommitURL,
HasDocker: c.config.Changelog.Docker.Repository != "",
HasDockerLatest: c.config.Changelog.Docker.Latest,
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 {
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{
"replace": replace,

View File

@@ -5,12 +5,15 @@ import (
"fmt"
"sort"
"github.com/pkg/errors"
"github.com/Masterminds/semver"
"github.com/Nightapes/go-semantic-release/internal/shared"
log "github.com/sirupsen/logrus"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/object"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
)
// GitUtil struct
@@ -139,7 +142,7 @@ func (g *GitUtil) GetCommits(lastTagHash string) ([]shared.Commit, error) {
if c.Hash.String() == lastTagHash {
log.Debugf("Found commit with hash %s, will stop here", c.Hash.String())
foundEnd = true
return storer.ErrStop
}
if !foundEnd {
log.Tracef("Found commit with hash %s", c.Hash.String())
@@ -153,5 +156,9 @@ func (g *GitUtil) GetCommits(lastTagHash string) ([]shared.Commit, error) {
return nil
})
return commits, err
if err != nil {
return commits, errors.Wrap(err, "Could not read commits, check git clone depth in your ci")
}
return commits, nil
}

View File

@@ -42,8 +42,9 @@ func New(config *config.GitLabProvider) (*Client, error) {
tokenHeader := util.NewAddHeaderTransport(nil, "PRIVATE-TOKEN", accessToken)
acceptHeader := util.NewAddHeaderTransport(tokenHeader, "Accept", "application/json")
contentHeader := util.NewAddHeaderTransport(acceptHeader, "Content-Type", "application/json")
httpClient := &http.Client{
Transport: acceptHeader,
Transport: contentHeader,
Timeout: time.Second * 60,
}
@@ -97,7 +98,7 @@ func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedC
g.Release = tag
g.log.Infof("create release with version %s", tag)
url := fmt.Sprintf("%s/projects/%s/releases", g.apiURL, util.PathEscape(g.config.Repo))
g.log.Infof("Send release to %s", url)
g.log.Infof("Send release to %s", url)
bodyBytes, err := json.Marshal(Release{
TagName: tag,
@@ -109,6 +110,8 @@ func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedC
return err
}
g.log.Tracef("Send release config %s", bodyBytes)
req, err := http.NewRequest("POST", url, bytes.NewReader(bodyBytes))
if err != nil {
return fmt.Errorf("could not create request: %s", err.Error())
@@ -124,7 +127,7 @@ func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedC
return err
}
g.log.Infof("Crated release")
g.log.Infof("Created release")
return nil
}

View File

@@ -13,7 +13,6 @@ import (
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
//"github.com/Nightapes/go-semantic-release/internal/releaser/util"
"github.com/Nightapes/go-semantic-release/internal/releaser/gitlab"
"github.com/Nightapes/go-semantic-release/internal/shared"
"github.com/Nightapes/go-semantic-release/pkg/config"
@@ -109,7 +108,7 @@ func TestCreateRelease(t *testing.T) {
},
responseBody: "{}",
responseCode: 200,
requestBody: `{"tag_name":"2.0.0","name":"title","ref":"master","description":"content","assets":{"links":null}}`,
requestBody: `{"tag_name":"2.0.0","name":"title","ref":"master","description":"content"}`,
valid: true,
},
{
@@ -133,7 +132,7 @@ func TestCreateRelease(t *testing.T) {
},
responseBody: "{}",
responseCode: 500,
requestBody: `{"tag_name":"2.0.0","name":"title","ref":"master","description":"content","assets":{"links":null}}`,
requestBody: `{"tag_name":"2.0.0","name":"title","ref":"master","description":"content"}`,
valid: false,
},
{
@@ -158,7 +157,7 @@ func TestCreateRelease(t *testing.T) {
},
responseCode: 400,
responseBody: "{}",
requestBody: `{"tag_name":"2.0.0","name":"title","ref":"master","description":"content","assets":{"links":null}}`,
requestBody: `{"tag_name":"2.0.0","name":"title","ref":"master","description":"content"}`,
valid: false,
},
}

View File

@@ -6,9 +6,6 @@ type Release struct {
Name string `json:"name"`
Ref string `json:"ref"`
Description string `json:"description,omitempty"`
Assets struct {
Links []*ReleaseLink `json:"links"`
} `json:"assets"`
}
// ReleaseLink struct

View File

@@ -10,11 +10,11 @@ import (
// ChangelogConfig struct
type ChangelogConfig struct {
PrintAll bool `yaml:"printAll,omitempty"`
Template string `yaml:"template,omitempty"`
TemplatePath string `yaml:"templatePath,omitempty"`
Docker ChangelogDocker `yaml:"docker,omitempty"`
NPM ChangelogNPM `yaml:"npm,omitempty"`
PrintAll bool `yaml:"printAll,omitempty"`
TemplateTitle string `yaml:"title,omitempty"`
TemplatePath string `yaml:"templatePath,omitempty"`
Docker ChangelogDocker `yaml:"docker,omitempty"`
NPM ChangelogNPM `yaml:"npm,omitempty"`
}
//ChangelogDocker type struct

View File

@@ -74,9 +74,9 @@ github:
CommitFormat: "angular",
Branch: map[string]string{"add_git_releases": "alpha", "alpha": "alpha", "beta": "beta", "master": "release", "rc": "rc"},
Changelog: config.ChangelogConfig{
PrintAll: false,
Template: "",
TemplatePath: ""},
PrintAll: false,
TemplateTitle: "",
TemplatePath: ""},
Release: "github",
GitHubProvider: config.GitHubProvider{
Repo: "go-semantic-release",
@@ -92,20 +92,3 @@ github:
}, 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")
// }