Merge branch 'master' into develop

This commit is contained in:
Torkel Ödegaard
2018-11-20 09:47:23 +01:00
104 changed files with 3398 additions and 841 deletions
+1 -3
View File
@@ -32,9 +32,7 @@ echo "Build arguments: $OPT"
go run build.go -goarch armv7 -cc ${CCARMV7} ${OPT} build
go run build.go -goarch arm64 -cc ${CCARM64} ${OPT} build
# MacOS build is broken atm. See Issue #13763
#go run build.go -goos darwin -cc ${CCOSX64} ${OPT} build
go run build.go -goos darwin -cc ${CCOSX64} ${OPT} build
go run build.go -goos windows -cc ${CCWIN64} ${OPT} build
CC=${CCX64} go run build.go ${OPT} build
+3 -1
View File
@@ -2,6 +2,8 @@
# no relation to publish.go
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-v5-3-x/10244"
@@ -11,4 +13,4 @@ _whatsNewUrl="http://docs.grafana.org/guides/whats-new-in-v5-3/"
--wn ${_whatsNewUrl} \
--rn ${_releaseNoteUrl} \
--version ${CIRCLE_TAG} \
--apikey ${GRAFANA_COM_API_KEY}
--apikey ${GRAFANA_COM_API_KEY} ${EXTRA_OPTS}
@@ -16,23 +16,31 @@ type releaseFromExternalContent struct {
func (re releaseFromExternalContent) prepareRelease(baseArchiveUrl, whatsNewUrl string, releaseNotesUrl string, nightly bool) (*release, error) {
version := re.rawVersion[1:]
isBeta := strings.Contains(version, "beta")
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 {
sha256, err := re.getter.getContents(fmt.Sprintf("%s.sha256", ba.getUrl(baseArchiveUrl, version, isBeta)))
sha256, err := re.getter.getContents(fmt.Sprintf("%s.sha256", ba.getUrl(baseArchiveUrl, version, rt)))
if err != nil {
return nil, err
}
builds = append(builds, newBuild(baseArchiveUrl, ba, version, isBeta, sha256))
builds = append(builds, newBuild(baseArchiveUrl, ba, version, rt, sha256))
}
r := release{
Version: version,
ReleaseDate: time.Now().UTC(),
Stable: !isBeta && !nightly,
Beta: isBeta,
Nightly: nightly,
Stable: rt.stable(),
Beta: rt.beta(),
Nightly: rt.nightly(),
WhatsNewUrl: whatsNewUrl,
ReleaseNotesUrl: releaseNotesUrl,
Builds: builds,
@@ -18,6 +18,9 @@ type releaseLocalSources struct {
}
func (r releaseLocalSources) prepareRelease(baseArchiveUrl, whatsNewUrl string, releaseNotesUrl string, nightly bool) (*release, error) {
if !nightly {
return nil, errors.New("Local releases only supported for nightly builds.")
}
buildData := r.findBuilds(baseArchiveUrl)
rel := release{
@@ -70,7 +73,7 @@ func createBuildWalker(path string, data *buildData, archiveTypes []buildArtifac
data.version = version
data.builds = append(data.builds, build{
Os: archive.os,
Url: archive.getUrl(baseArchiveUrl, version, false),
Url: archive.getUrl(baseArchiveUrl, version, NIGHTLY),
Sha256: string(shaBytes),
Arch: archive.arch,
})
+25 -12
View File
@@ -41,30 +41,43 @@ func main() {
var builder releaseBuilder
var product string
archiveProviderRoot := "https://s3-us-west-2.amazonaws.com"
buildArtifacts := completeBuildArtifactConfigurations
if enterprise {
product = "grafana-enterprise"
baseUrl = createBaseUrl(archiveProviderRoot, "grafana-enterprise-releases", product, nightly)
var err error
buildArtifacts, err = filterBuildArtifacts([]artifactFilter{
{os: "deb", arch: "amd64"},
{os: "rhel", arch: "amd64"},
{os: "linux", arch: "amd64"},
{os: "win", arch: "amd64"},
})
if err != nil {
log.Fatalf("Could not filter to the selected build artifacts, err=%v", err)
}
} else {
product = "grafana"
baseUrl = createBaseUrl(archiveProviderRoot, "grafana-releases", product, nightly)
}
if fromLocal {
path, _ := os.Getwd()
builder = releaseLocalSources{
path: path,
artifactConfigurations: buildArtifactConfigurations,
artifactConfigurations: buildArtifacts,
}
} else {
builder = releaseFromExternalContent{
getter: getHttpContents{},
rawVersion: version,
artifactConfigurations: buildArtifactConfigurations,
artifactConfigurations: buildArtifacts,
}
}
archiveProviderRoot := "https://s3-us-west-2.amazonaws.com"
if enterprise {
product = "grafana-enterprise"
baseUrl = createBaseUrl(archiveProviderRoot, "grafana-enterprise-releases", product, nightly)
} else {
product = "grafana"
baseUrl = createBaseUrl(archiveProviderRoot, "grafana-releases", product, nightly)
}
p := publisher{
apiKey: apiKey,
apiUri: "https://grafana.com/api",
+51 -5
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/pkg/errors"
"io/ioutil"
"log"
"net/http"
@@ -61,13 +62,33 @@ func (p *publisher) postRelease(r *release) error {
return nil
}
type ReleaseType int
const (
STABLE ReleaseType = iota + 1
BETA
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
}
func (t buildArtifact) getUrl(baseArchiveUrl, version string, isBeta bool) string {
func (t buildArtifact) getUrl(baseArchiveUrl, version string, releaseType ReleaseType) string {
prefix := "-"
rhelReleaseExtra := ""
@@ -75,7 +96,7 @@ func (t buildArtifact) getUrl(baseArchiveUrl, version string, isBeta bool) strin
prefix = "_"
}
if !isBeta && t.os == "rhel" {
if releaseType.stable() && t.os == "rhel" {
rhelReleaseExtra = "-1"
}
@@ -83,7 +104,7 @@ func (t buildArtifact) getUrl(baseArchiveUrl, version string, isBeta bool) strin
return url
}
var buildArtifactConfigurations = []buildArtifact{
var completeBuildArtifactConfigurations = []buildArtifact{
{
os: "deb",
arch: "arm64",
@@ -141,10 +162,35 @@ var buildArtifactConfigurations = []buildArtifact{
},
}
func newBuild(baseArchiveUrl string, ba buildArtifact, version string, isBeta bool, sha256 string) build {
type artifactFilter struct {
os string
arch string
}
func filterBuildArtifacts(filters []artifactFilter) ([]buildArtifact, error) {
var artifacts []buildArtifact
for _, f := range filters {
matched := false
for _, a := range completeBuildArtifactConfigurations {
if f.os == a.os && f.arch == a.arch {
artifacts = append(artifacts, a)
matched = true
break
}
}
if !matched {
return nil, errors.New(fmt.Sprintf("No buildArtifact for os=%v, arch=%v", f.os, f.arch))
}
}
return artifacts, nil
}
func newBuild(baseArchiveUrl string, ba buildArtifact, version string, rt ReleaseType, sha256 string) build {
return build{
Os: ba.os,
Url: ba.getUrl(baseArchiveUrl, version, isBeta),
Url: ba.getUrl(baseArchiveUrl, version, rt),
Sha256: sha256,
Arch: ba.arch,
}
+113 -32
View File
@@ -4,44 +4,98 @@ import "testing"
func TestPreparingReleaseFromRemote(t *testing.T) {
var builder releaseBuilder
versionIn := "v5.2.0-beta1"
expectedVersion := "5.2.0-beta1"
whatsNewUrl := "https://whatsnews.foo/"
relNotesUrl := "https://relnotes.foo/"
expectedArch := "amd64"
expectedOs := "linux"
buildArtifacts := []buildArtifact{{expectedOs, expectedArch, ".linux-amd64.tar.gz"}}
builder = releaseFromExternalContent{
getter: mockHttpGetter{},
rawVersion: versionIn,
artifactConfigurations: buildArtifactConfigurations,
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.x86_64.rpm",
baseArchiveUrl: "https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana",
buildArtifacts: []buildArtifact{{"rhel", "amd64", ".x86_64.rpm"}},
},
}
rel, _ := builder.prepareRelease("https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana", whatsNewUrl, relNotesUrl, false)
for _, test := range cases {
builder := releaseFromExternalContent{
getter: mockHttpGetter{},
rawVersion: test.version,
artifactConfigurations: test.buildArtifacts,
}
if !rel.Beta || rel.Stable {
t.Errorf("%s should have been tagged as beta (not stable), but wasn't .", versionIn)
}
rel, _ := builder.prepareRelease(test.baseArchiveUrl, test.whatsNewUrl, test.relNotesUrl, test.nightly)
if rel.Version != expectedVersion {
t.Errorf("Expected version to be %s, but it was %s.", expectedVersion, rel.Version)
}
if rel.Beta != test.expectedBeta || rel.Stable != test.expectedStable {
t.Errorf("%s should have been tagged as beta=%v, stable=%v.", test.version, test.expectedBeta, test.expectedStable)
}
expectedBuilds := len(buildArtifacts)
if len(rel.Builds) != expectedBuilds {
t.Errorf("Expected %v builds, but got %v.", expectedBuilds, len(rel.Builds))
}
if rel.Version != test.expectedVersion {
t.Errorf("Expected version to be %s, but it was %s.", test.expectedVersion, rel.Version)
}
build := rel.Builds[0]
if build.Arch != expectedArch {
t.Errorf("Expected arch to be %v, but it was %v", expectedArch, build.Arch)
}
expectedBuilds := len(test.buildArtifacts)
if len(rel.Builds) != expectedBuilds {
t.Errorf("Expected %v builds, but got %v.", expectedBuilds, len(rel.Builds))
}
if build.Os != expectedOs {
t.Errorf("Expected arch to be %v, but it was %v", expectedOs, build.Os)
build := rel.Builds[0]
if build.Arch != test.expectedArch {
t.Errorf("Expected arch to be %v, but it was %v", test.expectedArch, build.Arch)
}
if build.Os != test.expectedOs {
t.Errorf("Expected os to be %v, but it was %v", test.expectedOs, build.Os)
}
if build.Url != test.expectedUrl {
t.Errorf("Expected url to be %v, but it was %v", test.expectedUrl, build.Url)
}
}
}
@@ -61,7 +115,7 @@ func TestPreparingReleaseFromLocal(t *testing.T) {
testDataPath := "testdata"
builder = releaseLocalSources{
path: testDataPath,
artifactConfigurations: buildArtifactConfigurations,
artifactConfigurations: completeBuildArtifactConfigurations,
}
relAll, _ := builder.prepareRelease("https://s3-us-west-2.amazonaws.com/grafana-enterprise-releases/master/grafana-enterprise", whatsNewUrl, relNotesUrl, true)
@@ -116,4 +170,31 @@ func TestPreparingReleaseFromLocal(t *testing.T) {
if build.Os != expectedOs {
t.Fatalf("Expected os to be %s, but was %s", expectedOs, build.Os)
}
_, err := builder.prepareRelease("", "", "", false)
if err == nil {
t.Error("Error was nil, but expected an error as the local releaser only supports nightly builds.")
}
}
func TestFilterBuildArtifacts(t *testing.T) {
buildArtifacts, _ := filterBuildArtifacts([]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))
}
_, err := filterBuildArtifacts([]artifactFilter{
{os: "foobar", arch: "amd64"},
})
if err == nil {
t.Errorf("Expected an error as a we tried to filter on a nonexiststant os.")
}
}