You've already forked go-semantic-release
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6211095c38 | ||
|
|
74e895b5ad | ||
|
|
a69da92340 | ||
|
|
ff87725801 | ||
|
|
272a9b6e89 | ||
|
|
07b606a21a | ||
|
|
44f95969bf | ||
|
|
399a3515f2 | ||
|
|
2074877a3b | ||
|
|
b5551d8432 | ||
|
|
c92020d3ac | ||
|
|
d9f2b163c7 | ||
|
|
4379551982 | ||
|
|
3eb13972ec | ||
|
|
8659b40960 | ||
|
|
7ead374039 | ||
|
|
ee1dc3d8db | ||
|
|
38e4c178ee | ||
|
|
e22d3d07f4 | ||
|
|
46ae2da821 |
2
.dockerignore
Normal file
2
.dockerignore
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!build/
|
||||||
38
.github/workflows/main.yml
vendored
38
.github/workflows/main.yml
vendored
@@ -7,10 +7,10 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
- name: Set up Go 1.12
|
- name: Set up Go 1.13
|
||||||
uses: actions/setup-go@v1
|
uses: actions/setup-go@v1
|
||||||
with:
|
with:
|
||||||
go-version: 1.12
|
go-version: 1.13
|
||||||
id: go
|
id: go
|
||||||
|
|
||||||
- name: Check out code into the Go module directory
|
- name: Check out code into the Go module directory
|
||||||
@@ -19,7 +19,7 @@ jobs:
|
|||||||
- name: Lint
|
- name: Lint
|
||||||
run: |
|
run: |
|
||||||
export PATH=$PATH:$(go env GOPATH)/bin
|
export PATH=$PATH:$(go env GOPATH)/bin
|
||||||
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.16.0
|
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.18.0
|
||||||
golangci-lint run ./...
|
golangci-lint run ./...
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
@@ -31,8 +31,36 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
go build -o build/go-semantic-release-temp ./cmd/go-semantic-release/
|
go build -o build/go-semantic-release-temp ./cmd/go-semantic-release/
|
||||||
./build/go-semantic-release-temp next --no-cache --loglevel trace
|
./build/go-semantic-release-temp next --no-cache --loglevel trace
|
||||||
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 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:"$(./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
|
- name: Release
|
||||||
env:
|
env:
|
||||||
|
|||||||
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" ]
|
||||||
20
README.md
20
README.md
@@ -71,23 +71,28 @@ At the moment we support releases to gitlab and github.
|
|||||||
|
|
||||||
##### Github
|
##### Github
|
||||||
|
|
||||||
|
You need to set the env `GITHUB_TOKEN` with an access token.
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
release: 'github'
|
release: 'github'
|
||||||
github:
|
github:
|
||||||
user: "<user/group"
|
user: "<user/group"
|
||||||
repo: "<repositroyname>"
|
repo: "<repositroyname>"
|
||||||
## Optional, if your not using github.com
|
## Optional, if your not using github.com
|
||||||
customURL: <https://your.github>
|
customUrl: <https://your.github>
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Gitlab
|
##### Gitlab
|
||||||
|
|
||||||
|
You need to set the env `GITLAB_ACCESS_TOKEN` with an personal access token.
|
||||||
|
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
release: 'gitlab'
|
release: 'gitlab'
|
||||||
gitlab:
|
gitlab:
|
||||||
repo: "<repositroyname>" ## Example group/project
|
repo: "<repositroyname>" ## Example group/project
|
||||||
## Optional, if your not using gitlab.com
|
## Optional, if your not using gitlab.com
|
||||||
customURL: <https://your.gitlab>
|
customUrl: <https://your.gitlab>
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Assets
|
#### Assets
|
||||||
@@ -105,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
|
||||||
|
|||||||
3
_config.yml
Normal file
3
_config.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
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 -}}
|
||||||
3
go.mod
3
go.mod
@@ -1,6 +1,6 @@
|
|||||||
module github.com/Nightapes/go-semantic-release
|
module github.com/Nightapes/go-semantic-release
|
||||||
|
|
||||||
go 1.12
|
go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Masterminds/semver v1.4.2
|
github.com/Masterminds/semver v1.4.2
|
||||||
@@ -8,6 +8,7 @@ require (
|
|||||||
github.com/google/go-cmp v0.3.0 // indirect
|
github.com/google/go-cmp v0.3.0 // indirect
|
||||||
github.com/google/go-github/v25 v25.1.3
|
github.com/google/go-github/v25 v25.1.3
|
||||||
github.com/kevinburke/ssh_config v0.0.0-20190630040420-2e50c441276c // indirect
|
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/sirupsen/logrus v1.4.2
|
||||||
github.com/spf13/cobra v0.0.5
|
github.com/spf13/cobra v0.0.5
|
||||||
github.com/stretchr/testify v1.3.0
|
github.com/stretchr/testify v1.3.0
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ package ci
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
//ProviderConfig struct
|
//ProviderConfig struct
|
||||||
@@ -43,6 +44,7 @@ func GetCIProvider(gitUtil *gitutil.GitUtil, envs map[string]string) (*ProviderC
|
|||||||
services := []Service{
|
services := []Service{
|
||||||
Travis{},
|
Travis{},
|
||||||
GithubActions{},
|
GithubActions{},
|
||||||
|
GitlabCI{},
|
||||||
Git{gitUtil: gitUtil}, // GIt must be the last option to check
|
Git{gitUtil: gitUtil}, // GIt must be the last option to check
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -111,6 +111,19 @@ func TestCi(t *testing.T) {
|
|||||||
result: &ci.ProviderConfig{IsPR: false, PR: "", PRBranch: "", Branch: "feature-branch-1", Tag: "", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "", Service: "GithubActions", Name: "GithubActions CI"},
|
result: &ci.ProviderConfig{IsPR: false, PR: "", PRBranch: "", Branch: "feature-branch-1", Tag: "", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "", Service: "GithubActions", Name: "GithubActions CI"},
|
||||||
hasError: false,
|
hasError: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
service: "GitLab CI/CD PR",
|
||||||
|
envs: map[string]string{
|
||||||
|
"GITLAB_CI": "true",
|
||||||
|
"CI_COMMIT_SHA": "190bfd6aa60022afd0ef830342cfb07e33c45f37",
|
||||||
|
"CI_COMMIT_REF_NAME": "master",
|
||||||
|
"CI_COMMIT_TAG": "tag",
|
||||||
|
"CI_PROJECT_URL": "https://my.gitlab.com",
|
||||||
|
"CI_PIPELINE_ID": "1",
|
||||||
|
},
|
||||||
|
result: &ci.ProviderConfig{IsPR: false, PR: "", PRBranch: "", Branch: "master", Tag: "tag", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "https://my.gitlab.com/pipelines/1", Service: "gitlab", Name: "GitLab CI/CD"},
|
||||||
|
hasError: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, config := range testConfigs {
|
for _, config := range testConfigs {
|
||||||
|
|||||||
26
internal/ci/gitlab_ci.go
Normal file
26
internal/ci/gitlab_ci.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package ci
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
//GitlabCI struct
|
||||||
|
type GitlabCI struct{}
|
||||||
|
|
||||||
|
//Detect if on GitlabCI
|
||||||
|
func (t GitlabCI) detect(envs map[string]string) (*ProviderConfig, error) {
|
||||||
|
|
||||||
|
if _, exists := envs["GITLAB_CI"]; !exists {
|
||||||
|
return nil, fmt.Errorf("not running on gitlab")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &ProviderConfig{
|
||||||
|
Service: "gitlab",
|
||||||
|
Name: "GitLab CI/CD",
|
||||||
|
Commit: envs["CI_COMMIT_SHA"],
|
||||||
|
Tag: envs["CI_COMMIT_TAG"],
|
||||||
|
BuildURL: envs["CI_PROJECT_URL"] + "/pipelines/" + envs["CI_PIPELINE_ID"],
|
||||||
|
Branch: envs["CI_COMMIT_REF_NAME"],
|
||||||
|
IsPR: false,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@@ -5,12 +5,15 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/Masterminds/semver"
|
"github.com/Masterminds/semver"
|
||||||
"github.com/Nightapes/go-semantic-release/internal/shared"
|
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"gopkg.in/src-d/go-git.v4"
|
"gopkg.in/src-d/go-git.v4"
|
||||||
"gopkg.in/src-d/go-git.v4/plumbing"
|
"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/object"
|
||||||
|
"gopkg.in/src-d/go-git.v4/plumbing/storer"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GitUtil struct
|
// GitUtil struct
|
||||||
@@ -139,7 +142,7 @@ func (g *GitUtil) GetCommits(lastTagHash string) ([]shared.Commit, error) {
|
|||||||
if c.Hash.String() == lastTagHash {
|
if c.Hash.String() == lastTagHash {
|
||||||
log.Debugf("Found commit with hash %s, will stop here", c.Hash.String())
|
log.Debugf("Found commit with hash %s, will stop here", c.Hash.String())
|
||||||
foundEnd = true
|
foundEnd = true
|
||||||
|
return storer.ErrStop
|
||||||
}
|
}
|
||||||
if !foundEnd {
|
if !foundEnd {
|
||||||
log.Tracef("Found commit with hash %s", c.Hash.String())
|
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 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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,8 +42,9 @@ func New(config *config.GitLabProvider) (*Client, error) {
|
|||||||
|
|
||||||
tokenHeader := util.NewAddHeaderTransport(nil, "PRIVATE-TOKEN", accessToken)
|
tokenHeader := util.NewAddHeaderTransport(nil, "PRIVATE-TOKEN", accessToken)
|
||||||
acceptHeader := util.NewAddHeaderTransport(tokenHeader, "Accept", "application/json")
|
acceptHeader := util.NewAddHeaderTransport(tokenHeader, "Accept", "application/json")
|
||||||
|
contentHeader := util.NewAddHeaderTransport(acceptHeader, "Content-Type", "application/json")
|
||||||
httpClient := &http.Client{
|
httpClient := &http.Client{
|
||||||
Transport: acceptHeader,
|
Transport: contentHeader,
|
||||||
Timeout: time.Second * 60,
|
Timeout: time.Second * 60,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +98,7 @@ func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedC
|
|||||||
g.Release = tag
|
g.Release = tag
|
||||||
g.log.Infof("create release with version %s", tag)
|
g.log.Infof("create release with version %s", tag)
|
||||||
url := fmt.Sprintf("%s/projects/%s/releases", g.apiURL, util.PathEscape(g.config.Repo))
|
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{
|
bodyBytes, err := json.Marshal(Release{
|
||||||
TagName: tag,
|
TagName: tag,
|
||||||
@@ -109,6 +110,8 @@ func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedC
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g.log.Tracef("Send release config %s", bodyBytes)
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", url, bytes.NewReader(bodyBytes))
|
req, err := http.NewRequest("POST", url, bytes.NewReader(bodyBytes))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not create request: %s", err.Error())
|
return fmt.Errorf("could not create request: %s", err.Error())
|
||||||
@@ -124,7 +127,7 @@ func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedC
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
g.log.Infof("Crated release")
|
g.log.Infof("Created release")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/stretchr/testify/assert"
|
"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/releaser/gitlab"
|
||||||
"github.com/Nightapes/go-semantic-release/internal/shared"
|
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||||
"github.com/Nightapes/go-semantic-release/pkg/config"
|
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||||
@@ -109,7 +108,7 @@ func TestCreateRelease(t *testing.T) {
|
|||||||
},
|
},
|
||||||
responseBody: "{}",
|
responseBody: "{}",
|
||||||
responseCode: 200,
|
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,
|
valid: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -133,7 +132,7 @@ func TestCreateRelease(t *testing.T) {
|
|||||||
},
|
},
|
||||||
responseBody: "{}",
|
responseBody: "{}",
|
||||||
responseCode: 500,
|
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,
|
valid: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -158,7 +157,7 @@ func TestCreateRelease(t *testing.T) {
|
|||||||
},
|
},
|
||||||
responseCode: 400,
|
responseCode: 400,
|
||||||
responseBody: "{}",
|
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,
|
valid: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,6 @@ type Release struct {
|
|||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Ref string `json:"ref"`
|
Ref string `json:"ref"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
Assets struct {
|
|
||||||
Links []*ReleaseLink `json:"links"`
|
|
||||||
} `json:"assets"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReleaseLink struct
|
// ReleaseLink struct
|
||||||
|
|||||||
@@ -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