github.com/joselitofilho/goreleaser@v0.155.1-0.20210123221854-e4891856c593/internal/pipe/upload/upload.go (about)

     1  // Package upload provides a Pipe that push using HTTP.
     2  package upload
     3  
     4  import (
     5  	"fmt"
     6  	h "net/http"
     7  
     8  	"github.com/goreleaser/goreleaser/internal/http"
     9  	"github.com/goreleaser/goreleaser/internal/pipe"
    10  	"github.com/goreleaser/goreleaser/pkg/context"
    11  )
    12  
    13  // Pipe for http publishing.
    14  type Pipe struct{}
    15  
    16  // String returns the description of the pipe.
    17  func (Pipe) String() string {
    18  	return "http upload"
    19  }
    20  
    21  // Default sets the pipe defaults.
    22  func (Pipe) Default(ctx *context.Context) error {
    23  	return http.Defaults(ctx.Config.Uploads)
    24  }
    25  
    26  // Publish artifacts.
    27  func (Pipe) Publish(ctx *context.Context) error {
    28  	if len(ctx.Config.Uploads) == 0 {
    29  		return pipe.Skip("uploads section is not configured")
    30  	}
    31  
    32  	// Check requirements for every instance we have configured.
    33  	// If not fulfilled, we can skip this pipeline
    34  	for _, instance := range ctx.Config.Uploads {
    35  		instance := instance
    36  		if skip := http.CheckConfig(ctx, &instance, "upload"); skip != nil {
    37  			return pipe.Skip(skip.Error())
    38  		}
    39  	}
    40  
    41  	return http.Upload(ctx, ctx.Config.Uploads, "upload", func(res *h.Response) error {
    42  		if c := res.StatusCode; c < 200 || 299 < c {
    43  			return fmt.Errorf("unexpected http response status: %s", res.Status)
    44  		}
    45  		return nil
    46  	})
    47  }