mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-05 13:15:26 +02:00
feat(blob): allow to upload only extra_files (#4925)
Not happy with the option name tbh... happy to hear suggestions :) refs #4921 refs https://github.com/goreleaser/goreleaser/issues/4920 --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
8244d52f08
commit
3e663003b1
@ -28,9 +28,10 @@ func (Pipe) Default(ctx *context.Context) error {
|
|||||||
blob.Directory = "{{ .ProjectName }}/{{ .Tag }}"
|
blob.Directory = "{{ .ProjectName }}/{{ .Tag }}"
|
||||||
}
|
}
|
||||||
|
|
||||||
if blob.ContentDisposition == "" {
|
switch blob.ContentDisposition {
|
||||||
|
case "":
|
||||||
blob.ContentDisposition = "attachment;filename={{.Filename}}"
|
blob.ContentDisposition = "attachment;filename={{.Filename}}"
|
||||||
} else if blob.ContentDisposition == "-" {
|
case "-":
|
||||||
blob.ContentDisposition = ""
|
blob.ContentDisposition = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ func TestMinioUpload(t *testing.T) {
|
|||||||
require.NoError(t, Pipe{}.Default(ctx))
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
require.NoError(t, Pipe{}.Publish(ctx))
|
require.NoError(t, Pipe{}.Publish(ctx))
|
||||||
|
|
||||||
require.Subset(t, getFiles(t, ctx, ctx.Config.Blobs[0]), []string{
|
require.ElementsMatch(t, getFiles(t, ctx, ctx.Config.Blobs[0]), []string{
|
||||||
"testupload/v1.0.0/bin.deb",
|
"testupload/v1.0.0/bin.deb",
|
||||||
"testupload/v1.0.0/bin.tar.gz",
|
"testupload/v1.0.0/bin.tar.gz",
|
||||||
"testupload/v1.0.0/metadata.json",
|
"testupload/v1.0.0/metadata.json",
|
||||||
@ -211,6 +211,51 @@ func TestMinioUploadCustomBucketID(t *testing.T) {
|
|||||||
require.NoError(t, Pipe{}.Publish(ctx))
|
require.NoError(t, Pipe{}.Publish(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMinioUploadExtraFilesOnly(t *testing.T) {
|
||||||
|
name := "only-extra-files"
|
||||||
|
directory := t.TempDir()
|
||||||
|
tgzpath := filepath.Join(directory, "bin.tar.gz")
|
||||||
|
debpath := filepath.Join(directory, "bin.deb")
|
||||||
|
require.NoError(t, os.WriteFile(tgzpath, []byte("fake\ntargz"), 0o744))
|
||||||
|
require.NoError(t, os.WriteFile(debpath, []byte("fake\ndeb"), 0o744))
|
||||||
|
ctx := testctx.NewWithCfg(config.Project{
|
||||||
|
Dist: directory,
|
||||||
|
ProjectName: "testupload",
|
||||||
|
Blobs: []config.Blob{
|
||||||
|
{
|
||||||
|
Provider: "s3",
|
||||||
|
Bucket: name,
|
||||||
|
Endpoint: "http://" + listen,
|
||||||
|
IncludeMeta: true,
|
||||||
|
ExtraFilesOnly: true,
|
||||||
|
ExtraFiles: []config.ExtraFile{
|
||||||
|
{
|
||||||
|
Glob: "./testdata/*.golden",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, testctx.WithCurrentTag("v1.0.0"))
|
||||||
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
Name: "bin.tar.gz",
|
||||||
|
Path: tgzpath,
|
||||||
|
})
|
||||||
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
|
Type: artifact.LinuxPackage,
|
||||||
|
Name: "bin.deb",
|
||||||
|
Path: debpath,
|
||||||
|
})
|
||||||
|
|
||||||
|
setupBucket(t, testlib.MustDockerPool(t), name)
|
||||||
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
|
require.NoError(t, Pipe{}.Publish(ctx))
|
||||||
|
|
||||||
|
require.ElementsMatch(t, getFiles(t, ctx, ctx.Config.Blobs[0]), []string{
|
||||||
|
"testupload/v1.0.0/file.golden",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestMinioUploadRootDirectory(t *testing.T) {
|
func TestMinioUploadRootDirectory(t *testing.T) {
|
||||||
name := "rootdir"
|
name := "rootdir"
|
||||||
directory := t.TempDir()
|
directory := t.TempDir()
|
||||||
|
@ -96,25 +96,6 @@ func doUpload(ctx *context.Context, conf config.Blob) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
byTypes := []artifact.Filter{
|
|
||||||
artifact.ByType(artifact.UploadableArchive),
|
|
||||||
artifact.ByType(artifact.UploadableBinary),
|
|
||||||
artifact.ByType(artifact.UploadableSourceArchive),
|
|
||||||
artifact.ByType(artifact.Checksum),
|
|
||||||
artifact.ByType(artifact.Signature),
|
|
||||||
artifact.ByType(artifact.Certificate),
|
|
||||||
artifact.ByType(artifact.LinuxPackage),
|
|
||||||
artifact.ByType(artifact.SBOM),
|
|
||||||
}
|
|
||||||
if conf.IncludeMeta {
|
|
||||||
byTypes = append(byTypes, artifact.ByType(artifact.Metadata))
|
|
||||||
}
|
|
||||||
|
|
||||||
filter := artifact.Or(byTypes...)
|
|
||||||
if len(conf.IDs) > 0 {
|
|
||||||
filter = artifact.And(filter, artifact.ByIDs(conf.IDs...))
|
|
||||||
}
|
|
||||||
|
|
||||||
up := &productionUploader{
|
up := &productionUploader{
|
||||||
cacheControl: conf.CacheControl,
|
cacheControl: conf.CacheControl,
|
||||||
contentDisposition: conf.ContentDisposition,
|
contentDisposition: conf.ContentDisposition,
|
||||||
@ -136,7 +117,7 @@ func doUpload(ctx *context.Context, conf config.Blob) error {
|
|||||||
defer up.Close()
|
defer up.Close()
|
||||||
|
|
||||||
g := semerrgroup.New(ctx.Parallelism)
|
g := semerrgroup.New(ctx.Parallelism)
|
||||||
for _, artifact := range ctx.Artifacts.Filter(filter).List() {
|
for _, artifact := range artifactList(ctx, conf) {
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
// TODO: replace this with ?prefix=folder on the bucket url
|
// TODO: replace this with ?prefix=folder on the bucket url
|
||||||
dataFile := artifact.Path
|
dataFile := artifact.Path
|
||||||
@ -160,6 +141,31 @@ func doUpload(ctx *context.Context, conf config.Blob) error {
|
|||||||
return g.Wait()
|
return g.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func artifactList(ctx *context.Context, conf config.Blob) []*artifact.Artifact {
|
||||||
|
if conf.ExtraFilesOnly {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
byTypes := []artifact.Filter{
|
||||||
|
artifact.ByType(artifact.UploadableArchive),
|
||||||
|
artifact.ByType(artifact.UploadableBinary),
|
||||||
|
artifact.ByType(artifact.UploadableSourceArchive),
|
||||||
|
artifact.ByType(artifact.Checksum),
|
||||||
|
artifact.ByType(artifact.Signature),
|
||||||
|
artifact.ByType(artifact.Certificate),
|
||||||
|
artifact.ByType(artifact.LinuxPackage),
|
||||||
|
artifact.ByType(artifact.SBOM),
|
||||||
|
}
|
||||||
|
if conf.IncludeMeta {
|
||||||
|
byTypes = append(byTypes, artifact.ByType(artifact.Metadata))
|
||||||
|
}
|
||||||
|
|
||||||
|
filter := artifact.Or(byTypes...)
|
||||||
|
if len(conf.IDs) > 0 {
|
||||||
|
filter = artifact.And(filter, artifact.ByIDs(conf.IDs...))
|
||||||
|
}
|
||||||
|
return ctx.Artifacts.Filter(filter).List()
|
||||||
|
}
|
||||||
|
|
||||||
func uploadData(ctx *context.Context, conf config.Blob, up uploader, dataFile, uploadFile, bucketURL string) error {
|
func uploadData(ctx *context.Context, conf config.Blob, up uploader, dataFile, uploadFile, bucketURL string) error {
|
||||||
data, err := getData(ctx, conf, dataFile)
|
data, err := getData(ctx, conf, dataFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1129,6 +1129,7 @@ type Blob struct {
|
|||||||
CacheControl []string `yaml:"cache_control,omitempty" json:"cache_control,omitempty"`
|
CacheControl []string `yaml:"cache_control,omitempty" json:"cache_control,omitempty"`
|
||||||
ContentDisposition string `yaml:"content_disposition,omitempty" json:"content_disposition,omitempty"`
|
ContentDisposition string `yaml:"content_disposition,omitempty" json:"content_disposition,omitempty"`
|
||||||
IncludeMeta bool `yaml:"include_meta,omitempty" json:"include_meta,omitempty"`
|
IncludeMeta bool `yaml:"include_meta,omitempty" json:"include_meta,omitempty"`
|
||||||
|
ExtraFilesOnly bool `yaml:"extra_files_only,omitempty" json:"extra_files_only,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload configuration.
|
// Upload configuration.
|
||||||
|
@ -125,6 +125,17 @@ blobs:
|
|||||||
- provider: s3
|
- provider: s3
|
||||||
bucket: goreleaser-bucket
|
bucket: goreleaser-bucket
|
||||||
directory: "foo/bar/{{.Version}}"
|
directory: "foo/bar/{{.Version}}"
|
||||||
|
|
||||||
|
|
||||||
|
# Upload metadata.json and artifacts.json to the release as well.
|
||||||
|
#
|
||||||
|
# Since: v1.25
|
||||||
|
include_meta: true
|
||||||
|
|
||||||
|
# Upload only the files defined in extra_files.
|
||||||
|
#
|
||||||
|
# Since: v2.1
|
||||||
|
extra_files_only: true
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! tip
|
!!! tip
|
||||||
|
Loading…
x
Reference in New Issue
Block a user