mirror of
https://github.com/grafana/grafana.git
synced 2025-08-06 07:09:20 +08:00
CI: move grafana-build into pkg/build (#105640)
* move grafana-build into pkg/build
This commit is contained in:
45
pkg/build/daggerbuild/packages/names.go
Normal file
45
pkg/build/daggerbuild/packages/names.go
Normal file
@ -0,0 +1,45 @@
|
||||
package packages
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/build/daggerbuild/backend"
|
||||
)
|
||||
|
||||
type Name string
|
||||
|
||||
const (
|
||||
PackageGrafana Name = "grafana"
|
||||
PackageEnterprise Name = "grafana-enterprise"
|
||||
PackageEnterpriseBoring Name = "grafana-enterprise-boringcrypto"
|
||||
PackagePro Name = "grafana-pro"
|
||||
PackageNightly Name = "grafana-nightly"
|
||||
)
|
||||
|
||||
type NameOpts struct {
|
||||
// Name is the name of the product in the package. 99% of the time, this will be "grafana" or "grafana-enterprise".
|
||||
Name Name
|
||||
Version string
|
||||
BuildID string
|
||||
Distro backend.Distribution
|
||||
Extension string
|
||||
}
|
||||
|
||||
// FileName returns a file name that matches this format: {grafana|grafana-enterprise}_{version}_{os}_{arch}_{build_number}.tar.gz
|
||||
func FileName(name Name, version, buildID string, distro backend.Distribution, extension string) (string, error) {
|
||||
var (
|
||||
// This should return something like "linux", "arm"
|
||||
os, arch = backend.OSAndArch(distro)
|
||||
// If applicable this will be set to something like "7" (for arm7)
|
||||
archv = backend.ArchVersion(distro)
|
||||
)
|
||||
|
||||
if archv != "" {
|
||||
arch = strings.Join([]string{arch, archv}, "-")
|
||||
}
|
||||
|
||||
p := []string{string(name), version, buildID, os, arch}
|
||||
|
||||
return fmt.Sprintf("%s.%s", strings.Join(p, "_"), extension), nil
|
||||
}
|
71
pkg/build/daggerbuild/packages/names_test.go
Normal file
71
pkg/build/daggerbuild/packages/names_test.go
Normal file
@ -0,0 +1,71 @@
|
||||
package packages_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/build/daggerbuild/backend"
|
||||
"github.com/grafana/grafana/pkg/build/daggerbuild/packages"
|
||||
)
|
||||
|
||||
func TestFileName(t *testing.T) {
|
||||
t.Run("It should use the correct name if Enterprise is false", func(t *testing.T) {
|
||||
distro := backend.Distribution("plan9/amd64")
|
||||
opts := packages.NameOpts{
|
||||
Name: "grafana",
|
||||
Version: "v1.0.1-test",
|
||||
BuildID: "333",
|
||||
Distro: distro,
|
||||
Extension: "tar.gz",
|
||||
}
|
||||
|
||||
expected := "grafana_v1.0.1-test_333_plan9_amd64.tar.gz"
|
||||
if name, _ := packages.FileName(opts.Name, opts.Version, opts.BuildID, opts.Distro, opts.Extension); name != expected {
|
||||
t.Errorf("name '%s' does not match expected name '%s'", name, expected)
|
||||
}
|
||||
})
|
||||
t.Run("It should use the correct name if Enterprise is true", func(t *testing.T) {
|
||||
distro := backend.Distribution("plan9/amd64")
|
||||
opts := packages.NameOpts{
|
||||
Name: "grafana-enterprise",
|
||||
Version: "v1.0.1-test",
|
||||
BuildID: "333",
|
||||
Distro: distro,
|
||||
Extension: "tar.gz",
|
||||
}
|
||||
|
||||
expected := "grafana-enterprise_v1.0.1-test_333_plan9_amd64.tar.gz"
|
||||
if name, _ := packages.FileName(opts.Name, opts.Version, opts.BuildID, opts.Distro, opts.Extension); name != expected {
|
||||
t.Errorf("name '%s' does not match expected name '%s'", name, expected)
|
||||
}
|
||||
})
|
||||
t.Run("It should use include the arch version if one is supplied in the distro", func(t *testing.T) {
|
||||
distro := backend.Distribution("plan9/arm/v6")
|
||||
opts := packages.NameOpts{
|
||||
Name: "grafana-enterprise",
|
||||
Version: "v1.0.1-test",
|
||||
BuildID: "333",
|
||||
Distro: distro,
|
||||
Extension: "tar.gz",
|
||||
}
|
||||
|
||||
expected := "grafana-enterprise_v1.0.1-test_333_plan9_arm-6.tar.gz"
|
||||
if name, _ := packages.FileName(opts.Name, opts.Version, opts.BuildID, opts.Distro, opts.Extension); name != expected {
|
||||
t.Errorf("name '%s' does not match expected name '%s'", name, expected)
|
||||
}
|
||||
})
|
||||
t.Run("It should support grafana names with multiple hyphens", func(t *testing.T) {
|
||||
distro := backend.Distribution("plan9/arm/v6")
|
||||
opts := packages.NameOpts{
|
||||
Name: "grafana-enterprise-rpi",
|
||||
Version: "v1.0.1-test",
|
||||
BuildID: "333",
|
||||
Distro: distro,
|
||||
Extension: "tar.gz",
|
||||
}
|
||||
|
||||
expected := "grafana-enterprise-rpi_v1.0.1-test_333_plan9_arm-6.tar.gz"
|
||||
if name, _ := packages.FileName(opts.Name, opts.Version, opts.BuildID, opts.Distro, opts.Extension); name != expected {
|
||||
t.Errorf("name '%s' does not match expected name '%s'", name, expected)
|
||||
}
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user