Skip to content
Permalink
Browse files

feat: improve selection of artifacts to upload

  • Loading branch information...
lalloni authored and caarlos0 committed Jun 25, 2018
1 parent 0836c5a commit e1e1a9bf9c0521527372eccbb47f54d415e622e1
Showing with 24 additions and 19 deletions.
  1. +6 −4 config/config.go
  2. +18 −15 internal/http/http.go
@@ -284,10 +284,12 @@ type S3 struct {

// Put HTTP upload configuration
type Put struct {
Name string `yaml:",omitempty"`
Target string `yaml:",omitempty"`
Username string `yaml:",omitempty"`
Mode string `yaml:",omitempty"`
Name string `yaml:",omitempty"`
Target string `yaml:",omitempty"`
Username string `yaml:",omitempty"`
Mode string `yaml:",omitempty"`
Checksum bool `yaml:",omitempty"`
Signature bool `yaml:",omitempty"`
}

// Project includes all project configuration
@@ -76,37 +76,40 @@ func misconfigured(kind string, upload *config.Put, reason string) error {
type ResponseChecker func(*h.Response) (string, error)

// Upload does the actual uploading work
func Upload(ctx *context.Context, uploads []config.Put, kind string, check ResponseChecker) error {
func Upload(ctx *context.Context, puts []config.Put, kind string, check ResponseChecker) error {
if ctx.SkipPublish {
return pipeline.ErrSkipPublishEnabled
}

// Handle every configured artifactory instance
for _, instance := range uploads {
// Handle every configured put
for _, put := range puts {
filters := []artifact.Filter{}
if put.Checksum {
filters = append(filters, artifact.ByType(artifact.Checksum))
}
if put.Signature {
filters = append(filters, artifact.ByType(artifact.Signature))
}
// We support two different modes
// - "archive": Upload all artifacts
// - "binary": Upload only the raw binaries
var filter artifact.Filter
switch v := strings.ToLower(instance.Mode); v {
switch v := strings.ToLower(put.Mode); v {
case ModeArchive:
filter = artifact.Or(
filters = append(filters,
artifact.ByType(artifact.UploadableArchive),
artifact.ByType(artifact.LinuxPackage),
artifact.ByType(artifact.Checksum),
artifact.ByType(artifact.Signature),
)
artifact.ByType(artifact.LinuxPackage))
case ModeBinary:
filter = artifact.ByType(artifact.UploadableBinary)
filters = append(filters,
artifact.ByType(artifact.UploadableBinary))
default:
err := fmt.Errorf("%s: mode \"%s\" not supported", kind, v)
log.WithFields(log.Fields{
"instance": instance.Name,
"mode": v,
kind: put.Name,
"mode": v,
}).Error(err.Error())
return err
}

if err := runPipeByFilter(ctx, instance, filter, kind, check); err != nil {
if err := runPipeByFilter(ctx, put, artifact.Or(filters...), kind, check); err != nil {
return err
}
}

0 comments on commit e1e1a9b

Please sign in to comment.
You can’t perform that action at this time.