You've already forked go-semantic-release
Compare commits
20 Commits
1.0.0-beta
...
1.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9f2b163c7 | ||
|
|
4379551982 | ||
|
|
3eb13972ec | ||
|
|
8659b40960 | ||
|
|
7ead374039 | ||
|
|
ee1dc3d8db | ||
|
|
38e4c178ee | ||
|
|
e22d3d07f4 | ||
|
|
46ae2da821 | ||
|
|
e3265b1843 | ||
|
|
d03913e6d7 | ||
|
|
e5ed8edb75 | ||
|
|
76ffeda95b | ||
|
|
0994354089 | ||
|
|
e8d7feeca3 | ||
|
|
e0974e3140 | ||
|
|
8643656339 | ||
|
|
829f2925ab | ||
|
|
7729ba5914 | ||
|
|
72200582fd |
11
.github/workflows/main.yml
vendored
11
.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
|
||||||
@@ -30,8 +30,9 @@ jobs:
|
|||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
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/
|
||||||
go build -o build/go-semantic-release -ldflags "-w -s --X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
|
./build/go-semantic-release-temp next --no-cache --loglevel trace
|
||||||
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=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: Release
|
- name: Release
|
||||||
env:
|
env:
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -16,3 +16,4 @@ go-semantic-release
|
|||||||
.vscode/settings.json
|
.vscode/settings.json
|
||||||
CHANGELOG.md
|
CHANGELOG.md
|
||||||
cover.html
|
cover.html
|
||||||
|
build/
|
||||||
21
.release.yml
21
.release.yml
@@ -1,21 +1,12 @@
|
|||||||
commitFormat: angular
|
|
||||||
title: "go-semantic-release release"
|
|
||||||
branch:
|
|
||||||
master: beta
|
|
||||||
rc: rc
|
|
||||||
beta: beta
|
|
||||||
alpha: alpha
|
|
||||||
changelog:
|
|
||||||
printAll: false
|
|
||||||
template: ''
|
|
||||||
templatePath: ''
|
|
||||||
release: 'github'
|
release: 'github'
|
||||||
|
github:
|
||||||
|
repo: "go-semantic-release"
|
||||||
|
user: "nightapes"
|
||||||
|
commitFormat: angular
|
||||||
|
branch:
|
||||||
|
master: release
|
||||||
assets:
|
assets:
|
||||||
- name: ./build/go-semantic-release
|
- name: ./build/go-semantic-release
|
||||||
compress: false
|
compress: false
|
||||||
- name: ./build/go-semantic-release.exe
|
- name: ./build/go-semantic-release.exe
|
||||||
compress: false
|
compress: false
|
||||||
github:
|
|
||||||
repo: "go-semantic-release"
|
|
||||||
user: "nightapes"
|
|
||||||
customUrl: ""
|
|
||||||
|
|||||||
185
README.md
185
README.md
@@ -2,24 +2,183 @@
|
|||||||
|
|
||||||
## Release Types
|
## Release Types
|
||||||
|
|
||||||
| Type | Git tag | Changelog | Release | Write access git | Api token |
|
| Type | Implemendet | Git tag | Changelog | Release | Write access git | Api token |
|
||||||
|--- |:---: |:---: |:---: |:---: |:---: |
|
| ---------- | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: |
|
||||||
| `git` | :white_check_mark: | | | :white_check_mark:| |
|
| `github` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | :white_check_mark: |
|
||||||
| `github` | :white_check_mark: | :white_check_mark: | :white_check_mark:| | :white_check_mark: |
|
| `gitlab` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | :white_check_mark: |
|
||||||
| `gitlab` | :white_check_mark: | :white_check_mark: | :white_check_mark:| | :white_check_mark: |
|
| `git` | Comming soon | :white_check_mark: | | | :white_check_mark: | |
|
||||||
|
| `bitbuckt` | Comming soon | :white_check_mark: | | | :white_check_mark: | |
|
||||||
|
|
||||||
|
|
||||||
|
## Supported CI Pipelines
|
||||||
|
|
||||||
|
* Github Actions
|
||||||
|
* Gitlab CI
|
||||||
|
* Travis CI
|
||||||
|
* Custom CI, set enviroment `CI=true`
|
||||||
|
|
||||||
|
## How to use
|
||||||
|
|
||||||
|
`go-semantic-release` config file
|
||||||
|
Create a file with the name `.release.yml` or anything else, but you need to set to every command `-c <your config file>`
|
||||||
|
|
||||||
|
### Example config
|
||||||
|
|
||||||
|
```yml
|
||||||
|
commitFormat: angular
|
||||||
|
branch:
|
||||||
|
master: release
|
||||||
|
release: 'github'
|
||||||
|
github:
|
||||||
|
repo: "go-semantic-release"
|
||||||
|
user: "nightapes"
|
||||||
|
assets:
|
||||||
|
- name: ./build/go-semantic-release
|
||||||
|
compress: false
|
||||||
|
- name: ./build/go-semantic-release.exe
|
||||||
|
compress: false
|
||||||
|
```
|
||||||
|
|
||||||
|
#### CommitFormat
|
||||||
|
|
||||||
|
Set the commit format, at the moment we support ony [angular](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit-message-format), more coming soon.
|
||||||
|
|
||||||
|
```yml
|
||||||
|
commitFormat: angular
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Branch
|
||||||
|
|
||||||
|
You can define which kind of release should be created for different branches.
|
||||||
|
|
||||||
|
Supported release kinds:
|
||||||
|
|
||||||
|
* `release` -> `v1.0.0`
|
||||||
|
* `rc` -> `v1.0.0-rc.0`
|
||||||
|
* `beta` -> `v1.0.0-beta.0`
|
||||||
|
* `alpha` -> `v1.0.0-alpha.0`
|
||||||
|
|
||||||
|
Add a branch config to your config
|
||||||
|
|
||||||
|
```yml
|
||||||
|
branch:
|
||||||
|
<branch-name>: <kind>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Relase
|
||||||
|
|
||||||
|
At the moment we support releases to gitlab and github.
|
||||||
|
|
||||||
|
##### Github
|
||||||
|
|
||||||
|
You need to set the env `GITHUB_TOKEN` with an access token.
|
||||||
|
|
||||||
|
```yml
|
||||||
|
release: 'github'
|
||||||
|
github:
|
||||||
|
user: "<user/group"
|
||||||
|
repo: "<repositroyname>"
|
||||||
|
## Optional, if your not using github.com
|
||||||
|
customUrl: <https://your.github>
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Gitlab
|
||||||
|
|
||||||
|
You need to set the env `GITLAB_ACCESS_TOKEN` with an personal access token.
|
||||||
|
|
||||||
|
|
||||||
|
```yml
|
||||||
|
release: 'gitlab'
|
||||||
|
gitlab:
|
||||||
|
repo: "<repositroyname>" ## Example group/project
|
||||||
|
## Optional, if your not using gitlab.com
|
||||||
|
customUrl: <https://your.gitlab>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Assets
|
||||||
|
|
||||||
|
You can upload assets to a release
|
||||||
|
|
||||||
|
Support for gitlab and github.
|
||||||
|
If you want, you can let the file be compressed before uploading
|
||||||
|
|
||||||
|
```yml
|
||||||
|
assets:
|
||||||
|
- name: ./build/go-semantic-release
|
||||||
|
compress: false
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Changelog
|
||||||
|
|
||||||
|
```yml
|
||||||
|
changelog:
|
||||||
|
printAll: false ## Print all valid commits to changelog
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Docker
|
||||||
|
|
||||||
|
You can print a help text for a docker image
|
||||||
|
|
||||||
|
```yml
|
||||||
|
changelog:
|
||||||
|
docker:
|
||||||
|
latest: false ## If you uploaded a latest image
|
||||||
|
repository: ## Your docker repository, which is used for docker run
|
||||||
|
```
|
||||||
|
|
||||||
|
### Version
|
||||||
|
|
||||||
|
`go-semantic-release` has two modes for calcualting the version: automatic or manual.
|
||||||
|
|
||||||
|
#### Automatic
|
||||||
|
|
||||||
|
Version will be calculated on the `next` or `release` command
|
||||||
|
|
||||||
|
#### Manual
|
||||||
|
|
||||||
|
If you don't want that `go-semantic-release` is calculating the version from the commits, you can set the version by hand with
|
||||||
|
following command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./go-semantic-release set 1.1.1
|
||||||
|
```
|
||||||
|
|
||||||
|
### Print version
|
||||||
|
|
||||||
|
Print the next version, can be used to add version to your program
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./go-semantic-release next
|
||||||
|
```
|
||||||
|
Example with go-lang
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go build -ldflags "--X main.version=`./go-semantic-release next`"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Create release
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./go-semantic-release release
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Build
|
## Build from source
|
||||||
|
|
||||||
`go build ./cmd/go-semantic-release/`
|
```bash
|
||||||
|
go build ./cmd/go-semantic-release/
|
||||||
|
```
|
||||||
|
|
||||||
## Run
|
### Testing
|
||||||
|
|
||||||
Print the next version
|
```bash
|
||||||
|
go test ./...
|
||||||
|
```
|
||||||
|
|
||||||
`./go-semantic-release version next`
|
### Linting
|
||||||
|
|
||||||
Set a version
|
```
|
||||||
|
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.16.0
|
||||||
`./go-semantic-release version set v1.1.1`
|
golangci-lint run ./...
|
||||||
|
```
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
go build ./cmd/main.go && ./main.exe version next --path /f/Repro/ambassador/
|
|
||||||
go build ./cmd/main.go && ./main.exe --loglevel debug version set v1.1.1 --path /f/Repro/ambassador/
|
|
||||||
@@ -11,7 +11,7 @@ func init() {
|
|||||||
|
|
||||||
var zipCmd = &cobra.Command{
|
var zipCmd = &cobra.Command{
|
||||||
Use: "zip",
|
Use: "zip",
|
||||||
Short: "Zip configured artifact from release config",
|
Short: "Zip configured artifact from release config (internal)",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
config, err := cmd.Flags().GetString("config")
|
config, err := cmd.Flags().GetString("config")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
2
go.mod
2
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
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ const ANGULAR = "angular"
|
|||||||
|
|
||||||
func newAngular() *angular {
|
func newAngular() *angular {
|
||||||
return &angular{
|
return &angular{
|
||||||
regex: `(TAG)(?:\((.*)\))?: (.*)`,
|
regex: `^(TAG)(?:\((.*)\))?: (.*)`,
|
||||||
log: log.WithField("analyzer", ANGULAR),
|
log: log.WithField("analyzer", ANGULAR),
|
||||||
rules: []Rule{
|
rules: []Rule{
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -107,6 +107,11 @@ func TestAngular(t *testing.T) {
|
|||||||
Author: "me",
|
Author: "me",
|
||||||
Hash: "12345667",
|
Hash: "12345667",
|
||||||
},
|
},
|
||||||
|
shared.Commit{
|
||||||
|
Message: "Merge feat(internal/changelog): my first commit",
|
||||||
|
Author: "me",
|
||||||
|
Hash: "12345667",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -49,6 +49,11 @@ func (c *Calculator) CalculateNewVersion(commits map[shared.Release][]shared.Ana
|
|||||||
}
|
}
|
||||||
case "release":
|
case "release":
|
||||||
if !firstRelease {
|
if !firstRelease {
|
||||||
|
if lastVersion.Prerelease() != "" {
|
||||||
|
newVersion, _ := lastVersion.SetPrerelease("")
|
||||||
|
return newVersion
|
||||||
|
}
|
||||||
|
|
||||||
if len(commits["major"]) > 0 {
|
if len(commits["major"]) > 0 {
|
||||||
return lastVersion.IncMajor()
|
return lastVersion.IncMajor()
|
||||||
} else if len(commits["minor"]) > 0 {
|
} else if len(commits["minor"]) > 0 {
|
||||||
|
|||||||
@@ -31,17 +31,34 @@ introduced by commit:
|
|||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
|
{{ 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 -}}
|
||||||
`
|
`
|
||||||
|
|
||||||
type changelogContent struct {
|
type changelogContent struct {
|
||||||
Commits map[string][]shared.AnalyzedCommit
|
Commits map[string][]shared.AnalyzedCommit
|
||||||
BreakingChanges []shared.AnalyzedCommit
|
BreakingChanges []shared.AnalyzedCommit
|
||||||
Order []string
|
Order []string
|
||||||
Version string
|
Version string
|
||||||
Now time.Time
|
Now time.Time
|
||||||
Backtick string
|
Backtick string
|
||||||
HasURL bool
|
HasURL bool
|
||||||
URL string
|
URL string
|
||||||
|
HasDocker bool
|
||||||
|
HasDockerLatest bool
|
||||||
|
DockerRepository string
|
||||||
}
|
}
|
||||||
|
|
||||||
//Changelog struct
|
//Changelog struct
|
||||||
@@ -92,14 +109,17 @@ func (c *Changelog) GenerateChanglog(templateConfig shared.ChangelogTemplateConf
|
|||||||
}
|
}
|
||||||
|
|
||||||
changelogContent := changelogContent{
|
changelogContent := changelogContent{
|
||||||
Version: templateConfig.Version,
|
Version: templateConfig.Version,
|
||||||
Commits: commitsPerScope,
|
Commits: commitsPerScope,
|
||||||
Now: c.releaseTime,
|
Now: c.releaseTime,
|
||||||
BreakingChanges: commitsBreakingChange,
|
BreakingChanges: commitsBreakingChange,
|
||||||
Backtick: "`",
|
Backtick: "`",
|
||||||
Order: order,
|
Order: order,
|
||||||
HasURL: templateConfig.CommitURL != "",
|
HasURL: templateConfig.CommitURL != "",
|
||||||
URL: templateConfig.CommitURL,
|
URL: templateConfig.CommitURL,
|
||||||
|
HasDocker: c.config.Changelog.Docker.Repository != "",
|
||||||
|
HasDockerLatest: c.config.Changelog.Docker.Latest,
|
||||||
|
DockerRepository: c.config.Changelog.Docker.Repository,
|
||||||
}
|
}
|
||||||
|
|
||||||
title, err := generateTemplate(defaultChangelogTitle, changelogContent)
|
title, err := generateTemplate(defaultChangelogTitle, changelogContent)
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,6 +52,7 @@ func GetCIProvider(gitUtil *gitutil.GitUtil, envs map[string]string) (*ProviderC
|
|||||||
config, err := service.detect(envs)
|
config, err := service.detect(envs)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Infof("Found CI: %s", config.Name)
|
log.Infof("Found CI: %s", config.Name)
|
||||||
|
log.Tracef("Found CI config: %+v", config)
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
log.Debugf("%s", err.Error())
|
log.Debugf("%s", err.Error())
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -6,11 +6,11 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/Masterminds/semver"
|
"github.com/Masterminds/semver"
|
||||||
|
"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"
|
||||||
"github.com/Nightapes/go-semantic-release/internal/shared"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// GitUtil struct
|
// GitUtil struct
|
||||||
@@ -87,7 +87,7 @@ func (g *GitUtil) GetLastVersion() (*semver.Version, string, error) {
|
|||||||
|
|
||||||
err = gitTags.ForEach(func(p *plumbing.Reference) error {
|
err = gitTags.ForEach(func(p *plumbing.Reference) error {
|
||||||
v, err := semver.NewVersion(p.Name().Short())
|
v, err := semver.NewVersion(p.Name().Short())
|
||||||
log.Tracef("%+v with hash: %s", p.Target(), p.Hash())
|
log.Tracef("Tag %+v with hash: %s", p.Target(), p.Hash())
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
tags = append(tags, v)
|
tags = append(tags, v)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package gitlab
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -26,7 +25,6 @@ const GITLAB = "gitlab"
|
|||||||
// Client type struct
|
// Client type struct
|
||||||
type Client struct {
|
type Client struct {
|
||||||
config *config.GitLabProvider
|
config *config.GitLabProvider
|
||||||
context context.Context
|
|
||||||
client *http.Client
|
client *http.Client
|
||||||
baseURL string
|
baseURL string
|
||||||
apiURL string
|
apiURL string
|
||||||
@@ -36,12 +34,17 @@ type Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New initialize a new gitlabRelease
|
// New initialize a new gitlabRelease
|
||||||
func New(config *config.GitLabProvider, accessToken string) (*Client, error) {
|
func New(config *config.GitLabProvider) (*Client, error) {
|
||||||
ctx := context.Background()
|
accessToken, err := util.GetAccessToken(fmt.Sprintf("%s_ACCESS_TOKEN", strings.ToUpper(GITLAB)))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
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,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +68,6 @@ func New(config *config.GitLabProvider, accessToken string) (*Client, error) {
|
|||||||
return &Client{
|
return &Client{
|
||||||
token: accessToken,
|
token: accessToken,
|
||||||
config: config,
|
config: config,
|
||||||
context: ctx,
|
|
||||||
baseURL: config.CustomURL,
|
baseURL: config.CustomURL,
|
||||||
apiURL: config.CustomURL + "/api/v4",
|
apiURL: config.CustomURL + "/api/v4",
|
||||||
client: httpClient,
|
client: httpClient,
|
||||||
@@ -96,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,
|
||||||
@@ -108,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())
|
||||||
@@ -123,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,54 +13,61 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetCommitURL(t *testing.T) {
|
func TestGetCommitURL(t *testing.T) {
|
||||||
|
os.Setenv("GITLAB_ACCESS_TOKEN", "XXX")
|
||||||
|
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
|
||||||
client, err := gitlab.New(&config.GitLabProvider{
|
client, err := gitlab.New(&config.GitLabProvider{
|
||||||
CustomURL: "https://localhost/",
|
CustomURL: "https://localhost/",
|
||||||
Repo: "test/test",
|
Repo: "test/test",
|
||||||
}, "aToken")
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "https://localhost/test/test/commit/{{hash}}", client.GetCommitURL())
|
assert.Equal(t, "https://localhost/test/test/commit/{{hash}}", client.GetCommitURL())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetCompareURL(t *testing.T) {
|
func TestGetCompareURL(t *testing.T) {
|
||||||
|
os.Setenv("GITLAB_ACCESS_TOKEN", "XXX")
|
||||||
|
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
|
||||||
client, err := gitlab.New(&config.GitLabProvider{
|
client, err := gitlab.New(&config.GitLabProvider{
|
||||||
CustomURL: "https://localhost/",
|
CustomURL: "https://localhost/",
|
||||||
Repo: "test/test",
|
Repo: "test/test",
|
||||||
}, "aToken")
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "https://localhost/test/test/compare/1.0.0...1.0.1", client.GetCompareURL("1.0.0", "1.0.1"))
|
assert.Equal(t, "https://localhost/test/test/compare/1.0.0...1.0.1", client.GetCompareURL("1.0.0", "1.0.1"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidateConfig_EmptyRepro(t *testing.T) {
|
func TestValidateConfig_EmptyRepro(t *testing.T) {
|
||||||
|
os.Setenv("GITLAB_ACCESS_TOKEN", "XXX")
|
||||||
|
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
|
||||||
_, err := gitlab.New(&config.GitLabProvider{
|
_, err := gitlab.New(&config.GitLabProvider{
|
||||||
CustomURL: "https://localhost/",
|
CustomURL: "https://localhost/",
|
||||||
}, "aToken")
|
})
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidateConfig_DefaultURL(t *testing.T) {
|
func TestValidateConfig_DefaultURL(t *testing.T) {
|
||||||
|
os.Setenv("GITLAB_ACCESS_TOKEN", "XXX")
|
||||||
|
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
|
||||||
config := &config.GitLabProvider{
|
config := &config.GitLabProvider{
|
||||||
Repo: "localhost/test",
|
Repo: "localhost/test",
|
||||||
}
|
}
|
||||||
_, err := gitlab.New(config, "aToken")
|
_, err := gitlab.New(config)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "https://gitlab.com", config.CustomURL)
|
assert.Equal(t, "https://gitlab.com", config.CustomURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidateConfig_CustomURL(t *testing.T) {
|
func TestValidateConfig_CustomURL(t *testing.T) {
|
||||||
|
os.Setenv("GITLAB_ACCESS_TOKEN", "XXX")
|
||||||
|
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
|
||||||
config := &config.GitLabProvider{
|
config := &config.GitLabProvider{
|
||||||
Repo: "/localhost/test/",
|
Repo: "/localhost/test/",
|
||||||
CustomURL: "https://localhost/",
|
CustomURL: "https://localhost/",
|
||||||
}
|
}
|
||||||
_, err := gitlab.New(config, "aToken")
|
_, err := gitlab.New(config)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "https://localhost", config.CustomURL)
|
assert.Equal(t, "https://localhost", config.CustomURL)
|
||||||
assert.Equal(t, "localhost/test", config.Repo)
|
assert.Equal(t, "localhost/test", config.Repo)
|
||||||
@@ -101,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,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -125,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,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -150,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,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -181,8 +188,9 @@ func TestCreateRelease(t *testing.T) {
|
|||||||
if testObject.config.CustomURL == "" {
|
if testObject.config.CustomURL == "" {
|
||||||
testObject.config.CustomURL = testServer.URL
|
testObject.config.CustomURL = testServer.URL
|
||||||
}
|
}
|
||||||
|
os.Setenv("GITLAB_ACCESS_TOKEN", "aToken")
|
||||||
client, err := gitlab.New(&testObject.config, "aToken")
|
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
|
||||||
|
client, err := gitlab.New(&testObject.config)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
err = client.CreateRelease(testObject.releaseVersion, testObject.generatedChangelog)
|
err = client.CreateRelease(testObject.releaseVersion, testObject.generatedChangelog)
|
||||||
@@ -307,8 +315,9 @@ func TestUploadAssets(t *testing.T) {
|
|||||||
if testObject.config.CustomURL == "" {
|
if testObject.config.CustomURL == "" {
|
||||||
testObject.config.CustomURL = testServer.URL
|
testObject.config.CustomURL = testServer.URL
|
||||||
}
|
}
|
||||||
|
os.Setenv("GITLAB_ACCESS_TOKEN", "aToken")
|
||||||
client, err := gitlab.New(&testObject.config, "aToken")
|
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
|
||||||
|
client, err := gitlab.New(&testObject.config)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
client.Release = "1.0.0"
|
client.Release = "1.0.0"
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -2,11 +2,9 @@ package releaser
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Nightapes/go-semantic-release/internal/releaser/github"
|
"github.com/Nightapes/go-semantic-release/internal/releaser/github"
|
||||||
"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/releaser/util"
|
|
||||||
"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"
|
||||||
@@ -42,11 +40,7 @@ func (r *Releasers) GetReleaser() (Releaser, error) {
|
|||||||
return github.New(&r.config.GitHubProvider)
|
return github.New(&r.config.GitHubProvider)
|
||||||
case gitlab.GITLAB:
|
case gitlab.GITLAB:
|
||||||
log.Debugf("initialize new %s-provider", gitlab.GITLAB)
|
log.Debugf("initialize new %s-provider", gitlab.GITLAB)
|
||||||
accessToken, err := util.GetAccessToken(fmt.Sprintf("%s_ACCESS_TOKEN", strings.ToUpper(gitlab.GITLAB)))
|
return gitlab.New(&r.config.GitLabProvider)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return gitlab.New(&r.config.GitLabProvider, accessToken)
|
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("could not initialize a releaser from this type: %s", r.config.Release)
|
return nil, fmt.Errorf("could not initialize a releaser from this type: %s", r.config.Release)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,9 +10,23 @@ 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"`
|
Template string `yaml:"template,omitempty"`
|
||||||
TemplatePath string `yaml:"templatePath,omitempty"`
|
TemplatePath string `yaml:"templatePath,omitempty"`
|
||||||
|
Docker ChangelogDocker `yaml:"docker,omitempty"`
|
||||||
|
NPM ChangelogNPM `yaml:"npm,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
//ChangelogDocker type struct
|
||||||
|
type ChangelogDocker struct {
|
||||||
|
Latest bool `yaml:"latest"`
|
||||||
|
Repository string `yaml:"repository"`
|
||||||
|
}
|
||||||
|
|
||||||
|
//ChangelogNPM type struct
|
||||||
|
type ChangelogNPM struct {
|
||||||
|
YARN bool `yaml:"latest"`
|
||||||
|
Repository string `yaml:"repository"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//Asset type struct
|
//Asset type struct
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package semanticrelease
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Masterminds/semver"
|
"github.com/Masterminds/semver"
|
||||||
@@ -83,8 +82,8 @@ func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool
|
|||||||
firstRelease := false
|
firstRelease := false
|
||||||
|
|
||||||
if lastVersion == nil {
|
if lastVersion == nil {
|
||||||
defaultVersion, _ := semver.NewVersion("1.0.0")
|
lastVersion, _ = semver.NewVersion("1.0.0")
|
||||||
lastVersion = defaultVersion
|
log.Infof("This is the first release, will set version to %s", lastVersion.String())
|
||||||
firstRelease = true
|
firstRelease = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,14 +97,21 @@ func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool
|
|||||||
analyzedCommits := s.analyzer.Analyze(commits)
|
analyzedCommits := s.analyzer.Analyze(commits)
|
||||||
|
|
||||||
var newVersion semver.Version
|
var newVersion semver.Version
|
||||||
|
foundBranchConfig := false
|
||||||
for branch, releaseType := range s.config.Branch {
|
for branch, releaseType := range s.config.Branch {
|
||||||
if provider.Branch == branch || strings.HasPrefix(provider.Branch, branch) {
|
if provider.Branch == branch {
|
||||||
log.Debugf("Found branch config for branch %s with release type %s", provider.Branch, releaseType)
|
log.Debugf("Found branch config for branch %s with release type %s", provider.Branch, releaseType)
|
||||||
newVersion = s.calculator.CalculateNewVersion(analyzedCommits, lastVersion, releaseType, firstRelease)
|
newVersion = s.calculator.CalculateNewVersion(analyzedCommits, lastVersion, releaseType, firstRelease)
|
||||||
|
foundBranchConfig = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !foundBranchConfig {
|
||||||
|
log.Warnf("No branch config found for branch %s, will return last known version", provider.Branch)
|
||||||
|
newVersion = *lastVersion
|
||||||
|
}
|
||||||
|
|
||||||
releaseVersion := shared.ReleaseVersion{
|
releaseVersion := shared.ReleaseVersion{
|
||||||
Next: shared.ReleaseVersionEntry{
|
Next: shared.ReleaseVersionEntry{
|
||||||
Commit: provider.Commit,
|
Commit: provider.Commit,
|
||||||
@@ -119,6 +125,10 @@ func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool
|
|||||||
Commits: analyzedCommits,
|
Commits: analyzedCommits,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if firstRelease {
|
||||||
|
releaseVersion.Last.Version, _ = semver.NewVersion("0.0.0")
|
||||||
|
}
|
||||||
|
|
||||||
log.Infof("New version %s -> %s", lastVersion.String(), newVersion.String())
|
log.Infof("New version %s -> %s", lastVersion.String(), newVersion.String())
|
||||||
err = cache.Write(s.repository, releaseVersion)
|
err = cache.Write(s.repository, releaseVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user