mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-05 13:15:26 +02:00
feat: filter PUT by ID (#1016)
This commit is contained in:
parent
4180aa3f6a
commit
d9e89f69c7
@ -153,7 +153,12 @@ func Upload(ctx *context.Context, puts []config.Put, kind string, check Response
|
||||
}).Error(err.Error())
|
||||
return err
|
||||
}
|
||||
if err := uploadWithFilter(ctx, &put, artifact.Or(filters...), kind, check); err != nil {
|
||||
|
||||
var filter = artifact.Or(filters...)
|
||||
if len(put.IDs) > 0 {
|
||||
filter = artifact.And(filter, artifact.ByIDs(put.IDs...))
|
||||
}
|
||||
if err := uploadWithFilter(ctx, &put, filter, kind, check); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -327,6 +332,7 @@ type targetData struct {
|
||||
|
||||
// resolveTargetTemplate returns the resolved target template with replaced variables
|
||||
// Those variables can be replaced by the given context, goos, goarch, goarm and more
|
||||
// TODO: replace this with our internal template pkg
|
||||
func resolveTargetTemplate(ctx *context.Context, put *config.Put, artifact artifact.Artifact) (string, error) {
|
||||
data := targetData{
|
||||
Version: ctx.Version,
|
||||
|
@ -122,7 +122,7 @@ type check struct {
|
||||
func checks(checks ...check) func(rs []*h.Request) error {
|
||||
return func(rs []*h.Request) error {
|
||||
if len(rs) != len(checks) {
|
||||
return errors.New("expectations mismatch requests")
|
||||
return fmt.Errorf("expected %d requests, got %d", len(checks), len(rs))
|
||||
}
|
||||
for _, r := range rs {
|
||||
found := false
|
||||
@ -226,7 +226,14 @@ func TestUpload(t *testing.T) {
|
||||
} {
|
||||
var file = filepath.Join(folder, "a."+a.ext)
|
||||
require.NoError(t, ioutil.WriteFile(file, []byte("lorem ipsum"), 0644))
|
||||
ctx.Artifacts.Add(artifact.Artifact{Name: "a." + a.ext, Path: file, Type: a.typ})
|
||||
ctx.Artifacts.Add(artifact.Artifact{
|
||||
Name: "a." + a.ext,
|
||||
Path: file,
|
||||
Type: a.typ,
|
||||
Extra: map[string]interface{}{
|
||||
"ID": "foo",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
@ -279,6 +286,22 @@ func TestUpload(t *testing.T) {
|
||||
check{"/blah/2.1.0/a.tar", "u1", "x", content, map[string]string{}},
|
||||
),
|
||||
},
|
||||
{"archive_with_ids", true, true, false, false,
|
||||
func(s *httptest.Server) (*context.Context, config.Put) {
|
||||
return ctx, config.Put{
|
||||
Mode: ModeArchive,
|
||||
Name: "a",
|
||||
Target: s.URL + "/{{.ProjectName}}/{{.Version}}/",
|
||||
Username: "u1",
|
||||
TrustedCerts: cert(s),
|
||||
IDs: []string{"foo"},
|
||||
}
|
||||
},
|
||||
checks(
|
||||
check{"/blah/2.1.0/a.deb", "u1", "x", content, map[string]string{}},
|
||||
check{"/blah/2.1.0/a.tar", "u1", "x", content, map[string]string{}},
|
||||
),
|
||||
},
|
||||
{"binary", true, true, false, false,
|
||||
func(s *httptest.Server) (*context.Context, config.Put) {
|
||||
return ctx, config.Put{
|
||||
@ -291,6 +314,19 @@ func TestUpload(t *testing.T) {
|
||||
},
|
||||
checks(check{"/blah/2.1.0/a.ubi", "u2", "x", content, map[string]string{}}),
|
||||
},
|
||||
{"binary_with_ids", true, true, false, false,
|
||||
func(s *httptest.Server) (*context.Context, config.Put) {
|
||||
return ctx, config.Put{
|
||||
Mode: ModeBinary,
|
||||
Name: "a",
|
||||
Target: s.URL + "/{{.ProjectName}}/{{.Version}}/",
|
||||
Username: "u2",
|
||||
TrustedCerts: cert(s),
|
||||
IDs: []string{"foo"},
|
||||
}
|
||||
},
|
||||
checks(check{"/blah/2.1.0/a.ubi", "u2", "x", content, map[string]string{}}),
|
||||
},
|
||||
{"binary-add-ending-bar", true, true, false, false,
|
||||
func(s *httptest.Server) (*context.Context, config.Put) {
|
||||
return ctx, config.Put{
|
||||
@ -387,7 +423,7 @@ func TestUpload(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
uploadAndCheck := func(setup func(*httptest.Server) (*context.Context, config.Put), wantErrPlain, wantErrTLS bool, check func(r []*h.Request) error, srv *httptest.Server) {
|
||||
uploadAndCheck := func(t *testing.T, setup func(*httptest.Server) (*context.Context, config.Put), wantErrPlain, wantErrTLS bool, check func(r []*h.Request) error, srv *httptest.Server) {
|
||||
requests = nil
|
||||
ctx, put := setup(srv)
|
||||
wantErr := wantErrPlain
|
||||
@ -407,7 +443,7 @@ func TestUpload(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
srv := httptest.NewServer(mux)
|
||||
defer srv.Close()
|
||||
uploadAndCheck(tt.setup, tt.wantErrPlain, tt.wantErrTLS, tt.check, srv)
|
||||
uploadAndCheck(t, tt.setup, tt.wantErrPlain, tt.wantErrTLS, tt.check, srv)
|
||||
})
|
||||
}
|
||||
if tt.tryTLS {
|
||||
@ -415,7 +451,7 @@ func TestUpload(t *testing.T) {
|
||||
srv := httptest.NewUnstartedServer(mux)
|
||||
srv.StartTLS()
|
||||
defer srv.Close()
|
||||
uploadAndCheck(tt.setup, tt.wantErrPlain, tt.wantErrTLS, tt.check, srv)
|
||||
uploadAndCheck(t, tt.setup, tt.wantErrPlain, tt.wantErrTLS, tt.check, srv)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -123,24 +123,36 @@ puts:
|
||||
-
|
||||
# Unique name of your Put instance. Used to identify the instance.
|
||||
name: production
|
||||
|
||||
# IDs of the artifacts you want to PUT.
|
||||
ids:
|
||||
- foo
|
||||
- bar
|
||||
|
||||
# Upload mode. Valid options are `binary` and `archive`.
|
||||
# If mode is `archive`, variables _Os_, _Arch_ and _Arm_ for target name are not supported.
|
||||
# In that case these variables are empty.
|
||||
# Default is `archive`.
|
||||
mode: archive
|
||||
|
||||
# URL to be used as target of the HTTP PUT request
|
||||
target: https://some.server/some/path/example-repo-local/{{ .ProjectName }}/{{ .Version }}/
|
||||
|
||||
# User that will be used for the deployment
|
||||
username: deployuser
|
||||
|
||||
# An optional header you can use to tell GoReleaser to pass the artifact's
|
||||
# SHA256 checksum withing the upload request.
|
||||
# Default is empty.
|
||||
checksum_header: -X-SHA256-Sum
|
||||
|
||||
# Upload checksums (defaults to false)
|
||||
checksum: true
|
||||
|
||||
# Upload signatures (defaults to false)
|
||||
signature: true
|
||||
# Certificate chain used to validate server certificates
|
||||
|
||||
# Certificate chain used to validate server certificates
|
||||
trusted_certificates: |
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDrjCCApagAwIBAgIIShr2zchZo+8wDQYJKoZIhvcNAQENBQAwNTEXMBUGA1UE
|
||||
|
Loading…
x
Reference in New Issue
Block a user