From 42fc522a4311018e92ad245c975c006ccd96e06d Mon Sep 17 00:00:00 2001 From: Nightapes Date: Sun, 5 Jan 2020 18:41:44 +0100 Subject: [PATCH 1/6] feat(releaser): add git only as releaser, will create a new tag with version only --- .release.yml | 4 +- cmd/go-semantic-release/commands/changelog.go | 7 +- cmd/go-semantic-release/commands/next.go | 7 +- cmd/go-semantic-release/commands/release.go | 7 +- cmd/go-semantic-release/commands/root.go | 1 + cmd/go-semantic-release/commands/set.go | 7 +- cmd/go-semantic-release/commands/zip.go | 7 +- go.sum | 5 + internal/ci/ci.go | 10 +- internal/ci/ci_test.go | 2 +- internal/releaser/git/git.go | 101 ++++++++++++++++++ internal/releaser/github/github.go | 36 +++---- internal/releaser/github/github_test.go | 22 +--- internal/releaser/gitlab/gitlab.go | 14 +-- internal/releaser/gitlab/gitlab_test.go | 20 ++-- internal/releaser/releaser.go | 18 ++-- pkg/config/config.go | 43 +++++++- pkg/config/config_test.go | 17 ++- pkg/semanticrelease/semantic-release.go | 55 ++++++---- 19 files changed, 279 insertions(+), 104 deletions(-) create mode 100644 internal/releaser/git/git.go diff --git a/.release.yml b/.release.yml index 2f68ae0..d9a0aef 100644 --- a/.release.yml +++ b/.release.yml @@ -1,4 +1,4 @@ -release: 'github' +release: "github" github: repo: "go-semantic-release" user: "nightapes" @@ -13,4 +13,4 @@ assets: changelog: docker: latest: true - repository: "nightapes/go-semantic-release" \ No newline at end of file + repository: "nightapes/go-semantic-release" diff --git a/cmd/go-semantic-release/commands/changelog.go b/cmd/go-semantic-release/commands/changelog.go index 87adf63..f53ca0d 100644 --- a/cmd/go-semantic-release/commands/changelog.go +++ b/cmd/go-semantic-release/commands/changelog.go @@ -35,7 +35,12 @@ var changelogCmd = &cobra.Command{ return err } - s, err := semanticrelease.New(readConfig(config), repository) + ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks") + if err != nil { + return err + } + + s, err := semanticrelease.New(readConfig(config), repository, !ignoreConfigChecks) if err != nil { return err } diff --git a/cmd/go-semantic-release/commands/next.go b/cmd/go-semantic-release/commands/next.go index fc6499c..53d3ced 100644 --- a/cmd/go-semantic-release/commands/next.go +++ b/cmd/go-semantic-release/commands/next.go @@ -30,7 +30,12 @@ var nextCmd = &cobra.Command{ return err } - s, err := semanticrelease.New(readConfig(config), repository) + ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks") + if err != nil { + return err + } + + s, err := semanticrelease.New(readConfig(config), repository, !ignoreConfigChecks) if err != nil { return err } diff --git a/cmd/go-semantic-release/commands/release.go b/cmd/go-semantic-release/commands/release.go index efdd0f8..fea0e52 100644 --- a/cmd/go-semantic-release/commands/release.go +++ b/cmd/go-semantic-release/commands/release.go @@ -28,7 +28,12 @@ var releaseCmd = &cobra.Command{ return err } - s, err := semanticrelease.New(readConfig(config), repository) + ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks") + if err != nil { + return err + } + + s, err := semanticrelease.New(readConfig(config), repository, !ignoreConfigChecks) if err != nil { return err } diff --git a/cmd/go-semantic-release/commands/root.go b/cmd/go-semantic-release/commands/root.go index 87f4421..b05a522 100644 --- a/cmd/go-semantic-release/commands/root.go +++ b/cmd/go-semantic-release/commands/root.go @@ -35,6 +35,7 @@ func init() { rootCmd.PersistentFlags().StringP("loglevel", "l", "error", "Set loglevel") rootCmd.PersistentFlags().StringP("config", "c", ".release.yml", "Path to config file") rootCmd.PersistentFlags().Bool("no-cache", false, "Ignore cache, don't use in ci build") + rootCmd.PersistentFlags().Bool("no-checks", false, "Ignore missing values and envs") } func readConfig(file string) *config.ReleaseConfig { diff --git a/cmd/go-semantic-release/commands/set.go b/cmd/go-semantic-release/commands/set.go index e98618d..7ccae66 100644 --- a/cmd/go-semantic-release/commands/set.go +++ b/cmd/go-semantic-release/commands/set.go @@ -26,7 +26,12 @@ var setCmd = &cobra.Command{ return err } - s, err := semanticrelease.New(readConfig(config), repository) + ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks") + if err != nil { + return err + } + + s, err := semanticrelease.New(readConfig(config), repository, !ignoreConfigChecks) if err != nil { return err } diff --git a/cmd/go-semantic-release/commands/zip.go b/cmd/go-semantic-release/commands/zip.go index 7cda34d..40912dd 100644 --- a/cmd/go-semantic-release/commands/zip.go +++ b/cmd/go-semantic-release/commands/zip.go @@ -23,7 +23,12 @@ var zipCmd = &cobra.Command{ return err } - s, err := semanticrelease.New(readConfig(config), repository) + ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks") + if err != nil { + return err + } + + s, err := semanticrelease.New(readConfig(config), repository, !ignoreConfigChecks) if err != nil { return err } diff --git a/go.sum b/go.sum index 8741862..266bc25 100644 --- a/go.sum +++ b/go.sum @@ -55,6 +55,7 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= @@ -62,6 +63,7 @@ github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQz github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/pelletier/go-buffruneio v0.2.0 h1:U4t4R6YkofJ5xHm3dJzuRpPZ0mr5MMCoAWooScCR7aA= github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo= +github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -72,14 +74,17 @@ github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s= github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= +github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4= github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI= diff --git a/internal/ci/ci.go b/internal/ci/ci.go index 3e21c49..1074aaf 100644 --- a/internal/ci/ci.go +++ b/internal/ci/ci.go @@ -39,13 +39,13 @@ func ReadAllEnvs() map[string]string { } //GetCIProvider get provider -func GetCIProvider(gitUtil *gitutil.GitUtil, envs map[string]string) (*ProviderConfig, error) { +func GetCIProvider(gitUtil *gitutil.GitUtil, configCheck bool, envs map[string]string) (*ProviderConfig, error) { services := []Service{ Travis{}, GithubActions{}, GitlabCI{}, - Git{gitUtil: gitUtil}, // GIt must be the last option to check + Git{gitUtil: gitUtil}, // Git must be the last option to check } for _, service := range services { @@ -57,5 +57,9 @@ func GetCIProvider(gitUtil *gitutil.GitUtil, envs map[string]string) (*ProviderC } log.Debugf("%s", err.Error()) } - return nil, fmt.Errorf("could not find any CI, if running locally set env CI=true") + if configCheck { + return nil, fmt.Errorf("could not find any CI, if running locally set env CI=true") + + } + return Git{gitUtil: gitUtil}.detect(map[string]string{"CI": "true"}) } diff --git a/internal/ci/ci_test.go b/internal/ci/ci_test.go index 57a68e5..2fb65f5 100644 --- a/internal/ci/ci_test.go +++ b/internal/ci/ci_test.go @@ -127,7 +127,7 @@ func TestCi(t *testing.T) { } for _, config := range testConfigs { - provider, err := ci.GetCIProvider(gitUtilInMemory, config.envs) + provider, err := ci.GetCIProvider(gitUtilInMemory, true, config.envs) assert.Equalf(t, config.hasError, err != nil, "Service %s should have error: %t -> %s", config.service, config.hasError, err) assert.Equalf(t, config.result, provider, "Service %s should have provider", config.service) } diff --git a/internal/releaser/git/git.go b/internal/releaser/git/git.go new file mode 100644 index 0000000..a3bef6e --- /dev/null +++ b/internal/releaser/git/git.go @@ -0,0 +1,101 @@ +package git + +import ( + "fmt" + "time" + + "github.com/Nightapes/go-semantic-release/internal/gitutil" + "github.com/Nightapes/go-semantic-release/internal/shared" + "github.com/Nightapes/go-semantic-release/pkg/config" + "gopkg.in/src-d/go-git.v4" + gitConfig "gopkg.in/src-d/go-git.v4/config" + "gopkg.in/src-d/go-git.v4/plumbing/object" + "gopkg.in/src-d/go-git.v4/plumbing/transport/http" + + log "github.com/sirupsen/logrus" +) + +// GITONLY identifer for git interface +const GITONLY = "git" + +// Client type struct +type Client struct { + config *config.GitProvider + log *log.Entry + git *gitutil.GitUtil +} + +// New initialize a new gitRelease +func New(config *config.GitProvider, git *gitutil.GitUtil, checkConfig bool) (*Client, error) { + + logger := log.WithField("releaser", GITONLY) + + if config.Email == "" && checkConfig { + return nil, fmt.Errorf("git email not set") + } + + if config.Username == "" && checkConfig { + return nil, fmt.Errorf("git username not set") + } + + if !config.SSH && config.Auth == "" && checkConfig { + return nil, fmt.Errorf("git auth not set") + } + + if config.SSH { + return nil, fmt.Errorf("git ssh not supported yet") + } + + return &Client{ + config: config, + log: logger, + git: git, + }, nil +} + +//GetCommitURL for git +func (g *Client) GetCommitURL() string { + return "" +} + +//GetCompareURL for git +func (g *Client) GetCompareURL(oldVersion, newVersion string) string { + return "" +} + +// CreateRelease creates release on remote +func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog) error { + + tag := "v" + releaseVersion.Next.Version.String() + g.log.Infof("create release with version %s", tag) + + head, err := g.git.Repository.Head() + if err != nil { + return err + } + + _, err = g.git.Repository.CreateTag(tag, head.Hash(), &git.CreateTagOptions{Message: "Release " + tag, Tagger: &object.Signature{ + Name: g.config.Username, + Email: g.config.Email, + When: time.Now(), + }}) + if err != nil { + return err + } + + g.log.Infof("Created release") + + return g.git.Repository.Push(&git.PushOptions{ + Auth: &http.BasicAuth{ + Username: g.config.Username, + Password: g.config.Auth, + }, + RefSpecs: []gitConfig.RefSpec{"refs/tags/*:refs/tags/*"}, + }) + +} + +// UploadAssets uploads specified assets +func (g *Client) UploadAssets(repoDir string, assets []config.Asset) error { + return nil +} diff --git a/internal/releaser/github/github.go b/internal/releaser/github/github.go index f279636..9033a16 100644 --- a/internal/releaser/github/github.go +++ b/internal/releaser/github/github.go @@ -29,17 +29,27 @@ type Client struct { } // New initialize a new GitHubRelease -func New(c *config.GitHubProvider) (*Client, error) { - var err error +func New(c *config.GitHubProvider, checkConfig bool) (*Client, error) { - if c.AccessToken, err = util.GetAccessToken("GITHUB_TOKEN"); err != nil { + token, err := util.GetAccessToken("GITHUB_TOKEN") + if err != nil && checkConfig { return &Client{}, err } + c.AccessToken = token ctx := context.Background() httpClient := util.CreateBearerHTTPClient(ctx, c.AccessToken) var client *github.Client baseURL := "https://github.com" + + if c.Repo == "" && checkConfig { + return nil, fmt.Errorf("github repro is not set") + } + + if c.User == "" && checkConfig { + return nil, fmt.Errorf("github user is not set") + } + if c.CustomURL == "" { client = github.NewClient(httpClient) } else { @@ -54,7 +64,7 @@ func New(c *config.GitHubProvider) (*Client, error) { context: ctx, baseURL: baseURL, log: log.WithField("releaser", GITHUB), - }, err + }, nil } //GetCommitURL for github @@ -67,26 +77,10 @@ func (g *Client) GetCompareURL(oldVersion, newVersion string) string { return fmt.Sprintf("%s/%s/%s/compare/%s...%s", g.baseURL, g.config.User, g.config.Repo, oldVersion, newVersion) } -//ValidateConfig for github -func (g *Client) ValidateConfig() error { - g.log.Debugf("validate GitHub provider config") - - if g.config.Repo == "" { - return fmt.Errorf("github Repro is not set") - } - - if g.config.User == "" { - return fmt.Errorf("github User is not set") - } - - return nil - -} - // CreateRelease creates release on remote func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog) error { - tag := releaseVersion.Next.Version.String() + tag := "v" + releaseVersion.Next.Version.String() g.log.Debugf("create release with version %s", tag) prerelease := releaseVersion.Next.Version.Prerelease() != "" diff --git a/internal/releaser/github/github_test.go b/internal/releaser/github/github_test.go index 6813c11..179edc1 100644 --- a/internal/releaser/github/github_test.go +++ b/internal/releaser/github/github_test.go @@ -146,7 +146,7 @@ func TestNew(t *testing.T) { os.Setenv("GITHUB_TOKEN", "XXX") } - _, err := github.New(&testOject.config) + _, err := github.New(&testOject.config, true) assert.Equal(t, testOject.valid, err == nil) os.Unsetenv("GITHUB_TOKEN") @@ -157,7 +157,7 @@ func TestNew(t *testing.T) { func TestGetCommitURL(t *testing.T) { os.Setenv("GITHUB_TOKEN", "XX") for _, testOject := range testNewClient { - client, _ := github.New(&testOject.config) + client, _ := github.New(&testOject.config, false) actualURL := client.GetCommitURL() if testOject.config.CustomURL != "" { expectedURL := fmt.Sprintf("%s/%s/%s/commit/{{hash}}", testOject.config.CustomURL, testOject.config.User, testOject.config.Repo) @@ -175,7 +175,7 @@ func TestGetCommitURL(t *testing.T) { func TestGetCompareURL(t *testing.T) { os.Setenv("GITHUB_TOKEN", "XX") for _, testOject := range testNewClient { - client, _ := github.New(&testOject.config) + client, _ := github.New(&testOject.config, false) actualURL := client.GetCompareURL("1", "2") if testOject.config.CustomURL != "" { expectedURL := fmt.Sprintf("%s/%s/%s/compare/%s...%s", testOject.config.CustomURL, testOject.config.User, testOject.config.Repo, "1", "2") @@ -190,18 +190,6 @@ func TestGetCompareURL(t *testing.T) { } -func TestValidateConfig(t *testing.T) { - os.Setenv("GITHUB_TOKEN", "XX") - for _, testOject := range testHelperMethod { - client, _ := github.New(&testOject.config) - err := client.ValidateConfig() - - assert.Equal(t, testOject.valid, err == nil) - - } - os.Unsetenv("GITHUB_TOKEN") -} - func TestCreateRelease(t *testing.T) { os.Setenv("GITHUB_TOKEN", "XX") @@ -209,7 +197,7 @@ func TestCreateRelease(t *testing.T) { if testObejct.valid { server := initHTTPServer(testObejct.requestResponseCode, testObejct.requestResponseBody) testObejct.config.CustomURL = server.URL - client, _ := github.New(&testObejct.config) + client, _ := github.New(&testObejct.config, false) err := client.CreateRelease(testObejct.releaseVersion, testObejct.generatedChangelog) if err != nil { @@ -221,7 +209,7 @@ func TestCreateRelease(t *testing.T) { } else { testObejct.config.CustomURL = "http://foo" - client, _ := github.New(&testObejct.config) + client, _ := github.New(&testObejct.config, false) err := client.CreateRelease(testObejct.releaseVersion, testObejct.generatedChangelog) if err != nil { diff --git a/internal/releaser/gitlab/gitlab.go b/internal/releaser/gitlab/gitlab.go index fe5da5a..98395b7 100644 --- a/internal/releaser/gitlab/gitlab.go +++ b/internal/releaser/gitlab/gitlab.go @@ -34,9 +34,9 @@ type Client struct { } // New initialize a new gitlabRelease -func New(config *config.GitLabProvider) (*Client, error) { +func New(config *config.GitLabProvider, checkConfig bool) (*Client, error) { accessToken, err := util.GetAccessToken(fmt.Sprintf("%s_ACCESS_TOKEN", strings.ToUpper(GITLAB))) - if err != nil { + if err != nil && checkConfig { return nil, err } @@ -52,7 +52,7 @@ func New(config *config.GitLabProvider) (*Client, error) { logger.Debugf("validate gitlab provider config") - if config.Repo == "" { + if config.Repo == "" && checkConfig { return nil, fmt.Errorf("gitlab Repro is not set") } @@ -85,16 +85,10 @@ func (g *Client) GetCompareURL(oldVersion, newVersion string) string { return fmt.Sprintf("%s/%s/compare/%s...%s", g.baseURL, g.config.Repo, oldVersion, newVersion) } -//ValidateConfig for gitlab -func (g *Client) ValidateConfig() error { - return nil - -} - // CreateRelease creates release on remote func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog) error { - tag := releaseVersion.Next.Version.String() + tag := "v" + releaseVersion.Next.Version.String() 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)) diff --git a/internal/releaser/gitlab/gitlab_test.go b/internal/releaser/gitlab/gitlab_test.go index 1418ef6..bdfabcf 100644 --- a/internal/releaser/gitlab/gitlab_test.go +++ b/internal/releaser/gitlab/gitlab_test.go @@ -24,7 +24,7 @@ func TestGetCommitURL(t *testing.T) { client, err := gitlab.New(&config.GitLabProvider{ CustomURL: "https://localhost/", Repo: "test/test", - }) + }, true) assert.NoError(t, err) assert.Equal(t, "https://localhost/test/test/commit/{{hash}}", client.GetCommitURL()) } @@ -35,7 +35,7 @@ func TestGetCompareURL(t *testing.T) { client, err := gitlab.New(&config.GitLabProvider{ CustomURL: "https://localhost/", Repo: "test/test", - }) + }, true) 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")) } @@ -45,7 +45,7 @@ func TestValidateConfig_EmptyRepro(t *testing.T) { defer os.Unsetenv("GITLAB_ACCESS_TOKEN") _, err := gitlab.New(&config.GitLabProvider{ CustomURL: "https://localhost/", - }) + }, true) assert.Error(t, err) } @@ -55,7 +55,7 @@ func TestValidateConfig_DefaultURL(t *testing.T) { config := &config.GitLabProvider{ Repo: "localhost/test", } - _, err := gitlab.New(config) + _, err := gitlab.New(config, true) assert.NoError(t, err) assert.Equal(t, "https://gitlab.com", config.CustomURL) } @@ -67,7 +67,7 @@ func TestValidateConfig_CustomURL(t *testing.T) { Repo: "/localhost/test/", CustomURL: "https://localhost/", } - _, err := gitlab.New(config) + _, err := gitlab.New(config, true) assert.NoError(t, err) assert.Equal(t, "https://localhost", config.CustomURL) assert.Equal(t, "localhost/test", config.Repo) @@ -108,7 +108,7 @@ func TestCreateRelease(t *testing.T) { }, responseBody: "{}", responseCode: 200, - requestBody: `{"tag_name":"2.0.0","name":"title","ref":"master","description":"content"}`, + requestBody: `{"tag_name":"v2.0.0","name":"title","ref":"master","description":"content"}`, valid: true, }, { @@ -132,7 +132,7 @@ func TestCreateRelease(t *testing.T) { }, responseBody: "{}", responseCode: 500, - requestBody: `{"tag_name":"2.0.0","name":"title","ref":"master","description":"content"}`, + requestBody: `{"tag_name":"v2.0.0","name":"title","ref":"master","description":"content"}`, valid: false, }, { @@ -157,7 +157,7 @@ func TestCreateRelease(t *testing.T) { }, responseCode: 400, responseBody: "{}", - requestBody: `{"tag_name":"2.0.0","name":"title","ref":"master","description":"content"}`, + requestBody: `{"tag_name":"v2.0.0","name":"title","ref":"master","description":"content"}`, valid: false, }, } @@ -190,7 +190,7 @@ func TestCreateRelease(t *testing.T) { } os.Setenv("GITLAB_ACCESS_TOKEN", "aToken") defer os.Unsetenv("GITLAB_ACCESS_TOKEN") - client, err := gitlab.New(&testObject.config) + client, err := gitlab.New(&testObject.config, false) assert.NoError(t, err) err = client.CreateRelease(testObject.releaseVersion, testObject.generatedChangelog) @@ -317,7 +317,7 @@ func TestUploadAssets(t *testing.T) { } os.Setenv("GITLAB_ACCESS_TOKEN", "aToken") defer os.Unsetenv("GITLAB_ACCESS_TOKEN") - client, err := gitlab.New(&testObject.config) + client, err := gitlab.New(&testObject.config, false) assert.NoError(t, err) client.Release = "1.0.0" diff --git a/internal/releaser/releaser.go b/internal/releaser/releaser.go index b2a9863..465525f 100644 --- a/internal/releaser/releaser.go +++ b/internal/releaser/releaser.go @@ -3,6 +3,8 @@ package releaser import ( "fmt" + "github.com/Nightapes/go-semantic-release/internal/gitutil" + "github.com/Nightapes/go-semantic-release/internal/releaser/git" "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/shared" @@ -14,33 +16,37 @@ import ( // Releasers struct type type Releasers struct { config *config.ReleaseConfig + git *gitutil.GitUtil } // Releaser interface for providers type Releaser interface { - ValidateConfig() error CreateRelease(*shared.ReleaseVersion, *shared.GeneratedChangelog) error UploadAssets(repoDir string, assets []config.Asset) error GetCommitURL() string GetCompareURL(oldVersion, newVersion string) string } -// New initialize a Relerser -func New(c *config.ReleaseConfig) *Releasers { +// New initialize a releaser +func New(c *config.ReleaseConfig, git *gitutil.GitUtil) *Releasers { return &Releasers{ config: c, + git: git, } } //GetReleaser returns an initialized releaser -func (r *Releasers) GetReleaser() (Releaser, error) { +func (r *Releasers) GetReleaser(checkConfig bool) (Releaser, error) { switch r.config.Release { case github.GITHUB: log.Debugf("initialize new %s-provider", github.GITHUB) - return github.New(&r.config.GitHubProvider) + return github.New(&r.config.GitHubProvider, checkConfig) case gitlab.GITLAB: log.Debugf("initialize new %s-provider", gitlab.GITLAB) - return gitlab.New(&r.config.GitLabProvider) + return gitlab.New(&r.config.GitLabProvider, checkConfig) + case git.GITONLY: + log.Debugf("initialize new %s-provider", git.GITONLY) + return git.New(&r.config.GitProvider, r.git, checkConfig) } return nil, fmt.Errorf("could not initialize a releaser from this type: %s", r.config.Release) } diff --git a/pkg/config/config.go b/pkg/config/config.go index 6db6f68..8d795d2 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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 + } + + org := *releaseConfig + + 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", releaseConfig) + log.Tracef("Found config %+v", releaseConfigWithExpanedEnvs) - return &releaseConfig, nil + return releaseConfigWithExpanedEnvs, nil } diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index b2bb0f1..1776940 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -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", diff --git a/pkg/semanticrelease/semantic-release.go b/pkg/semanticrelease/semantic-release.go index bea56bb..2f851f7 100644 --- a/pkg/semanticrelease/semantic-release.go +++ b/pkg/semanticrelease/semantic-release.go @@ -11,6 +11,7 @@ import ( "github.com/Nightapes/go-semantic-release/internal/changelog" "github.com/Nightapes/go-semantic-release/internal/ci" "github.com/Nightapes/go-semantic-release/internal/gitutil" + "github.com/Nightapes/go-semantic-release/internal/hooks" "github.com/Nightapes/go-semantic-release/internal/releaser" "github.com/Nightapes/go-semantic-release/internal/releaser/util" "github.com/Nightapes/go-semantic-release/internal/shared" @@ -20,16 +21,17 @@ import ( // SemanticRelease struct type SemanticRelease struct { - config *config.ReleaseConfig - gitutil *gitutil.GitUtil - analyzer *analyzer.Analyzer - calculator *calculator.Calculator - releaser releaser.Releaser - repository string + config *config.ReleaseConfig + gitutil *gitutil.GitUtil + analyzer *analyzer.Analyzer + calculator *calculator.Calculator + releaser releaser.Releaser + repository string + checkConfig bool } // New SemanticRelease struct -func New(c *config.ReleaseConfig, repository string) (*SemanticRelease, error) { +func New(c *config.ReleaseConfig, repository string, checkConfig bool) (*SemanticRelease, error) { util, err := gitutil.New(repository) if err != nil { return nil, err @@ -40,24 +42,29 @@ func New(c *config.ReleaseConfig, repository string) (*SemanticRelease, error) { return nil, err } - releaser, err := releaser.New(c).GetReleaser() + if !checkConfig { + log.Infof("Ignore config checks!. No guarantee to run without issues") + } + + releaser, err := releaser.New(c, util).GetReleaser(checkConfig) if err != nil { return nil, err } return &SemanticRelease{ - config: c, - gitutil: util, - releaser: releaser, - analyzer: analyzer, - repository: repository, - calculator: calculator.New(), + config: c, + gitutil: util, + releaser: releaser, + analyzer: analyzer, + repository: repository, + checkConfig: checkConfig, + calculator: calculator.New(), }, nil } //GetCIProvider result with ci config func (s *SemanticRelease) GetCIProvider() (*ci.ProviderConfig, error) { - return ci.GetCIProvider(s.gitutil, ci.ReadAllEnvs()) + return ci.GetCIProvider(s.gitutil, s.checkConfig, ci.ReadAllEnvs()) } // GetNextVersion from .version or calculate new from commits @@ -183,7 +190,7 @@ func (s *SemanticRelease) WriteChangeLog(changelogContent, file string) error { return ioutil.WriteFile(file, []byte(changelogContent), 0644) } -// Release pusblish release to provider +// Release publish release to provider func (s *SemanticRelease) Release(provider *ci.ProviderConfig, force bool) error { if provider.IsPR { @@ -207,27 +214,31 @@ func (s *SemanticRelease) Release(provider *ci.ProviderConfig, force bool) error return nil } - generatedChanglog, err := s.GetChangelog(releaseVersion) + hook := hooks.New(s.config, releaseVersion) + + generatedChangelog, err := s.GetChangelog(releaseVersion) if err != nil { log.Debugf("Could not get changelog") return err } - releaser, err := releaser.New(s.config).GetReleaser() + err = hook.PreRelease() if err != nil { + log.Debugf("Error during pre release hook") return err } - err = releaser.ValidateConfig() - if err != nil { + if err = s.releaser.CreateRelease(releaseVersion, generatedChangelog); err != nil { return err } - if err = releaser.CreateRelease(releaseVersion, generatedChanglog); err != nil { + if err = s.releaser.UploadAssets(s.repository, s.config.Assets); err != nil { return err } - if err = releaser.UploadAssets(s.repository, s.config.Assets); err != nil { + err = hook.PostRelease() + if err != nil { + log.Debugf("Error during post release hook") return err } From 8ea92efb90615dcd231b1c05c73baea207eaa72e Mon Sep 17 00:00:00 2001 From: Nightapes Date: Sun, 5 Jan 2020 18:42:07 +0100 Subject: [PATCH 2/6] feat(hooks): add pre and post release hooks --- internal/hooks/hooks.go | 71 ++++++++++++++++++++++++ internal/hooks/hooks_test.go | 103 +++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 internal/hooks/hooks.go create mode 100644 internal/hooks/hooks_test.go diff --git a/internal/hooks/hooks.go b/internal/hooks/hooks.go new file mode 100644 index 0000000..1b51195 --- /dev/null +++ b/internal/hooks/hooks.go @@ -0,0 +1,71 @@ +package hooks + +import ( + "bufio" + "os/exec" + "strings" + + "github.com/Nightapes/go-semantic-release/internal/shared" + "github.com/Nightapes/go-semantic-release/pkg/config" + log "github.com/sirupsen/logrus" +) + +//Hooks struct +type Hooks struct { + version *shared.ReleaseVersion + config *config.ReleaseConfig +} + +// New hooks struct +func New(config *config.ReleaseConfig, version *shared.ReleaseVersion) *Hooks { + return &Hooks{ + config: config, + version: version, + } +} + +// PreRelease runs before creating release +func (h *Hooks) PreRelease() error { + log.Infof("Run pre release hooks") + for _, cmd := range h.config.Hooks.PreRelease { + log.Debugf("Run %s", cmd) + err := h.runCommand(cmd) + if err != nil { + return err + } + } + return nil +} + +// PostRelease runs after creating release +func (h *Hooks) PostRelease() error { + log.Infof("Run post release hooks") + for _, cmd := range h.config.Hooks.PostRelease { + err := h.runCommand(cmd) + if err != nil { + return err + } + } + return nil +} + +func (h *Hooks) runCommand(command string) error { + + splittedCmd := strings.Split(strings.ReplaceAll(command, "$RELEASE_VERSION", h.version.Next.Version.String()), " ") + + cmd := exec.Command(splittedCmd[0], splittedCmd[1:]...) + + cmdReader, err := cmd.StdoutPipe() + if err != nil { + return err + } + + scanner := bufio.NewScanner(cmdReader) + go func() { + for scanner.Scan() { + log.WithField("cmd", splittedCmd[0]).Infof("%s\n", scanner.Text()) + } + }() + + return cmd.Run() +} diff --git a/internal/hooks/hooks_test.go b/internal/hooks/hooks_test.go new file mode 100644 index 0000000..c4b84ec --- /dev/null +++ b/internal/hooks/hooks_test.go @@ -0,0 +1,103 @@ +package hooks_test + +import ( + "os" + "testing" + + "github.com/Masterminds/semver" + "github.com/Nightapes/go-semantic-release/internal/hooks" + "github.com/Nightapes/go-semantic-release/internal/shared" + "github.com/Nightapes/go-semantic-release/pkg/config" + "github.com/stretchr/testify/assert" +) + +func TestPreReleaseHooks(t *testing.T) { + + os.Setenv("GO_WANT_HELPER_PROCESS", "1") + hooks := hooks.New(&config.ReleaseConfig{ + Hooks: config.Hooks{ + PreRelease: []string{ + "go test -test.run=TestHelperProcess -- " + "$RELEASE_VERSION", + }, + }, + }, + &shared.ReleaseVersion{ + Next: shared.ReleaseVersionEntry{ + Version: createVersion("1.0.0"), + }, + }) + err := hooks.PreRelease() + assert.NoError(t, err) + os.Unsetenv("GO_WANT_HELPER_PROCESS") + +} + +func TestPreReleaseHooksError(t *testing.T) { + + hooks := hooks.New(&config.ReleaseConfig{ + Hooks: config.Hooks{ + PreRelease: []string{ + "exit 1", + }, + }, + }, + &shared.ReleaseVersion{ + Next: shared.ReleaseVersionEntry{ + Version: createVersion("1.0.0"), + }, + }) + err := hooks.PreRelease() + assert.Error(t, err) +} + +func TestPostReleaseHooks(t *testing.T) { + + os.Setenv("GO_WANT_HELPER_PROCESS", "1") + hooks := hooks.New(&config.ReleaseConfig{ + Hooks: config.Hooks{ + PostRelease: []string{ + "go test -test.run=TestHelperProcess -- " + "$RELEASE_VERSION", + }, + }, + }, + &shared.ReleaseVersion{ + Next: shared.ReleaseVersionEntry{ + Version: createVersion("1.0.0"), + }, + }) + err := hooks.PostRelease() + assert.NoError(t, err) + os.Unsetenv("GO_WANT_HELPER_PROCESS") + +} + +func TestPostReleaseHooksError(t *testing.T) { + + hooks := hooks.New(&config.ReleaseConfig{ + Hooks: config.Hooks{ + PostRelease: []string{ + "exit 1", + }, + }, + }, + &shared.ReleaseVersion{ + Next: shared.ReleaseVersionEntry{ + Version: createVersion("1.0.0"), + }, + }) + err := hooks.PostRelease() + assert.Error(t, err) +} + +func TestHelperProcess(t *testing.T) { + if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" { + + return + } + assert.Equal(t, "1.0.0", os.Args[3]) +} + +func createVersion(version string) *semver.Version { + ver, _ := semver.NewVersion(version) + return ver +} From 8e3c446605f4dd45c735127bb135e6d7aa32271a Mon Sep 17 00:00:00 2001 From: Nightapes Date: Sun, 5 Jan 2020 18:53:23 +0100 Subject: [PATCH 3/6] docs(README): add hooks --- README.md | 27 +++++++++++++++++++++++++-- internal/cache/cache_test.go | 2 +- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ed53712..4ebe426 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ | ---------- | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: | | `github` | :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: | | :white_check_mark: | -| `git` | Comming soon | :white_check_mark: | | | :white_check_mark: | | +| `git` | :white_check_mark: | :white_check_mark: | | | :white_check_mark: | | | `bitbuckt` | Comming soon | :white_check_mark: | | | :white_check_mark: | | @@ -37,6 +37,11 @@ assets: compress: false - name: ./build/go-semantic-release.exe compress: false +hooks: + preRelease: + - name: echo $RELEASE_VERSION + postRelease: + - name: echo $RELEASE_VERSION ``` #### CommitFormat @@ -65,7 +70,7 @@ branch: : ``` -#### Relase +#### Release At the moment we support releases to gitlab and github. @@ -95,6 +100,20 @@ gitlab: customUrl: ``` +##### Git only + +Only via https at the moment. You need write access to your git repository + + +```yml +release: 'git' +git: + email: "" # Used for creating tag + user: "" : # Used for creating tag and pushing + auth: "" # Used for pushing, can be env "$GIT_TOKEN", will be replaced with env +``` + + #### Assets You can upload assets to a release @@ -108,6 +127,10 @@ assets: compress: false ``` +#### Hooks + +Hooks will run when calling `release`. Hooks run only if a release will be triggered. + #### Changelog Following variables can be used for templates: diff --git a/internal/cache/cache_test.go b/internal/cache/cache_test.go index 2660e05..2fe71de 100644 --- a/internal/cache/cache_test.go +++ b/internal/cache/cache_test.go @@ -63,7 +63,7 @@ func TestWriteAndReadCache(t *testing.T) { Author: "Author", Hash: "Hash", }, - ParsedMessage: "add gitlab as relase option", + ParsedMessage: "add gitlab as release option", Scope: "releaser", ParsedBreakingChangeMessage: "", Tag: "feat", From 113ddf2b1fc83705c1685b052b37c646303af082 Mon Sep 17 00:00:00 2001 From: Nightapes Date: Sun, 5 Jan 2020 19:02:20 +0100 Subject: [PATCH 4/6] build(ci): use new hooks for docker release --- .github/workflows/main.yml | 105 ++++++++++++++++--------------------- .release.yml | 7 +++ 2 files changed, 51 insertions(+), 61 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4b4e3f1..d7d960b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,68 +1,51 @@ name: Go on: [push, pull_request] jobs: - build: name: Build runs-on: ubuntu-latest steps: - - - name: Set up Go 1.13 - uses: actions/setup-go@v1 - with: - go-version: 1.13 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v1 - - - name: Lint - run: | - 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.18.0 - golangci-lint run ./... - - - name: Run tests - run: go test ./... - - - name: Build binary - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - go build -o build/go-semantic-release-temp ./cmd/go-semantic-release/ - ./build/go-semantic-release-temp next --no-cache --loglevel trace - 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 }} - run: ./build/go-semantic-release-temp release --loglevel trace \ No newline at end of file + - name: Set up Go 1.13 + uses: actions/setup-go@v1 + with: + go-version: 1.13 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + + - name: Lint + run: | + 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.18.0 + golangci-lint run ./... + + - name: Run tests + run: go test ./... + + - name: Build binary + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + go build -o build/go-semantic-release-temp ./cmd/go-semantic-release/ + ./build/go-semantic-release-temp next --no-cache --loglevel trace + 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 + if: github.ref != 'refs/heads/master' + run: | + docker build -t nightapes/go-semantic-release:development . + docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }} + docker push nightapes/go-semantic-release:development + + - name: Push Docker image + if: github.ref != 'refs/heads/master' + run: | + + - name: Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }} + ./build/go-semantic-release-temp release --loglevel trace diff --git a/.release.yml b/.release.yml index d9a0aef..64892da 100644 --- a/.release.yml +++ b/.release.yml @@ -14,3 +14,10 @@ changelog: docker: latest: true repository: "nightapes/go-semantic-release" +hooks: + preRelease: + - docker build -t nightapes/go-semantic-release:latest . + - docker build -t nightapes/go-semantic-release:$RELEASE_VERSION . + postRelease: + - docker push nightapes/go-semantic-release:latest + - docker push nightapes/go-semantic-release:$RELEASE_VERSION From aff2203d66802570103bbda2ea1a965cedd199e5 Mon Sep 17 00:00:00 2001 From: Nightapes Date: Sun, 5 Jan 2020 19:06:15 +0100 Subject: [PATCH 5/6] style(github): fix lint issues --- internal/releaser/github/github_test.go | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/internal/releaser/github/github_test.go b/internal/releaser/github/github_test.go index 179edc1..a40b2a2 100644 --- a/internal/releaser/github/github_test.go +++ b/internal/releaser/github/github_test.go @@ -48,29 +48,6 @@ var testNewClient = []testHelperMethodStruct{ }, } -var testHelperMethod = []testHelperMethodStruct{ - testHelperMethodStruct{config: config.GitHubProvider{ - Repo: "foo", - User: "bar", - }, - valid: true, - }, - - testHelperMethodStruct{config: config.GitHubProvider{ - Repo: "", - User: "bar", - }, - valid: false, - }, - - testHelperMethodStruct{config: config.GitHubProvider{ - Repo: "foo", - User: "", - }, - valid: false, - }, -} - var lastVersion, _ = semver.NewVersion("1.0.0") var newVersion, _ = semver.NewVersion("2.0.0") From d92438b339860499a7e668dbe103ec3baa4d4fa0 Mon Sep 17 00:00:00 2001 From: Nightapes Date: Sun, 5 Jan 2020 19:10:07 +0100 Subject: [PATCH 6/6] test(hooks): fix testing --- internal/hooks/hooks_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/hooks/hooks_test.go b/internal/hooks/hooks_test.go index c4b84ec..6d67225 100644 --- a/internal/hooks/hooks_test.go +++ b/internal/hooks/hooks_test.go @@ -94,7 +94,7 @@ func TestHelperProcess(t *testing.T) { return } - assert.Equal(t, "1.0.0", os.Args[3]) + assert.Contains(t, os.Args, "1.0.0") } func createVersion(version string) *semver.Version {