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:
parent
8e1b6a1bbb
commit
791de897bb
@ -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)
|
||||
|
@ -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
1
internal/exec/testdata/a.txt
vendored
Normal file
@ -0,0 +1 @@
|
||||
lorem ipsum
|
@ -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.
|
||||
|
@ -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
6
www/docs/static/schema-pro.json
generated
vendored
@ -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
6
www/docs/static/schema.json
generated
vendored
@ -1652,6 +1652,12 @@
|
||||
"type": "string"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"extra_files": {
|
||||
"items": {
|
||||
"$ref": "#/definitions/ExtraFile"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
|
Loading…
Reference in New Issue
Block a user