[release-11.5.3] CI: Remove unused release_publisher scripts (#101158)
* CI: Remove unused release_publisher scripts (#101019)
* Remove the unused `release_publisher` script.
* Remove the "whats new check" in Drone.
* Automatically set the What's New URL in releases based on the tagged version.
(cherry picked from commit 49e5f77dd1)
* rerun?
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# no relation to publish.go
|
||||
|
||||
# shellcheck disable=SC2124
|
||||
|
||||
EXTRA_OPTS="$@"
|
||||
|
||||
# Right now we hack this in into the publish script.
|
||||
# Eventually we might want to keep a list of all previous releases somewhere.
|
||||
_releaseNoteUrl="https://community.grafana.com/t/release-notes-v7-0-x/29381"
|
||||
_whatsNewUrl="https://grafana.com/docs/grafana/latest/guides/whats-new-in-v7-0/"
|
||||
|
||||
./scripts/build/release_publisher/release_publisher \
|
||||
--wn "${_whatsNewUrl}" \
|
||||
--rn "${_releaseNoteUrl}" \
|
||||
--version "${CIRCLE_TAG}" \
|
||||
--apikey "${GRAFANA_COM_API_KEY}" "${EXTRA_OPTS}"
|
||||
@@ -1,71 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type releaseFromExternalContent struct {
|
||||
getter urlGetter
|
||||
rawVersion string
|
||||
artifactConfigurations []buildArtifact
|
||||
}
|
||||
|
||||
func (re releaseFromExternalContent) prepareRelease(baseArchiveURL, whatsNewURL string, releaseNotesURL string, nightly bool) (*release, error) {
|
||||
version := re.rawVersion[1:]
|
||||
beta := strings.Contains(version, "beta")
|
||||
var rt releaseType
|
||||
if beta {
|
||||
rt = BETA
|
||||
} else if nightly {
|
||||
rt = NIGHTLY
|
||||
} else {
|
||||
rt = STABLE
|
||||
}
|
||||
|
||||
builds := []build{}
|
||||
for _, ba := range re.artifactConfigurations {
|
||||
url := ba.getURL(baseArchiveURL, version, rt)
|
||||
sha256, err := re.getter.getContents(fmt.Sprintf("%s.sha256", url))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builds = append(builds, newBuild(url, ba, sha256))
|
||||
}
|
||||
|
||||
r := release{
|
||||
Version: version,
|
||||
ReleaseDate: time.Now().UTC(),
|
||||
Stable: rt.stable(),
|
||||
Beta: rt.beta(),
|
||||
Nightly: rt.nightly(),
|
||||
WhatsNewURL: whatsNewURL,
|
||||
ReleaseNotesURL: releaseNotesURL,
|
||||
Builds: builds,
|
||||
}
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
type urlGetter interface {
|
||||
getContents(url string) (string, error)
|
||||
}
|
||||
|
||||
type getHTTPContents struct{}
|
||||
|
||||
func (getHTTPContents) getContents(url string) (string, error) {
|
||||
response, err := http.Get(url)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
defer response.Body.Close()
|
||||
all, err := io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(all), nil
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var version string
|
||||
var whatsNewURL string
|
||||
var releaseNotesURL string
|
||||
var dryRun bool
|
||||
var enterprise bool
|
||||
var nightly bool
|
||||
var apiKey string
|
||||
|
||||
flag.StringVar(&version, "version", "", "Grafana version (ex: --version v5.2.0-beta1)")
|
||||
flag.StringVar(&whatsNewURL, "wn", "", "What's new url (ex: --wn http://docs.grafana.org/guides/whats-new-in-v5-2/)")
|
||||
flag.StringVar(&releaseNotesURL, "rn", "", "Grafana version (ex: --rn https://community.grafana.com/t/release-notes-v5-2-x/7894)")
|
||||
flag.StringVar(&apiKey, "apikey", "", "Grafana.com API key (ex: --apikey ABCDEF)")
|
||||
flag.BoolVar(&dryRun, "dry-run", false, "--dry-run")
|
||||
flag.BoolVar(&enterprise, "enterprise", false, "--enterprise")
|
||||
flag.BoolVar(&nightly, "nightly", false, "--nightly (default: false)")
|
||||
flag.Parse()
|
||||
|
||||
if len(os.Args) == 1 {
|
||||
fmt.Println("Usage: go run publisher.go main.go --version <v> --wn <what's new url> --rn <release notes url> --apikey <api key> --dry-run false --enterprise false --nightly false")
|
||||
fmt.Println("example: go run publisher.go main.go --version v5.2.0-beta2 --wn http://docs.grafana.org/guides/whats-new-in-v5-2/ --rn https://community.grafana.com/t/release-notes-v5-2-x/7894 --apikey ASDF123 --dry-run --enterprise")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if dryRun {
|
||||
log.Println("Dry-run has been enabled.")
|
||||
}
|
||||
var baseURL string
|
||||
var builder releaseBuilder
|
||||
var product string
|
||||
|
||||
archiveProviderRoot := "https://dl.grafana.com"
|
||||
buildArtifacts := completeBuildArtifactConfigurations
|
||||
|
||||
if enterprise {
|
||||
product = "grafana-enterprise"
|
||||
baseURL = createBaseURL(archiveProviderRoot, "enterprise", product, nightly)
|
||||
} else {
|
||||
product = "grafana"
|
||||
baseURL = createBaseURL(archiveProviderRoot, "oss", product, nightly)
|
||||
}
|
||||
|
||||
builder = releaseFromExternalContent{
|
||||
getter: getHTTPContents{},
|
||||
rawVersion: version,
|
||||
artifactConfigurations: buildArtifacts,
|
||||
}
|
||||
|
||||
p := publisher{
|
||||
apiKey: apiKey,
|
||||
apiURI: "https://grafana.com/api",
|
||||
product: product,
|
||||
dryRun: dryRun,
|
||||
enterprise: enterprise,
|
||||
baseArchiveURL: baseURL,
|
||||
builder: builder,
|
||||
}
|
||||
if err := p.doRelease(whatsNewURL, releaseNotesURL, nightly); err != nil {
|
||||
log.Fatalf("error: %v", err)
|
||||
}
|
||||
}
|
||||
func createBaseURL(root string, bucketName string, product string, nightly bool) string {
|
||||
var subPath string
|
||||
if nightly {
|
||||
subPath = "main"
|
||||
} else {
|
||||
subPath = "release"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s/%s/%s/%s", root, bucketName, subPath, product)
|
||||
}
|
||||
@@ -1,312 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type publisher struct {
|
||||
apiKey string
|
||||
apiURI string
|
||||
product string
|
||||
dryRun bool
|
||||
enterprise bool
|
||||
baseArchiveURL string
|
||||
builder releaseBuilder
|
||||
}
|
||||
|
||||
type releaseBuilder interface {
|
||||
prepareRelease(baseArchiveURL, whatsNewURL string, releaseNotesURL string, nightly bool) (*release, error)
|
||||
}
|
||||
|
||||
func (p *publisher) doRelease(whatsNewURL string, releaseNotesURL string, nightly bool) error {
|
||||
currentRelease, err := p.builder.prepareRelease(p.baseArchiveURL, whatsNewURL, releaseNotesURL, nightly)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := p.postRelease(currentRelease); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *publisher) postRelease(r *release) error {
|
||||
err := p.postRequest("/versions", r, fmt.Sprintf("Create Release %s", r.Version))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = p.postRequest("/versions/"+r.Version, r, fmt.Sprintf("Update Release %s", r.Version))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, b := range r.Builds {
|
||||
err = p.postRequest(fmt.Sprintf("/versions/%s/packages", r.Version), b, fmt.Sprintf("Create Build %s %s", b.Os, b.Arch))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = p.postRequest(fmt.Sprintf("/versions/%s/packages/%s/%s", r.Version, b.Arch, b.Os), b, fmt.Sprintf("Update Build %s %s", b.Os, b.Arch))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type releaseType int
|
||||
|
||||
const (
|
||||
// STABLE is a release type constant
|
||||
STABLE releaseType = iota + 1
|
||||
// BETA is a release type constant
|
||||
BETA
|
||||
// NIGHTLY is a release type constant
|
||||
NIGHTLY
|
||||
)
|
||||
|
||||
func (rt releaseType) beta() bool {
|
||||
return rt == BETA
|
||||
}
|
||||
|
||||
func (rt releaseType) stable() bool {
|
||||
return rt == STABLE
|
||||
}
|
||||
|
||||
func (rt releaseType) nightly() bool {
|
||||
return rt == NIGHTLY
|
||||
}
|
||||
|
||||
type buildArtifact struct {
|
||||
os string
|
||||
arch string
|
||||
urlPostfix string
|
||||
packagePostfix string
|
||||
}
|
||||
|
||||
func (t buildArtifact) getURL(baseArchiveURL, version string, releaseType releaseType) string {
|
||||
prefix := "-"
|
||||
rev := ""
|
||||
|
||||
if t.os == "deb" {
|
||||
prefix = "_"
|
||||
}
|
||||
|
||||
if t.os == "rhel" {
|
||||
rev = "-1"
|
||||
}
|
||||
|
||||
verComponents := strings.Split(version, "-")
|
||||
if len(verComponents) > 2 {
|
||||
panic(fmt.Sprintf("Version string contains more than one hyphen: %q", version))
|
||||
}
|
||||
|
||||
switch t.os {
|
||||
case "deb", "rhel":
|
||||
if len(verComponents) > 1 {
|
||||
// With Debian and RPM packages, it's customary to prefix any pre-release component with a ~, since this
|
||||
// is considered of lower lexical value than the empty character, and this way pre-release versions are
|
||||
// considered to be of a lower version than the final version (which lacks this suffix).
|
||||
version = fmt.Sprintf("%s~%s", verComponents[0], verComponents[1])
|
||||
}
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s%s%s%s%s%s", baseArchiveURL, t.packagePostfix, prefix, version, rev, t.urlPostfix)
|
||||
return url
|
||||
}
|
||||
|
||||
var completeBuildArtifactConfigurations = []buildArtifact{
|
||||
{
|
||||
os: "deb",
|
||||
arch: "arm64",
|
||||
urlPostfix: "_arm64.deb",
|
||||
},
|
||||
{
|
||||
os: "rhel",
|
||||
arch: "arm64",
|
||||
urlPostfix: ".aarch64.rpm",
|
||||
},
|
||||
{
|
||||
os: "linux",
|
||||
arch: "arm64",
|
||||
urlPostfix: ".linux-arm64.tar.gz",
|
||||
},
|
||||
{
|
||||
os: "deb",
|
||||
arch: "armv7",
|
||||
urlPostfix: "_armhf.deb",
|
||||
},
|
||||
{
|
||||
os: "deb",
|
||||
arch: "armv6",
|
||||
packagePostfix: "-rpi",
|
||||
urlPostfix: "_armhf.deb",
|
||||
},
|
||||
{
|
||||
os: "rhel",
|
||||
arch: "armv7",
|
||||
urlPostfix: ".armhfp.rpm",
|
||||
},
|
||||
{
|
||||
os: "linux",
|
||||
arch: "armv6",
|
||||
urlPostfix: ".linux-armv6.tar.gz",
|
||||
},
|
||||
{
|
||||
os: "linux",
|
||||
arch: "armv7",
|
||||
urlPostfix: ".linux-armv7.tar.gz",
|
||||
},
|
||||
{
|
||||
os: "darwin",
|
||||
arch: "amd64",
|
||||
urlPostfix: ".darwin-amd64.tar.gz",
|
||||
},
|
||||
{
|
||||
os: "deb",
|
||||
arch: "amd64",
|
||||
urlPostfix: "_amd64.deb",
|
||||
},
|
||||
{
|
||||
os: "rhel",
|
||||
arch: "amd64",
|
||||
urlPostfix: ".x86_64.rpm",
|
||||
},
|
||||
{
|
||||
os: "linux",
|
||||
arch: "amd64",
|
||||
urlPostfix: ".linux-amd64.tar.gz",
|
||||
},
|
||||
{
|
||||
os: "win",
|
||||
arch: "amd64",
|
||||
urlPostfix: ".windows-amd64.zip",
|
||||
},
|
||||
{
|
||||
os: "win-installer",
|
||||
arch: "amd64",
|
||||
urlPostfix: ".windows-amd64.msi",
|
||||
},
|
||||
}
|
||||
|
||||
type artifactFilter struct {
|
||||
os string
|
||||
arch string
|
||||
}
|
||||
|
||||
type filterType string
|
||||
|
||||
const (
|
||||
Add filterType = "add"
|
||||
Remove filterType = "remove"
|
||||
)
|
||||
|
||||
func filterBuildArtifacts(filterFrom []buildArtifact, ft filterType, filters []artifactFilter) ([]buildArtifact, error) {
|
||||
var artifacts []buildArtifact
|
||||
|
||||
for _, a := range filterFrom {
|
||||
matched := false
|
||||
var match buildArtifact
|
||||
|
||||
for _, f := range filters {
|
||||
if f.os == a.os && f.arch == a.arch {
|
||||
match = a
|
||||
matched = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if matched && ft == Add {
|
||||
artifacts = append(artifacts, match)
|
||||
} else if !matched && ft == Remove {
|
||||
artifacts = append(artifacts, a)
|
||||
}
|
||||
}
|
||||
return artifacts, nil
|
||||
}
|
||||
|
||||
func newBuild(url string, ba buildArtifact, sha256 string) build {
|
||||
return build{
|
||||
Os: ba.os,
|
||||
URL: url,
|
||||
Sha256: sha256,
|
||||
Arch: ba.arch,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *publisher) apiURL(url string) string {
|
||||
return fmt.Sprintf("%s/%s%s", p.apiURI, p.product, url)
|
||||
}
|
||||
|
||||
func (p *publisher) postRequest(url string, obj any, desc string) error {
|
||||
jsonBytes, err := json.Marshal(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if p.dryRun {
|
||||
log.Printf("POST to %s:\n", p.apiURL(url))
|
||||
log.Println(string(jsonBytes))
|
||||
return nil
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(http.MethodPost, p.apiURL(url), bytes.NewReader(jsonBytes))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Add("Authorization", "Bearer "+p.apiKey)
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if res.StatusCode == http.StatusOK {
|
||||
log.Printf("Action: %s \t OK", desc)
|
||||
return nil
|
||||
}
|
||||
|
||||
if res.Body != nil {
|
||||
defer res.Body.Close()
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if strings.Contains(string(body), "already exists") || strings.Contains(string(body), "Nothing to update") {
|
||||
log.Printf("Action: %s \t Already exists", desc)
|
||||
} else {
|
||||
log.Printf("Action: %s \t Failed - Status: %v", desc, res.Status)
|
||||
log.Printf("Resp: %s", body)
|
||||
log.Fatalf("Quitting")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type release struct {
|
||||
Version string `json:"version"`
|
||||
ReleaseDate time.Time `json:"releaseDate"`
|
||||
Stable bool `json:"stable"`
|
||||
Beta bool `json:"beta"`
|
||||
Nightly bool `json:"nightly"`
|
||||
WhatsNewURL string `json:"whatsNewUrl"`
|
||||
ReleaseNotesURL string `json:"releaseNotesUrl"`
|
||||
Builds []build `json:"-"`
|
||||
}
|
||||
|
||||
type build struct {
|
||||
Os string `json:"os"`
|
||||
URL string `json:"url"`
|
||||
Sha256 string `json:"sha256"`
|
||||
Arch string `json:"arch"`
|
||||
}
|
||||
@@ -1,201 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestPreparingReleaseFromRemote(t *testing.T) {
|
||||
cases := []struct {
|
||||
version string
|
||||
expectedVersion string
|
||||
whatsNewURL string
|
||||
relNotesURL string
|
||||
nightly bool
|
||||
expectedBeta bool
|
||||
expectedStable bool
|
||||
expectedArch string
|
||||
expectedOs string
|
||||
expectedURL string
|
||||
baseArchiveURL string
|
||||
buildArtifacts []buildArtifact
|
||||
}{
|
||||
{
|
||||
version: "v5.2.0-beta1",
|
||||
expectedVersion: "5.2.0-beta1",
|
||||
whatsNewURL: "https://whatsnews.foo/",
|
||||
relNotesURL: "https://relnotes.foo/",
|
||||
nightly: false,
|
||||
expectedBeta: true,
|
||||
expectedStable: false,
|
||||
expectedArch: "amd64",
|
||||
expectedOs: "linux",
|
||||
expectedURL: "https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.2.0-beta1.linux-amd64.tar.gz",
|
||||
baseArchiveURL: "https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana",
|
||||
buildArtifacts: []buildArtifact{{"linux", "amd64", ".linux-amd64.tar.gz", ""}},
|
||||
},
|
||||
{
|
||||
version: "v5.2.3",
|
||||
expectedVersion: "5.2.3",
|
||||
whatsNewURL: "https://whatsnews.foo/",
|
||||
relNotesURL: "https://relnotes.foo/",
|
||||
nightly: false,
|
||||
expectedBeta: false,
|
||||
expectedStable: true,
|
||||
expectedArch: "amd64",
|
||||
expectedOs: "rhel",
|
||||
expectedURL: "https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.2.3-1.x86_64.rpm",
|
||||
baseArchiveURL: "https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana",
|
||||
buildArtifacts: []buildArtifact{{"rhel", "amd64", ".x86_64.rpm", ""}},
|
||||
},
|
||||
{
|
||||
version: "v5.4.0-pre1asdf",
|
||||
expectedVersion: "5.4.0-pre1asdf",
|
||||
whatsNewURL: "https://whatsnews.foo/",
|
||||
relNotesURL: "https://relnotes.foo/",
|
||||
nightly: true,
|
||||
expectedBeta: false,
|
||||
expectedStable: false,
|
||||
expectedArch: "amd64",
|
||||
expectedOs: "rhel",
|
||||
expectedURL: "https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.4.0~pre1asdf-1.x86_64.rpm",
|
||||
baseArchiveURL: "https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana",
|
||||
buildArtifacts: []buildArtifact{{"rhel", "amd64", ".x86_64.rpm", ""}},
|
||||
},
|
||||
{
|
||||
version: "v5.4.0-pre1asdf",
|
||||
expectedVersion: "5.4.0-pre1asdf",
|
||||
whatsNewURL: "https://whatsnews.foo/",
|
||||
relNotesURL: "https://relnotes.foo/",
|
||||
nightly: true,
|
||||
expectedBeta: false,
|
||||
expectedStable: false,
|
||||
expectedArch: "armv6",
|
||||
expectedOs: "deb",
|
||||
expectedURL: "https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-rpi_5.4.0~pre1asdf_armhf.deb",
|
||||
baseArchiveURL: "https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana",
|
||||
buildArtifacts: []buildArtifact{
|
||||
{os: "deb", arch: "armv6", urlPostfix: "_armhf.deb", packagePostfix: "-rpi"},
|
||||
},
|
||||
},
|
||||
{
|
||||
version: "v5.4.0-pre1asdf",
|
||||
expectedVersion: "5.4.0-pre1asdf",
|
||||
whatsNewURL: "https://whatsnews.foo/",
|
||||
relNotesURL: "https://relnotes.foo/",
|
||||
nightly: true,
|
||||
expectedBeta: false,
|
||||
expectedStable: false,
|
||||
expectedArch: "amd64",
|
||||
expectedOs: "win-installer",
|
||||
expectedURL: "https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.4.0-pre1asdf.windows-amd64.msi",
|
||||
baseArchiveURL: "https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana",
|
||||
buildArtifacts: []buildArtifact{{"win-installer", "amd64", ".windows-amd64.msi", ""}},
|
||||
},
|
||||
{
|
||||
version: "v5.4.0-pre1asdf",
|
||||
expectedVersion: "5.4.0-pre1asdf",
|
||||
whatsNewURL: "https://whatsnews.foo/",
|
||||
relNotesURL: "https://relnotes.foo/",
|
||||
nightly: true,
|
||||
expectedBeta: false,
|
||||
expectedStable: false,
|
||||
expectedArch: "amd64",
|
||||
expectedOs: "win",
|
||||
expectedURL: "https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.4.0-pre1asdf.windows-amd64.zip",
|
||||
baseArchiveURL: "https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana",
|
||||
buildArtifacts: []buildArtifact{{"win", "amd64", ".windows-amd64.zip", ""}},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range cases {
|
||||
builder := releaseFromExternalContent{
|
||||
getter: mockHTTPGetter{},
|
||||
rawVersion: test.version,
|
||||
artifactConfigurations: test.buildArtifacts,
|
||||
}
|
||||
|
||||
t.Log("Preparing release", "baseArchiveURL", test.baseArchiveURL, "nightly", test.nightly)
|
||||
rel, err := builder.prepareRelease(test.baseArchiveURL, test.whatsNewURL, test.relNotesURL, test.nightly)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, test.expectedBeta, rel.Beta)
|
||||
assert.Equal(t, test.expectedStable, rel.Stable)
|
||||
assert.Equal(t, test.expectedVersion, rel.Version)
|
||||
|
||||
assert.Len(t, rel.Builds, len(test.buildArtifacts))
|
||||
|
||||
build := rel.Builds[0]
|
||||
assert.Equal(t, test.expectedArch, build.Arch)
|
||||
assert.Equal(t, test.expectedOs, build.Os)
|
||||
assert.Equal(t, test.expectedURL, build.URL)
|
||||
}
|
||||
}
|
||||
|
||||
type mockHTTPGetter struct{}
|
||||
|
||||
func (mockHTTPGetter) getContents(url string) (string, error) {
|
||||
return url, nil
|
||||
}
|
||||
|
||||
func TestFilterBuildArtifacts(t *testing.T) {
|
||||
buildArtifacts, _ := filterBuildArtifacts(completeBuildArtifactConfigurations, Add, []artifactFilter{
|
||||
{os: "deb", arch: "amd64"},
|
||||
{os: "rhel", arch: "amd64"},
|
||||
{os: "linux", arch: "amd64"},
|
||||
{os: "win", arch: "amd64"},
|
||||
})
|
||||
|
||||
if len(buildArtifacts) != 4 {
|
||||
t.Errorf("Expected 4 build artifacts after filtering, but was %v", len(buildArtifacts))
|
||||
}
|
||||
|
||||
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.Error()
|
||||
}
|
||||
|
||||
if len(buildArtifacts) != 2 {
|
||||
t.Errorf("Expected 2 artifacts, was %v", len(buildArtifacts))
|
||||
}
|
||||
|
||||
for _, ba := range buildArtifacts {
|
||||
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)
|
||||
}
|
||||
}
|
||||
Vendored
Vendored
-1
@@ -1 +0,0 @@
|
||||
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||
Vendored
Vendored
-1
@@ -1 +0,0 @@
|
||||
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||
Vendored
Vendored
-1
@@ -1 +0,0 @@
|
||||
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||
-1
@@ -1 +0,0 @@
|
||||
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||
Reference in New Issue
Block a user