mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
build: publisher can find artifacts from local sources.
This commit is contained in:
parent
c5c3e08442
commit
d9eaec99e2
@ -0,0 +1 @@
|
||||
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
@ -0,0 +1 @@
|
||||
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
@ -0,0 +1 @@
|
||||
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
@ -0,0 +1 @@
|
||||
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
91
scripts/build/release_publisher/localrelease.go
Normal file
91
scripts/build/release_publisher/localrelease.go
Normal file
@ -0,0 +1,91 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type releaseLocalSources struct {
|
||||
path string
|
||||
}
|
||||
|
||||
func (r releaseLocalSources) prepareRelease(baseArchiveUrl, whatsNewUrl string, releaseNotesUrl string, artifactConfigurations []buildArtifact) (*release, error) {
|
||||
buildData := r.findBuilds(artifactConfigurations, baseArchiveUrl)
|
||||
|
||||
rel := release{
|
||||
Version: buildData.version,
|
||||
ReleaseDate: time.Time{},
|
||||
Stable: false,
|
||||
Beta: false,
|
||||
Nightly: true,
|
||||
WhatsNewUrl: whatsNewUrl,
|
||||
ReleaseNotesUrl: releaseNotesUrl,
|
||||
Builds: buildData.builds,
|
||||
}
|
||||
|
||||
return &rel, nil
|
||||
}
|
||||
|
||||
type buildData struct {
|
||||
version string
|
||||
builds []build
|
||||
}
|
||||
|
||||
func (r releaseLocalSources) findBuilds(buildArtifacts []buildArtifact, baseArchiveUrl string) buildData {
|
||||
data := buildData{}
|
||||
filepath.Walk(r.path, createBuildWalker(r.path, &data, buildArtifacts, baseArchiveUrl))
|
||||
return data
|
||||
}
|
||||
|
||||
func createBuildWalker(path string, data *buildData, archiveTypes []buildArtifact, baseArchiveUrl string) func(path string, f os.FileInfo, err error) error {
|
||||
return func(path string, f os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
log.Printf("error: %v", err)
|
||||
}
|
||||
|
||||
if f.Name() == path || strings.HasSuffix(f.Name(), ".sha256") {
|
||||
return nil
|
||||
}
|
||||
|
||||
shaBytes, err := ioutil.ReadFile(path + ".sha256")
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to read sha256 file %v", err)
|
||||
}
|
||||
|
||||
|
||||
for _, archive := range archiveTypes {
|
||||
if strings.HasSuffix(f.Name(), archive.urlPostfix) {
|
||||
version, err := grabVersion(f.Name(), archive.urlPostfix)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
continue
|
||||
}
|
||||
data.version = version
|
||||
data.builds = append(data.builds, build{
|
||||
Os: archive.os,
|
||||
Url: archive.getUrl(baseArchiveUrl, version, false),
|
||||
Sha256: string(shaBytes),
|
||||
Arch: archive.arch,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
func grabVersion(name string, suffix string) (string, error) {
|
||||
match := regexp.MustCompile(fmt.Sprintf(`grafana(-enterprise)?[-_](.*)%s`, suffix)).FindSubmatch([]byte(name))
|
||||
if len(match) > 0 {
|
||||
return string(match[2]), nil
|
||||
}
|
||||
|
||||
return "", errors.New("No version found.")
|
||||
}
|
@ -11,7 +11,9 @@ func TestPreparingReleaseFromRemote(t *testing.T) {
|
||||
expectedOs := "linux"
|
||||
buildArtifacts := []buildArtifact{{expectedOs,expectedArch, ".linux-amd64.tar.gz"}}
|
||||
|
||||
builder := releaseFromExternalContent{
|
||||
var builder releaseBuilder
|
||||
|
||||
builder = releaseFromExternalContent{
|
||||
getter: mockHttpGetter{},
|
||||
rawVersion: versionIn,
|
||||
}
|
||||
@ -49,5 +51,60 @@ func (mockHttpGetter) getContents(url string) (string, error) {
|
||||
|
||||
|
||||
func TestPreparingReleaseFromLocal(t *testing.T) {
|
||||
whatsNewUrl := "https://whatsnews.foo/"
|
||||
relNotesUrl := "https://relnotes.foo/"
|
||||
expectedVersion := "5.4.0-123pre1"
|
||||
expectedBuilds := 4
|
||||
|
||||
var builder releaseBuilder
|
||||
builder = releaseLocalSources{
|
||||
path: "local_test_data",
|
||||
}
|
||||
|
||||
relAll, _ := builder.prepareRelease("https://s3-us-west-2.amazonaws.com/grafana-enterprise-releases/master/grafana-enterprise", whatsNewUrl, relNotesUrl, buildArtifactConfigurations)
|
||||
|
||||
if relAll.Stable || !relAll.Nightly {
|
||||
t.Error("Expected a nightly release but wasn't.")
|
||||
}
|
||||
|
||||
if relAll.ReleaseNotesUrl != relNotesUrl {
|
||||
t.Errorf("expected releaseNotesUrl to be %s, but it was %s", relNotesUrl, relAll.ReleaseNotesUrl)
|
||||
}
|
||||
if relAll.WhatsNewUrl != whatsNewUrl {
|
||||
t.Errorf("expected whatsNewUrl to be %s, but it was %s", whatsNewUrl, relAll.WhatsNewUrl)
|
||||
}
|
||||
|
||||
if relAll.Beta {
|
||||
t.Errorf("Expected release to be nightly, not beta.")
|
||||
}
|
||||
|
||||
if relAll.Version != expectedVersion {
|
||||
t.Errorf("Expected version=%s, but got=%s", expectedVersion, relAll.Version)
|
||||
}
|
||||
|
||||
if len(relAll.Builds) != expectedBuilds {
|
||||
t.Errorf("Expected %v builds, but was %v", expectedBuilds, len(relAll.Builds))
|
||||
}
|
||||
|
||||
expectedArch := "amd64"
|
||||
expectedOs := "win"
|
||||
relOne, _ := builder.prepareRelease("https://s3-us-west-2.amazonaws.com/grafana-enterprise-releases/master/grafana-enterprise", whatsNewUrl, relNotesUrl, []buildArtifact{{
|
||||
os: expectedOs,
|
||||
arch: expectedArch,
|
||||
urlPostfix: ".windows-amd64.zip",
|
||||
}})
|
||||
|
||||
if len(relOne.Builds) != 1 {
|
||||
t.Errorf("Expected 1 artifact, but was %v", len(relOne.Builds))
|
||||
}
|
||||
|
||||
build := relOne.Builds[0]
|
||||
|
||||
if build.Arch != expectedArch {
|
||||
t.Fatalf("Expected arch to be %s, but was %s", expectedArch, build.Arch)
|
||||
}
|
||||
|
||||
if build.Os != expectedOs {
|
||||
t.Fatalf("Expected os to be %s, but was %s", expectedOs, build.Os)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user