feat(releaser): add git only as releaser, will create a new tag with version only

This commit is contained in:
Nightapes
2020-01-05 18:41:44 +01:00
parent 6211095c38
commit 42fc522a43
19 changed files with 284 additions and 109 deletions

View File

@@ -3,6 +3,7 @@ package config
import (
"io/ioutil"
"os"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
@@ -50,6 +51,20 @@ type GitLabProvider struct {
AccessToken string
}
// GitProvider struct
type GitProvider struct {
Email string `yaml:"email"`
Username string `yaml:"user"`
Auth string `yaml:"auth"`
SSH bool `yaml:"ssh"`
}
// Hooks struct
type Hooks struct {
PreRelease []string `yaml:"preRelease"`
PostRelease []string `yaml:"postRelease"`
}
// ReleaseConfig struct
type ReleaseConfig struct {
CommitFormat string `yaml:"commitFormat"`
@@ -58,7 +73,9 @@ type ReleaseConfig struct {
Release string `yaml:"release,omitempty"`
GitHubProvider GitHubProvider `yaml:"github,omitempty"`
GitLabProvider GitLabProvider `yaml:"gitlab,omitempty"`
GitProvider GitProvider `yaml:"git,omitempty"`
Assets []Asset `yaml:"assets"`
Hooks Hooks `yaml:"hooks"`
ReleaseTitle string `yaml:"title"`
IsPreRelease bool
}
@@ -71,13 +88,31 @@ func Read(configPath string) (*ReleaseConfig, error) {
return &ReleaseConfig{}, err
}
var releaseConfig ReleaseConfig
err = yaml.Unmarshal(content, &releaseConfig)
log.Tracef("Found config %s", string(content))
releaseConfig := &ReleaseConfig{}
err = yaml.Unmarshal(content, releaseConfig)
if err != nil {
return &ReleaseConfig{}, err
}
log.Tracef("Found config %+v", releaseConfig)
org := *releaseConfig
return &releaseConfig, nil
releaseConfig.Hooks = Hooks{}
configWithoutHooks, err := yaml.Marshal(releaseConfig)
if err != nil {
return &ReleaseConfig{}, err
}
configWithoutHooks = []byte(os.ExpandEnv(string(configWithoutHooks)))
releaseConfigWithExpanedEnvs := &ReleaseConfig{}
err = yaml.Unmarshal(configWithoutHooks, releaseConfigWithExpanedEnvs)
if err != nil {
return &ReleaseConfig{}, err
}
releaseConfigWithExpanedEnvs.Hooks = org.Hooks
log.Tracef("Found config %+v", releaseConfigWithExpanedEnvs)
return releaseConfigWithExpanedEnvs, nil
}

View File

@@ -41,6 +41,9 @@ func TestWriteAndReadCache(t *testing.T) {
assert.NoError(t, err)
defer os.RemoveAll(dir)
os.Setenv("TEST_CONFIG", "value")
defer os.Unsetenv("TEST_CONFIG")
completePath := path.Join(path.Dir(dir), ".release.yml")
content := []byte(`
commitFormat: angular
@@ -53,9 +56,12 @@ branch:
add_git_releases: alpha
changelog:
printAll: false
template: ''
templatePath: ''
template: ""
templatePath: '${TEST_CONFIG}'
release: 'github'
hooks:
preRelease:
- "Test hook ${RELEASE_VERSION}"
assets:
- name: ./build/go-semantic-release
compress: false
@@ -76,13 +82,18 @@ github:
Changelog: config.ChangelogConfig{
PrintAll: false,
TemplateTitle: "",
TemplatePath: ""},
TemplatePath: "value"},
Release: "github",
GitHubProvider: config.GitHubProvider{
Repo: "go-semantic-release",
User: "nightapes",
CustomURL: "",
AccessToken: ""},
Hooks: config.Hooks{
PreRelease: []string{
"Test hook ${RELEASE_VERSION}",
},
},
Assets: []config.Asset{
config.Asset{
Name: "./build/go-semantic-release",