Commit 65bacf2d by Leonard Gram Committed by GitHub

CI: fix release script remove filtering (#20552)

parent 22edacd4
......@@ -45,9 +45,9 @@ func main() {
product = "grafana-enterprise"
baseURL = createBaseURL(archiveProviderRoot, "enterprise", product, nightly)
var err error
buildArtifacts, err = filterBuildArtifacts([]artifactFilter{
buildArtifacts, err = filterBuildArtifacts(completeBuildArtifactConfigurations, Remove, []artifactFilter{
{os: "win-installer", arch: "amd64"},
}, Remove)
})
if err != nil {
log.Fatalf("Could not filter to the selected build artifacts, err=%v", err)
......
......@@ -193,10 +193,10 @@ const (
Remove filterType = "remove"
)
func filterBuildArtifacts(filters []artifactFilter, ft filterType) ([]buildArtifact, error) {
func filterBuildArtifacts(filterFrom []buildArtifact, ft filterType, filters []artifactFilter) ([]buildArtifact, error) {
var artifacts []buildArtifact
for _, a := range completeBuildArtifactConfigurations {
for _, a := range filterFrom {
matched := false
var match buildArtifact
......@@ -211,7 +211,7 @@ func filterBuildArtifacts(filters []artifactFilter, ft filterType) ([]buildArtif
if matched && ft == Add {
artifacts = append(artifacts, match)
} else if !matched && ft == Remove {
artifacts = append(artifacts, match)
artifacts = append(artifacts, a)
}
}
return artifacts, nil
......
package main
import "testing"
import (
"reflect"
"testing"
)
func TestPreparingReleaseFromRemote(t *testing.T) {
......@@ -148,33 +151,60 @@ func (mockHTTPGetter) getContents(url string) (string, error) {
}
func TestFilterBuildArtifacts(t *testing.T) {
buildArtifacts, _ := filterBuildArtifacts([]artifactFilter{
buildArtifacts, _ := filterBuildArtifacts(completeBuildArtifactConfigurations, Add, []artifactFilter{
{os: "deb", arch: "amd64"},
{os: "rhel", arch: "amd64"},
{os: "linux", arch: "amd64"},
{os: "win", arch: "amd64"},
}, Add)
})
if len(buildArtifacts) != 4 {
t.Errorf("Expected 4 build artifacts after filtering, but was %v", len(buildArtifacts))
}
buildArtifacts, err := filterBuildArtifacts([]artifactFilter{
{os: "win-installer", arch: "amd64"},
}, Remove)
buildArtifacts, err := filterBuildArtifacts([]buildArtifact{
{
os: "linux",
arch: "amd64",
},
{
os: "arm",
arch: "amd64",
},
{
os: "darwin",
arch: "amd64",
},
}, Remove, []artifactFilter{
{os: "darwin", arch: "amd64"},
})
if err != nil {
t.Errorf("Expected all artifacts except win-msi, not error=%v", err)
t.Error()
}
if len(buildArtifacts) != len(completeBuildArtifactConfigurations)-1 {
t.Errorf("Expected %v artifacts but was %v", completeBuildArtifactConfigurations, buildArtifacts)
if len(buildArtifacts) != 2 {
t.Errorf("Expected 2 artifacts, was %v", len(buildArtifacts))
}
for _, ba := range buildArtifacts {
if ba.arch == "amd64" && ba.os == "win-installer" {
t.Errorf("win-installer/amd64 should be gone due to filtering")
if ba.arch == "amd64" && ba.os == "darwin" {
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)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment