Commit 84832cb6 by Leonard Gram

build: releaser supports releasing only some artifacts.

parent 87707c96
......@@ -359,6 +359,9 @@ jobs:
- run:
name: deploy to gcp
command: '/opt/google-cloud-sdk/bin/gsutil cp ./enterprise-dist/* gs://$GCP_BUCKET_NAME/enterprise/release'
- run:
name: Deploy to Grafana.com
command: './scripts/build/publish.sh --enterprise'
deploy-master:
docker:
......
......@@ -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}
......@@ -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: "rpm", arch: "amd64"},
{os: "linux", arch: "amd64"},
{os: "windows", 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",
......
......@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/pkg/errors"
"io/ioutil"
"log"
"net/http"
......@@ -103,7 +104,7 @@ func (t buildArtifact) getUrl(baseArchiveUrl, version string, releaseType Releas
return url
}
var buildArtifactConfigurations = []buildArtifact{
var completeBuildArtifactConfigurations = []buildArtifact{
{
os: "deb",
arch: "arm64",
......@@ -161,6 +162,31 @@ var buildArtifactConfigurations = []buildArtifact{
},
}
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,
......
......@@ -115,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)
......@@ -176,3 +176,27 @@ func TestPreparingReleaseFromLocal(t *testing.T) {
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.")
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment