From cf960ed8219ae8a21660d1f7f70fd5d444a41c89 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 5 Feb 2020 22:55:21 -0300 Subject: [PATCH 1/6] feat: upload extra files to the release Signed-off-by: Carlos Alexandro Becker --- go.sum | 1 + internal/artifact/artifact.go | 2 + internal/pipe/release/release.go | 74 ++++++++++++++++----------- internal/pipe/release/release_test.go | 25 +++++++++ pkg/config/config.go | 17 +++--- www/content/release.md | 21 ++++++++ 6 files changed, 101 insertions(+), 39 deletions(-) diff --git a/go.sum b/go.sum index e31811af0c2..4732ca1d3b4 100644 --- a/go.sum +++ b/go.sum @@ -88,6 +88,7 @@ github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY= github.com/google/go-github/v28 v28.1.1 h1:kORf5ekX5qwXO2mGzXXOjMe/g6ap8ahVe0sBEulhSxo= github.com/google/go-github/v28 v28.1.1/go.mod h1:bsqJWQX05omyWVmc00nEUql9mhQyv38lDZ8kPZcQVoM= github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= diff --git a/internal/artifact/artifact.go b/internal/artifact/artifact.go index e38c40d811f..fb161ad2e9e 100644 --- a/internal/artifact/artifact.go +++ b/internal/artifact/artifact.go @@ -27,6 +27,8 @@ const ( UploadableArchive Type = iota // UploadableBinary is a binary file to be uploaded UploadableBinary + // UploadableFile is any file that can be uploaded + UploadableFile // Binary is a binary (output of a gobuild) Binary // LinuxPackage is a linux package generated by nfpm diff --git a/internal/pipe/release/release.go b/internal/pipe/release/release.go index 4b31fd122af..67002824592 100644 --- a/internal/pipe/release/release.go +++ b/internal/pipe/release/release.go @@ -123,44 +123,36 @@ func doPublish(ctx *context.Context, client client.Client) error { return err } - var filters = []artifact.Filter{ - artifact.Or( - artifact.ByType(artifact.UploadableArchive), - artifact.ByType(artifact.UploadableBinary), - artifact.ByType(artifact.Checksum), - artifact.ByType(artifact.Signature), - artifact.ByType(artifact.LinuxPackage), - ), + for name, path := range ctx.Config.Release.ExtraFiles { + if _, err := os.Stat(path); os.IsNotExist(err) { + return errors.Wrapf(err, "failed to upload %s", name) + } + ctx.Artifacts.Add(&artifact.Artifact{ + Name: name, + Path: path, + Type: artifact.UploadableFile, + }) } + var filters = artifact.Or( + artifact.ByType(artifact.UploadableArchive), + artifact.ByType(artifact.UploadableBinary), + artifact.ByType(artifact.Checksum), + artifact.ByType(artifact.Signature), + artifact.ByType(artifact.LinuxPackage), + ) + if len(ctx.Config.Release.IDs) > 0 { - filters = append(filters, artifact.ByIDs(ctx.Config.Release.IDs...)) + filters = artifact.And(filters, artifact.ByIDs(ctx.Config.Release.IDs...)) } + filters = artifact.Or(filters, artifact.ByType(artifact.UploadableFile)) + var g = semerrgroup.New(ctx.Parallelism) - for _, artifact := range ctx.Artifacts.Filter(artifact.And(filters...)).List() { + for _, artifact := range ctx.Artifacts.Filter(filters).List() { artifact := artifact g.Go(func() error { - var repeats uint - what := func(try uint) error { - repeats = try + 1 - if uploadErr := upload(ctx, client, releaseID, artifact); uploadErr != nil { - log.WithFields(log.Fields{ - "try": try, - "artifact": artifact.Name, - }).Warnf("failed to upload artifact, will retry") - return uploadErr - } - return nil - } - how := []func(uint, error) bool{ - strategy.Limit(10), - strategy.Backoff(backoff.Linear(50 * time.Millisecond)), - } - if err := retry.Try(ctx, what, how...); err != nil { - return errors.Wrapf(err, "failed to upload %s after %d retries", artifact.Name, repeats) - } - return nil + return upload(ctx, client, releaseID, artifact) }) } return g.Wait() @@ -173,5 +165,25 @@ func upload(ctx *context.Context, client client.Client, releaseID string, artifa } defer file.Close() // nolint: errcheck log.WithField("file", file.Name()).WithField("name", artifact.Name).Info("uploading to release") - return client.Upload(ctx, releaseID, artifact, file) + + var repeats uint + what := func(try uint) error { + repeats = try + 1 + if err := client.Upload(ctx, releaseID, artifact, file); err != nil { + log.WithFields(log.Fields{ + "try": try, + "artifact": artifact.Name, + }).Warnf("failed to upload artifact, will retry") + return err + } + return nil + } + how := []func(uint, error) bool{ + strategy.Limit(10), + strategy.Backoff(backoff.Linear(50 * time.Millisecond)), + } + if err := retry.Try(ctx, what, how...); err != nil { + return errors.Wrapf(err, "failed to upload %s after %d retries", artifact.Name, repeats) + } + return nil } diff --git a/internal/pipe/release/release_test.go b/internal/pipe/release/release_test.go index 898883955d1..60deb5ac2a2 100644 --- a/internal/pipe/release/release_test.go +++ b/internal/pipe/release/release_test.go @@ -104,6 +104,9 @@ func TestRunPipeWithIDsThenFilters(t *testing.T) { Name: "test", }, IDs: []string{"foo"}, + ExtraFiles: map[string]string{ + "test1": "./testdata/release1.golden", + }, }, } var ctx = context.New(config) @@ -146,6 +149,7 @@ func TestRunPipeWithIDsThenFilters(t *testing.T) { assert.True(t, client.UploadedFile) assert.Contains(t, client.UploadedFileNames, "bin.deb") assert.Contains(t, client.UploadedFileNames, "bin.tar.gz") + assert.Contains(t, client.UploadedFileNames, "test1") assert.NotContains(t, client.UploadedFileNames, "filtered.deb") assert.NotContains(t, client.UploadedFileNames, "filtered.tar.gz") } @@ -219,6 +223,27 @@ func TestRunPipeUploadFailure(t *testing.T) { assert.False(t, client.UploadedFile) } +func TestRunPipeExtraFileNotFound(t *testing.T) { + var config = config.Project{ + Release: config.Release{ + GitHub: config.Repo{ + Owner: "test", + Name: "test", + }, + ExtraFiles: map[string]string{ + "test1": "./testdata/release2.golden", + "lala": "./nope", + }, + }, + } + var ctx = context.New(config) + ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"} + client := &DummyClient{} + assert.EqualError(t, doPublish(ctx, client), "failed to upload lala: stat ./nope: no such file or directory") + assert.True(t, client.CreatedRelease) + assert.False(t, client.UploadedFile) +} + func TestRunPipeUploadRetry(t *testing.T) { folder, err := ioutil.TempDir("", "goreleasertest") assert.NoError(t, err) diff --git a/pkg/config/config.go b/pkg/config/config.go index e714c5ffc87..6103187d269 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -178,14 +178,15 @@ type Archive struct { // Release config used for the GitHub/GitLab release type Release struct { - GitHub Repo `yaml:",omitempty"` - GitLab Repo `yaml:",omitempty"` - Gitea Repo `yaml:",omitempty"` - Draft bool `yaml:",omitempty"` - Disable bool `yaml:",omitempty"` - Prerelease string `yaml:",omitempty"` - NameTemplate string `yaml:"name_template,omitempty"` - IDs []string `yaml:"ids,omitempty"` + GitHub Repo `yaml:",omitempty"` + GitLab Repo `yaml:",omitempty"` + Gitea Repo `yaml:",omitempty"` + Draft bool `yaml:",omitempty"` + Disable bool `yaml:",omitempty"` + Prerelease string `yaml:",omitempty"` + NameTemplate string `yaml:"name_template,omitempty"` + IDs []string `yaml:"ids,omitempty"` + ExtraFiles map[string]string `yaml:"extra_files,omitempty"` } // NFPM config diff --git a/www/content/release.md b/www/content/release.md index fa585bdea45..ec248e90b9c 100644 --- a/www/content/release.md +++ b/www/content/release.md @@ -45,6 +45,13 @@ release: # GitHub. # Defaults to false. disable: true + + # You can add extra pre-existing files to the release. + # The left side is the name you want on the github release and the right + # side is the path to the file. + # Defaults to empty. + extra_files: + name_on_github: ./path/to/file.txt ``` Second, let's see what can be customized in the `release` section for GitLab. @@ -73,6 +80,13 @@ release: # GitLab. # Defaults to false. disable: true + + # You can add extra pre-existing files to the release. + # The left side is the name you want on the gitlab release and the right + # side is the path to the file. + # Defaults to empty. + extra_files: + name_on_gitlab: ./path/to/file.txt ``` You can also configure the `release` section to upload to a [Gitea](https://gitea.io) instance: @@ -99,6 +113,13 @@ release: # Gitea. # Defaults to false. disable: true + + # You can add extra pre-existing files to the release. + # The left side is the name you want on the gitea release and the right + # side is the path to the file. + # Defaults to empty. + extra_files: + name_on_gitea: ./path/to/file.txt ``` To enable uploading `tar.gz` and `checksums.txt` files you need to add the following to your Gitea config in `app.ini`: From 72dcbaaa3937c0f80b364668ec2cfa7412df0cf3 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 5 Feb 2020 22:59:42 -0300 Subject: [PATCH 2/6] fix: retry upload Signed-off-by: Carlos Alexandro Becker --- internal/pipe/release/release.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/internal/pipe/release/release.go b/internal/pipe/release/release.go index 67002824592..ad4c8f448d6 100644 --- a/internal/pipe/release/release.go +++ b/internal/pipe/release/release.go @@ -159,16 +159,15 @@ func doPublish(ctx *context.Context, client client.Client) error { } func upload(ctx *context.Context, client client.Client, releaseID string, artifact *artifact.Artifact) error { - file, err := os.Open(artifact.Path) - if err != nil { - return err - } - defer file.Close() // nolint: errcheck - log.WithField("file", file.Name()).WithField("name", artifact.Name).Info("uploading to release") - var repeats uint what := func(try uint) error { repeats = try + 1 + file, err := os.Open(artifact.Path) + if err != nil { + return err + } + defer file.Close() // nolint: errcheck + log.WithField("file", file.Name()).WithField("name", artifact.Name).Info("uploading to release") if err := client.Upload(ctx, releaseID, artifact, file); err != nil { log.WithFields(log.Fields{ "try": try, From 6d469707860f954214d7bd1068bce7f18d98b568 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 5 Feb 2020 23:00:38 -0300 Subject: [PATCH 3/6] fix: go mod tidy Signed-off-by: Carlos Alexandro Becker --- go.sum | 1 - 1 file changed, 1 deletion(-) diff --git a/go.sum b/go.sum index 4732ca1d3b4..e31811af0c2 100644 --- a/go.sum +++ b/go.sum @@ -88,7 +88,6 @@ github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY= github.com/google/go-github/v28 v28.1.1 h1:kORf5ekX5qwXO2mGzXXOjMe/g6ap8ahVe0sBEulhSxo= github.com/google/go-github/v28 v28.1.1/go.mod h1:bsqJWQX05omyWVmc00nEUql9mhQyv38lDZ8kPZcQVoM= github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= From 4a5feeecd8ff44a8e16d1c4dea1ea7bc19fd5be6 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Mon, 10 Feb 2020 23:46:00 -0300 Subject: [PATCH 4/6] fix: globs Signed-off-by: Carlos Alexandro Becker --- internal/pipe/release/release.go | 31 ++++++++++++- internal/pipe/release/release_test.go | 45 ++++++++++++++++--- .../pipe/release/testdata/upload_same_name/f1 | 0 .../release/testdata/upload_same_name/f2/f1 | 0 pkg/config/config.go | 18 ++++---- www/content/release.md | 30 ++++++++----- 6 files changed, 95 insertions(+), 29 deletions(-) create mode 100644 internal/pipe/release/testdata/upload_same_name/f1 create mode 100644 internal/pipe/release/testdata/upload_same_name/f2/f1 diff --git a/internal/pipe/release/release.go b/internal/pipe/release/release.go index ad4c8f448d6..3a4c9399731 100644 --- a/internal/pipe/release/release.go +++ b/internal/pipe/release/release.go @@ -1,7 +1,9 @@ package release import ( + "fmt" "os" + "path/filepath" "time" "github.com/apex/log" @@ -13,6 +15,7 @@ import ( "github.com/kamilsk/retry/v4" "github.com/kamilsk/retry/v4/backoff" "github.com/kamilsk/retry/v4/strategy" + "github.com/mattn/go-zglob" "github.com/pkg/errors" ) @@ -123,7 +126,12 @@ func doPublish(ctx *context.Context, client client.Client) error { return err } - for name, path := range ctx.Config.Release.ExtraFiles { + extraFiles, err := findFiles(ctx) + if err != nil { + return err + } + + for name, path := range extraFiles { if _, err := os.Stat(path); os.IsNotExist(err) { return errors.Wrapf(err, "failed to upload %s", name) } @@ -186,3 +194,24 @@ func upload(ctx *context.Context, client client.Client, releaseID string, artifa } return nil } + +func findFiles(ctx *context.Context) (map[string]string, error) { + var result = map[string]string{} + for _, glob := range ctx.Config.Release.ExtraFilesGlobs { + files, err := zglob.Glob(glob) + if err != nil { + return result, fmt.Errorf("globbing failed for pattern %s: %s", glob, err.Error()) + } + for _, file := range files { + if info, _ := os.Stat(file); info.IsDir() { + continue + } + var name = filepath.Base(file) + if old, ok := result[name]; ok { + log.Warnf("overriding %s with %s for name %s", old, file, name) + } + result[name] = file + } + } + return result, nil +} diff --git a/internal/pipe/release/release_test.go b/internal/pipe/release/release_test.go index 60deb5ac2a2..fccc7987cbb 100644 --- a/internal/pipe/release/release_test.go +++ b/internal/pipe/release/release_test.go @@ -4,6 +4,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strings" "sync" "testing" @@ -104,8 +105,8 @@ func TestRunPipeWithIDsThenFilters(t *testing.T) { Name: "test", }, IDs: []string{"foo"}, - ExtraFiles: map[string]string{ - "test1": "./testdata/release1.golden", + ExtraFilesGlobs: []string{ + "./testdata/**/*", }, }, } @@ -149,7 +150,9 @@ func TestRunPipeWithIDsThenFilters(t *testing.T) { assert.True(t, client.UploadedFile) assert.Contains(t, client.UploadedFileNames, "bin.deb") assert.Contains(t, client.UploadedFileNames, "bin.tar.gz") - assert.Contains(t, client.UploadedFileNames, "test1") + assert.Contains(t, client.UploadedFileNames, "release1.golden") + assert.Contains(t, client.UploadedFileNames, "release2.golden") + assert.Contains(t, client.UploadedFileNames, "f1") assert.NotContains(t, client.UploadedFileNames, "filtered.deb") assert.NotContains(t, client.UploadedFileNames, "filtered.tar.gz") } @@ -230,20 +233,43 @@ func TestRunPipeExtraFileNotFound(t *testing.T) { Owner: "test", Name: "test", }, - ExtraFiles: map[string]string{ - "test1": "./testdata/release2.golden", - "lala": "./nope", + ExtraFilesGlobs: []string{ + "./testdata/release2.golden", + "./nope", }, }, } var ctx = context.New(config) ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"} client := &DummyClient{} - assert.EqualError(t, doPublish(ctx, client), "failed to upload lala: stat ./nope: no such file or directory") + assert.EqualError(t, doPublish(ctx, client), "globbing failed for pattern ./nope: file does not exist") assert.True(t, client.CreatedRelease) assert.False(t, client.UploadedFile) } +func TestRunPipeExtraOverride(t *testing.T) { + var config = config.Project{ + Release: config.Release{ + GitHub: config.Repo{ + Owner: "test", + Name: "test", + }, + ExtraFilesGlobs: []string{ + "./testdata/**/*", + "./testdata/upload_same_name/f1", + }, + }, + } + var ctx = context.New(config) + ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"} + client := &DummyClient{} + assert.NoError(t, doPublish(ctx, client)) + assert.True(t, client.CreatedRelease) + assert.True(t, client.UploadedFile) + assert.Contains(t, client.UploadedFileNames, "f1") + assert.True(t, strings.HasSuffix(client.UploadedFilePaths["f1"], "testdata/upload_same_name/f1")) +} + func TestRunPipeUploadRetry(t *testing.T) { folder, err := ioutil.TempDir("", "goreleasertest") assert.NoError(t, err) @@ -495,6 +521,7 @@ type DummyClient struct { CreatedRelease bool UploadedFile bool UploadedFileNames []string + UploadedFilePaths map[string]string FailFirstUpload bool Lock sync.Mutex } @@ -514,6 +541,9 @@ func (client *DummyClient) CreateFile(ctx *context.Context, commitAuthor config. func (client *DummyClient) Upload(ctx *context.Context, releaseID string, artifact *artifact.Artifact, file *os.File) error { client.Lock.Lock() defer client.Lock.Unlock() + if client.UploadedFilePaths == nil { + client.UploadedFilePaths = map[string]string{} + } // ensure file is read to better mimic real behavior _, err := ioutil.ReadAll(file) if err != nil { @@ -528,5 +558,6 @@ func (client *DummyClient) Upload(ctx *context.Context, releaseID string, artifa } client.UploadedFile = true client.UploadedFileNames = append(client.UploadedFileNames, artifact.Name) + client.UploadedFilePaths[artifact.Name] = artifact.Path return nil } diff --git a/internal/pipe/release/testdata/upload_same_name/f1 b/internal/pipe/release/testdata/upload_same_name/f1 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/internal/pipe/release/testdata/upload_same_name/f2/f1 b/internal/pipe/release/testdata/upload_same_name/f2/f1 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/pkg/config/config.go b/pkg/config/config.go index 63d55734e85..fb69c39a775 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -178,15 +178,15 @@ type Archive struct { // Release config used for the GitHub/GitLab release type Release struct { - GitHub Repo `yaml:",omitempty"` - GitLab Repo `yaml:",omitempty"` - Gitea Repo `yaml:",omitempty"` - Draft bool `yaml:",omitempty"` - Disable bool `yaml:",omitempty"` - Prerelease string `yaml:",omitempty"` - NameTemplate string `yaml:"name_template,omitempty"` - IDs []string `yaml:"ids,omitempty"` - ExtraFiles map[string]string `yaml:"extra_files,omitempty"` + GitHub Repo `yaml:",omitempty"` + GitLab Repo `yaml:",omitempty"` + Gitea Repo `yaml:",omitempty"` + Draft bool `yaml:",omitempty"` + Disable bool `yaml:",omitempty"` + Prerelease string `yaml:",omitempty"` + NameTemplate string `yaml:"name_template,omitempty"` + IDs []string `yaml:"ids,omitempty"` + ExtraFilesGlobs []string `yaml:"extra_files_globs,omitempty"` } // NFPM config diff --git a/www/content/release.md b/www/content/release.md index ec248e90b9c..76e99941feb 100644 --- a/www/content/release.md +++ b/www/content/release.md @@ -47,11 +47,13 @@ release: disable: true # You can add extra pre-existing files to the release. - # The left side is the name you want on the github release and the right - # side is the path to the file. + # The filename on the release will be the last part of the path (base). If + # another file with the same name exists, the latest one found will be used. # Defaults to empty. - extra_files: - name_on_github: ./path/to/file.txt + extra_files_globs: + - ./path/to/file.txt + - ./glob/**/to/**/file/**/* + - ./glob/foo/to/bar/file/foobar/override_from_previous ``` Second, let's see what can be customized in the `release` section for GitLab. @@ -82,11 +84,13 @@ release: disable: true # You can add extra pre-existing files to the release. - # The left side is the name you want on the gitlab release and the right - # side is the path to the file. + # The filename on the release will be the last part of the path (base). If + # another file with the same name exists, the latest one found will be used. # Defaults to empty. - extra_files: - name_on_gitlab: ./path/to/file.txt + extra_files_globs: + - ./path/to/file.txt + - ./glob/**/to/**/file/**/* + - ./glob/foo/to/bar/file/foobar/override_from_previous ``` You can also configure the `release` section to upload to a [Gitea](https://gitea.io) instance: @@ -115,11 +119,13 @@ release: disable: true # You can add extra pre-existing files to the release. - # The left side is the name you want on the gitea release and the right - # side is the path to the file. + # The filename on the release will be the last part of the path (base). If + # another file with the same name exists, the latest one found will be used. # Defaults to empty. - extra_files: - name_on_gitea: ./path/to/file.txt + extra_files_globs: + - ./path/to/file.txt + - ./glob/**/to/**/file/**/* + - ./glob/foo/to/bar/file/foobar/override_from_previous ``` To enable uploading `tar.gz` and `checksums.txt` files you need to add the following to your Gitea config in `app.ini`: From 60d256f0678d5db472a52363d7214fe0d6a25cc0 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Tue, 11 Feb 2020 10:11:12 -0300 Subject: [PATCH 5/6] fix: globs Signed-off-by: Carlos Alexandro Becker --- internal/pipe/release/release.go | 29 ++++++++++-------- internal/pipe/release/release_test.go | 16 +++++----- pkg/config/config.go | 23 ++++++++------ www/content/release.md | 44 +++++++++++++-------------- 4 files changed, 60 insertions(+), 52 deletions(-) diff --git a/internal/pipe/release/release.go b/internal/pipe/release/release.go index 3a4c9399731..d8783dc0f8a 100644 --- a/internal/pipe/release/release.go +++ b/internal/pipe/release/release.go @@ -1,7 +1,6 @@ package release import ( - "fmt" "os" "path/filepath" "time" @@ -197,20 +196,24 @@ func upload(ctx *context.Context, client client.Client, releaseID string, artifa func findFiles(ctx *context.Context) (map[string]string, error) { var result = map[string]string{} - for _, glob := range ctx.Config.Release.ExtraFilesGlobs { - files, err := zglob.Glob(glob) - if err != nil { - return result, fmt.Errorf("globbing failed for pattern %s: %s", glob, err.Error()) - } - for _, file := range files { - if info, _ := os.Stat(file); info.IsDir() { - continue + for _, extra := range ctx.Config.Release.ExtraFiles { + if extra.Glob != "" { + files, err := zglob.Glob(extra.Glob) + if err != nil { + return result, errors.Wrapf(err, "globbing failed for pattern %s", extra.Glob) } - var name = filepath.Base(file) - if old, ok := result[name]; ok { - log.Warnf("overriding %s with %s for name %s", old, file, name) + for _, file := range files { + info, err := os.Stat(file) + if err == nil && info.IsDir() { + log.Debugf("ignoring directory %s", file) + continue + } + var name = filepath.Base(file) + if old, ok := result[name]; ok { + log.Warnf("overriding %s with %s for name %s", old, file, name) + } + result[name] = file } - result[name] = file } } return result, nil diff --git a/internal/pipe/release/release_test.go b/internal/pipe/release/release_test.go index fccc7987cbb..1334c66c745 100644 --- a/internal/pipe/release/release_test.go +++ b/internal/pipe/release/release_test.go @@ -105,8 +105,8 @@ func TestRunPipeWithIDsThenFilters(t *testing.T) { Name: "test", }, IDs: []string{"foo"}, - ExtraFilesGlobs: []string{ - "./testdata/**/*", + ExtraFiles: []config.ExtraFile{ + {Glob: "./testdata/**/*"}, }, }, } @@ -233,9 +233,9 @@ func TestRunPipeExtraFileNotFound(t *testing.T) { Owner: "test", Name: "test", }, - ExtraFilesGlobs: []string{ - "./testdata/release2.golden", - "./nope", + ExtraFiles: []config.ExtraFile{ + {Glob: "./testdata/release2.golden"}, + {Glob: "./nope"}, }, }, } @@ -254,9 +254,9 @@ func TestRunPipeExtraOverride(t *testing.T) { Owner: "test", Name: "test", }, - ExtraFilesGlobs: []string{ - "./testdata/**/*", - "./testdata/upload_same_name/f1", + ExtraFiles: []config.ExtraFile{ + {Glob: "./testdata/**/*"}, + {Glob: "./testdata/upload_same_name/f1"}, }, }, } diff --git a/pkg/config/config.go b/pkg/config/config.go index fb69c39a775..7e6ae8ada21 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -178,15 +178,20 @@ type Archive struct { // Release config used for the GitHub/GitLab release type Release struct { - GitHub Repo `yaml:",omitempty"` - GitLab Repo `yaml:",omitempty"` - Gitea Repo `yaml:",omitempty"` - Draft bool `yaml:",omitempty"` - Disable bool `yaml:",omitempty"` - Prerelease string `yaml:",omitempty"` - NameTemplate string `yaml:"name_template,omitempty"` - IDs []string `yaml:"ids,omitempty"` - ExtraFilesGlobs []string `yaml:"extra_files_globs,omitempty"` + GitHub Repo `yaml:",omitempty"` + GitLab Repo `yaml:",omitempty"` + Gitea Repo `yaml:",omitempty"` + Draft bool `yaml:",omitempty"` + Disable bool `yaml:",omitempty"` + Prerelease string `yaml:",omitempty"` + NameTemplate string `yaml:"name_template,omitempty"` + IDs []string `yaml:"ids,omitempty"` + ExtraFiles []ExtraFile `yaml:"extra_files,omitempty"` +} + +// ExtraFile on a release +type ExtraFile struct { + Glob string `yaml:"glob,omitempty"` } // NFPM config diff --git a/www/content/release.md b/www/content/release.md index 76e99941feb..7a5fd03def9 100644 --- a/www/content/release.md +++ b/www/content/release.md @@ -6,7 +6,7 @@ weight: 110 --- GoReleaser will create a GitHub/GitLab release with the current tag, upload all -the artifacts and generate the changelog based on the new commits since the +the artifacts and generate the change log based on the new commits since the previous tag. Let's see what can be customized in the `release` section for GitHub: @@ -50,10 +50,10 @@ release: # The filename on the release will be the last part of the path (base). If # another file with the same name exists, the latest one found will be used. # Defaults to empty. - extra_files_globs: - - ./path/to/file.txt - - ./glob/**/to/**/file/**/* - - ./glob/foo/to/bar/file/foobar/override_from_previous + extra_files: + - glob: ./path/to/file.txt + - glob: ./glob/**/to/**/file/**/* + - glob: ./glob/foo/to/bar/file/foobar/override_from_previous ``` Second, let's see what can be customized in the `release` section for GitLab. @@ -87,10 +87,10 @@ release: # The filename on the release will be the last part of the path (base). If # another file with the same name exists, the latest one found will be used. # Defaults to empty. - extra_files_globs: - - ./path/to/file.txt - - ./glob/**/to/**/file/**/* - - ./glob/foo/to/bar/file/foobar/override_from_previous + extra_files: + - glob: ./path/to/file.txt + - glob: ./glob/**/to/**/file/**/* + - glob: ./glob/foo/to/bar/file/foobar/override_from_previous ``` You can also configure the `release` section to upload to a [Gitea](https://gitea.io) instance: @@ -122,10 +122,10 @@ release: # The filename on the release will be the last part of the path (base). If # another file with the same name exists, the latest one found will be used. # Defaults to empty. - extra_files_globs: - - ./path/to/file.txt - - ./glob/**/to/**/file/**/* - - ./glob/foo/to/bar/file/foobar/override_from_previous + extra_files: + - glob: ./path/to/file.txt + - glob: ./glob/**/to/**/file/**/* + - glob: ./glob/foo/to/bar/file/foobar/override_from_previous ``` To enable uploading `tar.gz` and `checksums.txt` files you need to add the following to your Gitea config in `app.ini`: @@ -141,22 +141,22 @@ so you will have to enable all file types with `*/*`. > Learn more about the [name template engine](/templates). -## Customize the changelog +## Customize the change log -You can customize how the changelog is generated using the -`changelog` section in the config file: +You can customize how the change log is generated using the +`change log` section in the config file: ```yaml # .goreleaser.yml -changelog: - # set it to true if you wish to skip the changelog generation +change log: + # set it to true if you wish to skip the change log generation skip: true # could either be asc, desc or empty # Default is empty sort: asc filters: # commit messages matching the regexp listed here will be removed from - # the changelog + # the change log # Default is empty exclude: - '^docs:' @@ -166,7 +166,7 @@ changelog: ### Define Previous Tag -GoReleaser uses `git describe` to get the previous tag used for generating the Changelog. +GoReleaser uses `git describe` to get the previous tag used for generating the Change log. You can set a different build tag using the environment variable `GORELEASER_PREVIOUS_TAG`. This is useful in scenarios where two tags point to the same commit. @@ -184,10 +184,10 @@ To list all commits since the last tag, but skip ones starting with `Merge` or `docs`, you could run this command: ```sh -$ goreleaser --release-notes <(some_changelog_generator) +$ goreleaser --release-notes <(some_change log_generator) ``` -Some changelog generators you can use: +Some change log generators you can use: - [buchanae/github-release-notes](https://github.com/buchanae/github-release-notes) From 173191eb4ae44abdb02bb17b655e62cff0d14592 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Tue, 11 Feb 2020 10:12:31 -0300 Subject: [PATCH 6/6] fix: typo Signed-off-by: Carlos Alexandro Becker --- www/content/release.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/www/content/release.md b/www/content/release.md index 7a5fd03def9..3552a7540c7 100644 --- a/www/content/release.md +++ b/www/content/release.md @@ -6,7 +6,7 @@ weight: 110 --- GoReleaser will create a GitHub/GitLab release with the current tag, upload all -the artifacts and generate the change log based on the new commits since the +the artifacts and generate the changelog based on the new commits since the previous tag. Let's see what can be customized in the `release` section for GitHub: @@ -141,22 +141,22 @@ so you will have to enable all file types with `*/*`. > Learn more about the [name template engine](/templates). -## Customize the change log +## Customize the changelog -You can customize how the change log is generated using the -`change log` section in the config file: +You can customize how the changelog is generated using the +`changelog` section in the config file: ```yaml # .goreleaser.yml -change log: - # set it to true if you wish to skip the change log generation +changelog: + # set it to true if you wish to skip the changelog generation skip: true # could either be asc, desc or empty # Default is empty sort: asc filters: # commit messages matching the regexp listed here will be removed from - # the change log + # the changelog # Default is empty exclude: - '^docs:' @@ -166,7 +166,7 @@ change log: ### Define Previous Tag -GoReleaser uses `git describe` to get the previous tag used for generating the Change log. +GoReleaser uses `git describe` to get the previous tag used for generating the Changelog. You can set a different build tag using the environment variable `GORELEASER_PREVIOUS_TAG`. This is useful in scenarios where two tags point to the same commit. @@ -184,10 +184,10 @@ To list all commits since the last tag, but skip ones starting with `Merge` or `docs`, you could run this command: ```sh -$ goreleaser --release-notes <(some_change log_generator) +$ goreleaser --release-notes <(some_changelog_generator) ``` -Some change log generators you can use: +Some changelog generators you can use: - [buchanae/github-release-notes](https://github.com/buchanae/github-release-notes)