CI: fix release script remove filtering (#20552)
This commit is contained in:
@@ -45,9 +45,9 @@ func main() {
|
|||||||
product = "grafana-enterprise"
|
product = "grafana-enterprise"
|
||||||
baseURL = createBaseURL(archiveProviderRoot, "enterprise", product, nightly)
|
baseURL = createBaseURL(archiveProviderRoot, "enterprise", product, nightly)
|
||||||
var err error
|
var err error
|
||||||
buildArtifacts, err = filterBuildArtifacts([]artifactFilter{
|
buildArtifacts, err = filterBuildArtifacts(completeBuildArtifactConfigurations, Remove, []artifactFilter{
|
||||||
{os: "win-installer", arch: "amd64"},
|
{os: "win-installer", arch: "amd64"},
|
||||||
}, Remove)
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not filter to the selected build artifacts, err=%v", err)
|
log.Fatalf("Could not filter to the selected build artifacts, err=%v", err)
|
||||||
|
|||||||
@@ -193,10 +193,10 @@ const (
|
|||||||
Remove filterType = "remove"
|
Remove filterType = "remove"
|
||||||
)
|
)
|
||||||
|
|
||||||
func filterBuildArtifacts(filters []artifactFilter, ft filterType) ([]buildArtifact, error) {
|
func filterBuildArtifacts(filterFrom []buildArtifact, ft filterType, filters []artifactFilter) ([]buildArtifact, error) {
|
||||||
var artifacts []buildArtifact
|
var artifacts []buildArtifact
|
||||||
|
|
||||||
for _, a := range completeBuildArtifactConfigurations {
|
for _, a := range filterFrom {
|
||||||
matched := false
|
matched := false
|
||||||
var match buildArtifact
|
var match buildArtifact
|
||||||
|
|
||||||
@@ -211,7 +211,7 @@ func filterBuildArtifacts(filters []artifactFilter, ft filterType) ([]buildArtif
|
|||||||
if matched && ft == Add {
|
if matched && ft == Add {
|
||||||
artifacts = append(artifacts, match)
|
artifacts = append(artifacts, match)
|
||||||
} else if !matched && ft == Remove {
|
} else if !matched && ft == Remove {
|
||||||
artifacts = append(artifacts, match)
|
artifacts = append(artifacts, a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return artifacts, nil
|
return artifacts, nil
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func TestPreparingReleaseFromRemote(t *testing.T) {
|
func TestPreparingReleaseFromRemote(t *testing.T) {
|
||||||
|
|
||||||
@@ -148,33 +151,60 @@ func (mockHTTPGetter) getContents(url string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterBuildArtifacts(t *testing.T) {
|
func TestFilterBuildArtifacts(t *testing.T) {
|
||||||
buildArtifacts, _ := filterBuildArtifacts([]artifactFilter{
|
buildArtifacts, _ := filterBuildArtifacts(completeBuildArtifactConfigurations, Add, []artifactFilter{
|
||||||
{os: "deb", arch: "amd64"},
|
{os: "deb", arch: "amd64"},
|
||||||
{os: "rhel", arch: "amd64"},
|
{os: "rhel", arch: "amd64"},
|
||||||
{os: "linux", arch: "amd64"},
|
{os: "linux", arch: "amd64"},
|
||||||
{os: "win", arch: "amd64"},
|
{os: "win", arch: "amd64"},
|
||||||
}, Add)
|
})
|
||||||
|
|
||||||
if len(buildArtifacts) != 4 {
|
if len(buildArtifacts) != 4 {
|
||||||
t.Errorf("Expected 4 build artifacts after filtering, but was %v", len(buildArtifacts))
|
t.Errorf("Expected 4 build artifacts after filtering, but was %v", len(buildArtifacts))
|
||||||
}
|
}
|
||||||
|
|
||||||
buildArtifacts, err := filterBuildArtifacts([]artifactFilter{
|
buildArtifacts, err := filterBuildArtifacts([]buildArtifact{
|
||||||
{os: "win-installer", arch: "amd64"},
|
{
|
||||||
}, Remove)
|
os: "linux",
|
||||||
|
arch: "amd64",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
os: "arm",
|
||||||
|
arch: "amd64",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
os: "darwin",
|
||||||
|
arch: "amd64",
|
||||||
|
},
|
||||||
|
}, Remove, []artifactFilter{
|
||||||
|
{os: "darwin", arch: "amd64"},
|
||||||
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Expected all artifacts except win-msi, not error=%v", err)
|
t.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(buildArtifacts) != len(completeBuildArtifactConfigurations)-1 {
|
if len(buildArtifacts) != 2 {
|
||||||
t.Errorf("Expected %v artifacts but was %v", completeBuildArtifactConfigurations, buildArtifacts)
|
t.Errorf("Expected 2 artifacts, was %v", len(buildArtifacts))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ba := range buildArtifacts {
|
for _, ba := range buildArtifacts {
|
||||||
if ba.arch == "amd64" && ba.os == "win-installer" {
|
if ba.arch == "amd64" && ba.os == "darwin" {
|
||||||
t.Errorf("win-installer/amd64 should be gone due to filtering")
|
t.Errorf("darwin/amd64 should be gone due to filtering")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
left := []buildArtifact{
|
||||||
|
{
|
||||||
|
os: "linux",
|
||||||
|
arch: "amd64",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
os: "arm",
|
||||||
|
arch: "amd64",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(left, buildArtifacts) {
|
||||||
|
t.Errorf("Lists should have been equal but was, expected=%v, actual=%v", left, buildArtifacts)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user