mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
build: refactor releaser.
This commit is contained in:
62
scripts/build/release_publisher/externalrelease.go
Normal file
62
scripts/build/release_publisher/externalrelease.go
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type releaseFromExternalContent struct {
|
||||||
|
getter urlGetter
|
||||||
|
rawVersion string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (re releaseFromExternalContent) prepareRelease(baseArchiveUrl, whatsNewUrl string, releaseNotesUrl string, artifactConfigurations []buildArtifact) (*release, error) {
|
||||||
|
version := re.rawVersion[1:]
|
||||||
|
now := time.Now()
|
||||||
|
isBeta := strings.Contains(version, "beta")
|
||||||
|
|
||||||
|
builds := []build{}
|
||||||
|
for _, ba := range artifactConfigurations {
|
||||||
|
sha256, err := re.getter.getContents(fmt.Sprintf("%s.sha256", ba.getUrl(baseArchiveUrl, version, isBeta)))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
builds = append(builds, newBuild(baseArchiveUrl, ba, version, isBeta, sha256))
|
||||||
|
}
|
||||||
|
|
||||||
|
r := release{
|
||||||
|
Version: version,
|
||||||
|
ReleaseDate: time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local),
|
||||||
|
Stable: !isBeta,
|
||||||
|
Beta: isBeta,
|
||||||
|
Nightly: false,
|
||||||
|
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 := ioutil.ReadAll(response.Body)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(all), nil
|
||||||
|
}
|
||||||
@@ -141,38 +141,6 @@ var buildArtifactConfigurations = []buildArtifact{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
type releaseFromExternalContent struct {
|
|
||||||
getter urlGetter
|
|
||||||
rawVersion string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (re releaseFromExternalContent) prepareRelease(baseArchiveUrl, whatsNewUrl string, releaseNotesUrl string, artifactConfigurations []buildArtifact) (*release, error) {
|
|
||||||
version := re.rawVersion[1:]
|
|
||||||
now := time.Now()
|
|
||||||
isBeta := strings.Contains(version, "beta")
|
|
||||||
|
|
||||||
builds := []build{}
|
|
||||||
for _, ba := range artifactConfigurations {
|
|
||||||
sha256, err := re.getter.getContents(fmt.Sprintf("%s.sha256", ba.getUrl(baseArchiveUrl, version, isBeta)))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
builds = append(builds, newBuild(baseArchiveUrl, ba, version, isBeta, sha256))
|
|
||||||
}
|
|
||||||
|
|
||||||
r := release{
|
|
||||||
Version: version,
|
|
||||||
ReleaseDate: time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local),
|
|
||||||
Stable: !isBeta,
|
|
||||||
Beta: isBeta,
|
|
||||||
Nightly: false,
|
|
||||||
WhatsNewUrl: whatsNewUrl,
|
|
||||||
ReleaseNotesUrl: releaseNotesUrl,
|
|
||||||
Builds: builds,
|
|
||||||
}
|
|
||||||
return &r, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func newBuild(baseArchiveUrl string, ba buildArtifact, version string, isBeta bool, sha256 string) build {
|
func newBuild(baseArchiveUrl string, ba buildArtifact, version string, isBeta bool, sha256 string) build {
|
||||||
return build{
|
return build{
|
||||||
Os: ba.os,
|
Os: ba.os,
|
||||||
@@ -251,24 +219,3 @@ type build struct {
|
|||||||
Sha256 string `json:"sha256"`
|
Sha256 string `json:"sha256"`
|
||||||
Arch string `json:"arch"`
|
Arch string `json:"arch"`
|
||||||
}
|
}
|
||||||
|
|
||||||
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 := ioutil.ReadAll(response.Body)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(all), nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package main
|
|||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestNewRelease(t *testing.T) {
|
func TestPreparingReleaseFromRemote(t *testing.T) {
|
||||||
versionIn := "v5.2.0-beta1"
|
versionIn := "v5.2.0-beta1"
|
||||||
expectedVersion := "5.2.0-beta1"
|
expectedVersion := "5.2.0-beta1"
|
||||||
whatsNewUrl := "https://whatsnews.foo/"
|
whatsNewUrl := "https://whatsnews.foo/"
|
||||||
@@ -46,3 +46,8 @@ type mockHttpGetter struct{}
|
|||||||
func (mockHttpGetter) getContents(url string) (string, error) {
|
func (mockHttpGetter) getContents(url string) (string, error) {
|
||||||
return url, nil
|
return url, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func TestPreparingReleaseFromLocal(t *testing.T) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user