mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 10:17:05 +08:00
build: prepares release tool for finding local releases.
This commit is contained in:
@ -12,6 +12,7 @@ func main() {
|
||||
var whatsNewUrl string
|
||||
var releaseNotesUrl string
|
||||
var dryRun bool
|
||||
var enterprise bool
|
||||
var apiKey string
|
||||
|
||||
flag.StringVar(&version, "version", "", "Grafana version (ex: --version v5.2.0-beta1)")
|
||||
@ -19,25 +20,39 @@ func main() {
|
||||
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.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")
|
||||
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 true")
|
||||
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")
|
||||
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
|
||||
|
||||
if enterprise {
|
||||
baseUrl = fmt.Sprintf("https://s3-us-west-2.amazonaws.com/%s", "grafana-enterprise-releases/release/grafana-enterprise")
|
||||
} else {
|
||||
baseUrl = fmt.Sprintf("https://s3-us-west-2.amazonaws.com/%s", "grafana-releases/release/grafana")
|
||||
}
|
||||
|
||||
p := publisher{
|
||||
apiKey: apiKey,
|
||||
baseUri: "https://grafana.com/api",
|
||||
product: "grafana",
|
||||
dryRun: dryRun,
|
||||
apiKey: apiKey,
|
||||
baseUri: "https://grafana.com/api",
|
||||
product: "grafana",
|
||||
dryRun: dryRun,
|
||||
enterprise: enterprise,
|
||||
baseArchiveUrl: baseUrl,
|
||||
builder: releaseFromExternalContent{
|
||||
getter: getHttpContents{},
|
||||
rawVersion: version,
|
||||
},
|
||||
}
|
||||
if err := p.doRelease(version, whatsNewUrl, releaseNotesUrl); err != nil {
|
||||
if err := p.doRelease(whatsNewUrl, releaseNotesUrl); err != nil {
|
||||
log.Fatalf("error: %v", err)
|
||||
}
|
||||
}
|
||||
|
@ -12,14 +12,21 @@ import (
|
||||
)
|
||||
|
||||
type publisher struct {
|
||||
apiKey string
|
||||
baseUri string
|
||||
product string
|
||||
dryRun bool
|
||||
apiKey string
|
||||
baseUri string
|
||||
product string
|
||||
dryRun bool
|
||||
enterprise bool
|
||||
baseArchiveUrl string
|
||||
builder releaseBuilder
|
||||
}
|
||||
|
||||
func (p *publisher) doRelease(version string, whatsNewUrl string, releaseNotesUrl string) error {
|
||||
currentRelease, err := newRelease(version, whatsNewUrl, releaseNotesUrl, buildArtifactConfigurations, getHttpContents{})
|
||||
type releaseBuilder interface {
|
||||
prepareRelease(baseArchiveUrl, whatsNewUrl string, releaseNotesUrl string, artifactConfigurations []buildArtifact) (*release, error)
|
||||
}
|
||||
|
||||
func (p *publisher) doRelease(whatsNewUrl string, releaseNotesUrl string) error {
|
||||
currentRelease, err := p.builder.prepareRelease(p.baseArchiveUrl, whatsNewUrl, releaseNotesUrl, buildArtifactConfigurations)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -54,15 +61,13 @@ func (p *publisher) postRelease(r *release) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
const baseArhiveUrl = "https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana"
|
||||
|
||||
type buildArtifact struct {
|
||||
os string
|
||||
arch string
|
||||
urlPostfix string
|
||||
}
|
||||
|
||||
func (t buildArtifact) getUrl(version string, isBeta bool) string {
|
||||
func (t buildArtifact) getUrl(baseArchiveUrl, version string, isBeta bool) string {
|
||||
prefix := "-"
|
||||
rhelReleaseExtra := ""
|
||||
|
||||
@ -74,7 +79,7 @@ func (t buildArtifact) getUrl(version string, isBeta bool) string {
|
||||
rhelReleaseExtra = "-1"
|
||||
}
|
||||
|
||||
url := strings.Join([]string{baseArhiveUrl, prefix, version, rhelReleaseExtra, t.urlPostfix}, "")
|
||||
url := strings.Join([]string{baseArchiveUrl, prefix, version, rhelReleaseExtra, t.urlPostfix}, "")
|
||||
return url
|
||||
}
|
||||
|
||||
@ -136,18 +141,23 @@ var buildArtifactConfigurations = []buildArtifact{
|
||||
},
|
||||
}
|
||||
|
||||
func newRelease(rawVersion string, whatsNewUrl string, releaseNotesUrl string, artifactConfigurations []buildArtifact, getter urlGetter) (*release, error) {
|
||||
version := rawVersion[1:]
|
||||
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 := getter.getContents(fmt.Sprintf("%s.sha256", ba.getUrl(version, isBeta)))
|
||||
sha256, err := re.getter.getContents(fmt.Sprintf("%s.sha256", ba.getUrl(baseArchiveUrl, version, isBeta)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builds = append(builds, newBuild(ba, version, isBeta, sha256))
|
||||
builds = append(builds, newBuild(baseArchiveUrl, ba, version, isBeta, sha256))
|
||||
}
|
||||
|
||||
r := release{
|
||||
@ -163,10 +173,10 @@ func newRelease(rawVersion string, whatsNewUrl string, releaseNotesUrl string, a
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
func newBuild(ba buildArtifact, version string, isBeta bool, sha256 string) build {
|
||||
func newBuild(baseArchiveUrl string, ba buildArtifact, version string, isBeta bool, sha256 string) build {
|
||||
return build{
|
||||
Os: ba.os,
|
||||
Url: ba.getUrl(version, isBeta),
|
||||
Url: ba.getUrl(baseArchiveUrl, version, isBeta),
|
||||
Sha256: sha256,
|
||||
Arch: ba.arch,
|
||||
}
|
||||
|
@ -9,9 +9,14 @@ func TestNewRelease(t *testing.T) {
|
||||
relNotesUrl := "https://relnotes.foo/"
|
||||
expectedArch := "amd64"
|
||||
expectedOs := "linux"
|
||||
buildArtifacts := []buildArtifact{{expectedOs, expectedArch, ".linux-amd64.tar.gz"}}
|
||||
buildArtifacts := []buildArtifact{{expectedOs,expectedArch, ".linux-amd64.tar.gz"}}
|
||||
|
||||
rel, _ := newRelease(versionIn, whatsNewUrl, relNotesUrl, buildArtifacts, mockHttpGetter{})
|
||||
builder := releaseFromExternalContent{
|
||||
getter: mockHttpGetter{},
|
||||
rawVersion: versionIn,
|
||||
}
|
||||
|
||||
rel, _ := builder.prepareRelease("https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana", whatsNewUrl, relNotesUrl, buildArtifacts)
|
||||
|
||||
if !rel.Beta || rel.Stable {
|
||||
t.Errorf("%s should have been tagged as beta (not stable), but wasn't .", versionIn)
|
||||
|
Reference in New Issue
Block a user