1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-16 03:52:12 +02:00

feat: support extra_files in publishers (#2770)

Reference: https://github.com/goreleaser/goreleaser/issues/2768

Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Brian Flad 2022-01-06 20:04:43 -05:00 committed by GitHub
parent 8e1b6a1bbb
commit 791de897bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 102 additions and 7 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/apex/log"
"github.com/caarlos0/go-shellwords"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/extrafiles"
"github.com/goreleaser/goreleaser/internal/gio"
"github.com/goreleaser/goreleaser/internal/logext"
"github.com/goreleaser/goreleaser/internal/pipe"
@ -43,6 +44,20 @@ func Execute(ctx *context.Context, publishers []config.Publisher) error {
func executePublisher(ctx *context.Context, publisher config.Publisher) error {
log.Debugf("filtering %d artifacts", len(ctx.Artifacts.List()))
artifacts := filterArtifacts(ctx.Artifacts, publisher)
extraFiles, err := extrafiles.Find(ctx, publisher.ExtraFiles)
if err != nil {
return err
}
for name, path := range extraFiles {
artifacts = append(artifacts, &artifact.Artifact{
Name: name,
Path: path,
Type: artifact.UploadableFile,
})
}
log.Debugf("will execute custom publisher with %d artifacts", len(artifacts))
g := semerrgroup.New(ctx.Parallelism)

View File

@ -202,6 +202,59 @@ func TestExecute(t *testing.T) {
},
nil,
},
{
"extra files",
[]config.Publisher{
{
Name: "test",
Cmd: MockCmd + " {{ .ArtifactName }}",
Env: []string{
MarshalMockEnv(&MockData{
AnyOf: []MockCall{
{ExpectedArgs: []string{"a.deb"}, ExitCode: 0, ExpectedEnv: osEnv()},
{ExpectedArgs: []string{"a.ubi"}, ExitCode: 0, ExpectedEnv: osEnv()},
{ExpectedArgs: []string{"a.tar"}, ExitCode: 0, ExpectedEnv: osEnv()},
{ExpectedArgs: []string{"a.txt"}, ExitCode: 0, ExpectedEnv: osEnv()},
{ExpectedArgs: []string{"foo/bar"}, ExitCode: 0, ExpectedEnv: osEnv()},
{ExpectedArgs: []string{"foo/bar:amd64"}, ExitCode: 0, ExpectedEnv: osEnv()},
},
}),
},
ExtraFiles: []config.ExtraFile{
{Glob: filepath.Join("testdata", "*.txt")},
},
},
},
nil,
},
{
"extra files with rename",
[]config.Publisher{
{
Name: "test",
Cmd: MockCmd + " {{ .ArtifactName }}",
Env: []string{
MarshalMockEnv(&MockData{
AnyOf: []MockCall{
{ExpectedArgs: []string{"a.deb"}, ExitCode: 0, ExpectedEnv: osEnv()},
{ExpectedArgs: []string{"a.ubi"}, ExitCode: 0, ExpectedEnv: osEnv()},
{ExpectedArgs: []string{"a.tar"}, ExitCode: 0, ExpectedEnv: osEnv()},
{ExpectedArgs: []string{"b.txt"}, ExitCode: 0, ExpectedEnv: osEnv()},
{ExpectedArgs: []string{"foo/bar"}, ExitCode: 0, ExpectedEnv: osEnv()},
{ExpectedArgs: []string{"foo/bar:amd64"}, ExitCode: 0, ExpectedEnv: osEnv()},
},
}),
},
ExtraFiles: []config.ExtraFile{
{
Glob: filepath.Join("testdata", "*.txt"),
NameTemplate: "b.txt",
},
},
},
},
nil,
},
{
"try dir templating",
[]config.Publisher{

1
internal/exec/testdata/a.txt vendored Normal file
View File

@ -0,0 +1 @@
lorem ipsum

View File

@ -799,13 +799,14 @@ type Upload struct {
// Publisher configuration.
type Publisher struct {
Name string `yaml:"name,omitempty"`
IDs []string `yaml:"ids,omitempty"`
Checksum bool `yaml:"checksum,omitempty"`
Signature bool `yaml:"signature,omitempty"`
Dir string `yaml:"dir,omitempty"`
Cmd string `yaml:"cmd,omitempty"`
Env []string `yaml:"env,omitempty"`
Name string `yaml:"name,omitempty"`
IDs []string `yaml:"ids,omitempty"`
Checksum bool `yaml:"checksum,omitempty"`
Signature bool `yaml:"signature,omitempty"`
Dir string `yaml:"dir,omitempty"`
Cmd string `yaml:"cmd,omitempty"`
Env []string `yaml:"env,omitempty"`
ExtraFiles []ExtraFile `yaml:"extra_files,omitempty"`
}
// Source configuration.

View File

@ -114,6 +114,19 @@ publishers:
# Environment variables
env:
- API_TOKEN=secret-token
# You can publish extra pre-existing files.
# The filename published will be the last part of the path (base).
# If another file with the same name exists, the last one found will be used.
# These globs can also include templates.
#
# Defaults to empty.
extra_files:
- glob: ./path/to/file.txt
- glob: ./glob/**/to/**/file/**/*
- glob: ./glob/foo/to/bar/file/foobar/override_from_previous
- glob: ./single_file.txt
name_template: file.txt # note that this only works if glob matches 1 file only
```
These settings should allow you to push your artifacts to any number of endpoints

6
www/docs/static/schema-pro.json generated vendored
View File

@ -1814,6 +1814,12 @@
"type": "string"
},
"type": "array"
},
"extra_files": {
"items": {
"$ref": "#/definitions/ExtraFile"
},
"type": "array"
}
},
"additionalProperties": false,

6
www/docs/static/schema.json generated vendored
View File

@ -1652,6 +1652,12 @@
"type": "string"
},
"type": "array"
},
"extra_files": {
"items": {
"$ref": "#/definitions/ExtraFile"
},
"type": "array"
}
},
"additionalProperties": false,