mirror of
https://github.com/grafana/grafana.git
synced 2026-08-16 16:14:59 -05:00
CI: move grabpl build-frontend-packages from grabpl to grafana (#53072)
* move grabpl build-frontend-packages * add frontend and lerna packages * grabpl build-frontend-packages -> ./bin/build build-frontend-packages * move getgrafanaversion * add noinstalldeps flag * fix compiler error * fix lint error * add missing flags
This commit is contained in:
+9
-10
@@ -308,7 +308,7 @@ steps:
|
|||||||
image: grafana/build-container:1.5.9
|
image: grafana/build-container:1.5.9
|
||||||
name: build-frontend
|
name: build-frontend
|
||||||
- commands:
|
- commands:
|
||||||
- ./bin/grabpl build-frontend-packages --jobs 8 --edition oss --build-id ${DRONE_BUILD_NUMBER}
|
- ./bin/build build-frontend-packages --jobs 8 --edition oss --build-id ${DRONE_BUILD_NUMBER}
|
||||||
depends_on:
|
depends_on:
|
||||||
- yarn-install
|
- yarn-install
|
||||||
environment:
|
environment:
|
||||||
@@ -643,7 +643,7 @@ steps:
|
|||||||
image: grafana/build-container:1.5.9
|
image: grafana/build-container:1.5.9
|
||||||
name: lint-docs
|
name: lint-docs
|
||||||
- commands:
|
- commands:
|
||||||
- ./bin/grabpl build-frontend-packages --jobs 8 --edition oss --build-id ${DRONE_BUILD_NUMBER}
|
- ./bin/build build-frontend-packages --jobs 8 --edition oss --build-id ${DRONE_BUILD_NUMBER}
|
||||||
depends_on:
|
depends_on:
|
||||||
- yarn-install
|
- yarn-install
|
||||||
environment:
|
environment:
|
||||||
@@ -727,7 +727,7 @@ steps:
|
|||||||
image: grafana/build-container:1.5.9
|
image: grafana/build-container:1.5.9
|
||||||
name: lint-docs
|
name: lint-docs
|
||||||
- commands:
|
- commands:
|
||||||
- ./bin/grabpl build-frontend-packages --jobs 8 --edition oss --build-id ${DRONE_BUILD_NUMBER}
|
- ./bin/build build-frontend-packages --jobs 8 --edition oss --build-id ${DRONE_BUILD_NUMBER}
|
||||||
depends_on:
|
depends_on:
|
||||||
- yarn-install
|
- yarn-install
|
||||||
environment:
|
environment:
|
||||||
@@ -1049,7 +1049,7 @@ steps:
|
|||||||
image: grafana/build-container:1.5.9
|
image: grafana/build-container:1.5.9
|
||||||
name: build-frontend
|
name: build-frontend
|
||||||
- commands:
|
- commands:
|
||||||
- ./bin/grabpl build-frontend-packages --jobs 8 --edition oss --build-id ${DRONE_BUILD_NUMBER}
|
- ./bin/build build-frontend-packages --jobs 8 --edition oss --build-id ${DRONE_BUILD_NUMBER}
|
||||||
depends_on:
|
depends_on:
|
||||||
- yarn-install
|
- yarn-install
|
||||||
environment:
|
environment:
|
||||||
@@ -1743,7 +1743,7 @@ steps:
|
|||||||
image: grafana/build-container:1.5.9
|
image: grafana/build-container:1.5.9
|
||||||
name: build-frontend
|
name: build-frontend
|
||||||
- commands:
|
- commands:
|
||||||
- ./bin/grabpl build-frontend-packages --jobs 8 --edition oss ${DRONE_TAG}
|
- ./bin/build build-frontend-packages --jobs 8 --edition oss ${DRONE_TAG}
|
||||||
depends_on:
|
depends_on:
|
||||||
- yarn-install
|
- yarn-install
|
||||||
environment:
|
environment:
|
||||||
@@ -2367,7 +2367,7 @@ steps:
|
|||||||
image: grafana/build-container:1.5.9
|
image: grafana/build-container:1.5.9
|
||||||
name: build-frontend
|
name: build-frontend
|
||||||
- commands:
|
- commands:
|
||||||
- ./bin/grabpl build-frontend-packages --jobs 8 --edition enterprise ${DRONE_TAG}
|
- ./bin/build build-frontend-packages --jobs 8 --edition enterprise ${DRONE_TAG}
|
||||||
depends_on:
|
depends_on:
|
||||||
- yarn-install
|
- yarn-install
|
||||||
environment:
|
environment:
|
||||||
@@ -3712,7 +3712,7 @@ steps:
|
|||||||
image: grafana/build-container:1.5.9
|
image: grafana/build-container:1.5.9
|
||||||
name: build-frontend
|
name: build-frontend
|
||||||
- commands:
|
- commands:
|
||||||
- ./bin/grabpl build-frontend-packages --jobs 8 --edition oss --build-id ${DRONE_BUILD_NUMBER}
|
- ./bin/build build-frontend-packages --jobs 8 --edition oss --build-id ${DRONE_BUILD_NUMBER}
|
||||||
depends_on:
|
depends_on:
|
||||||
- yarn-install
|
- yarn-install
|
||||||
environment:
|
environment:
|
||||||
@@ -4282,8 +4282,7 @@ steps:
|
|||||||
image: grafana/build-container:1.5.9
|
image: grafana/build-container:1.5.9
|
||||||
name: build-frontend
|
name: build-frontend
|
||||||
- commands:
|
- commands:
|
||||||
- ./bin/grabpl build-frontend-packages --jobs 8 --edition enterprise --build-id
|
- ./bin/build build-frontend-packages --jobs 8 --edition enterprise --build-id ${DRONE_BUILD_NUMBER}
|
||||||
${DRONE_BUILD_NUMBER}
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- yarn-install
|
- yarn-install
|
||||||
environment:
|
environment:
|
||||||
@@ -5093,6 +5092,6 @@ kind: secret
|
|||||||
name: packages_secret_access_key
|
name: packages_secret_access_key
|
||||||
---
|
---
|
||||||
kind: signature
|
kind: signature
|
||||||
hmac: fb770c3cc5bd204e3aceae01d35997818ee210efb54c8ccbe37a410773f1ce73
|
hmac: 2689da88c9d55f8949f4f9a26a850661fdec1ecf8f5da5c3713bde4ca481b8dd
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/build/errutil"
|
||||||
|
"github.com/grafana/grafana/pkg/build/frontend"
|
||||||
|
"github.com/grafana/grafana/pkg/build/syncutil"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BuildFrontendPackages(c *cli.Context) error {
|
||||||
|
version := ""
|
||||||
|
if c.NArg() == 1 {
|
||||||
|
version = strings.TrimPrefix(c.Args().Get(0), "v")
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg, mode, err := frontend.GetConfig(c, version)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
p := syncutil.NewWorkerPool(cfg.NumWorkers)
|
||||||
|
defer p.Close()
|
||||||
|
|
||||||
|
g, _ := errutil.GroupWithContext(c.Context)
|
||||||
|
if err := frontend.BuildFrontendPackages(cfg.PackageVersion, mode, frontend.GrafanaDir, p, g); err != nil {
|
||||||
|
return cli.Exit(err.Error(), 1)
|
||||||
|
}
|
||||||
|
if err := g.Wait(); err != nil {
|
||||||
|
return cli.Exit(err.Error(), 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("Successfully built Grafana front-end packages!")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -25,6 +25,18 @@ func main() {
|
|||||||
&buildIDFlag,
|
&buildIDFlag,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "build-frontend-packages",
|
||||||
|
Usage: "Build front-end packages",
|
||||||
|
ArgsUsage: "[version]",
|
||||||
|
Action: BuildFrontendPackages,
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&jobsFlag,
|
||||||
|
&editionFlag,
|
||||||
|
&buildIDFlag,
|
||||||
|
&noInstallDepsFlag,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "e2e-tests",
|
Name: "e2e-tests",
|
||||||
Usage: "Run Grafana e2e tests",
|
Usage: "Run Grafana e2e tests",
|
||||||
|
|||||||
@@ -100,15 +100,6 @@ func GetVersion(mode VersionMode) (*Version, error) {
|
|||||||
return nil, fmt.Errorf("mode '%s' not found in version list", mode)
|
return nil, fmt.Errorf("mode '%s' not found in version list", mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func shortenBuildID(buildID string) string {
|
|
||||||
buildID = strings.ReplaceAll(buildID, "-", "")
|
|
||||||
if len(buildID) < 9 {
|
|
||||||
return buildID
|
|
||||||
}
|
|
||||||
|
|
||||||
return buildID[0:8]
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetGrafanaVersion gets the Grafana version from the package.json
|
// GetGrafanaVersion gets the Grafana version from the package.json
|
||||||
func GetGrafanaVersion(buildID, grafanaDir string) (string, error) {
|
func GetGrafanaVersion(buildID, grafanaDir string) (string, error) {
|
||||||
pkgJSONPath := filepath.Join(grafanaDir, "package.json")
|
pkgJSONPath := filepath.Join(grafanaDir, "package.json")
|
||||||
@@ -184,3 +175,12 @@ func GetDroneCommit() (string, error) {
|
|||||||
}
|
}
|
||||||
return commit, nil
|
return commit, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func shortenBuildID(buildID string) string {
|
||||||
|
buildID = strings.ReplaceAll(buildID, "-", "")
|
||||||
|
if len(buildID) < 9 {
|
||||||
|
return buildID
|
||||||
|
}
|
||||||
|
|
||||||
|
return buildID[0:8]
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,9 +9,23 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/build/config"
|
"github.com/grafana/grafana/pkg/build/config"
|
||||||
"github.com/grafana/grafana/pkg/build/errutil"
|
"github.com/grafana/grafana/pkg/build/errutil"
|
||||||
|
"github.com/grafana/grafana/pkg/build/lerna"
|
||||||
"github.com/grafana/grafana/pkg/build/syncutil"
|
"github.com/grafana/grafana/pkg/build/syncutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func BuildFrontendPackages(version string, edition config.Edition, grafanaDir string, p syncutil.WorkerPool, g *errutil.Group) error {
|
||||||
|
p.Schedule(g.Wrap(func() error {
|
||||||
|
if err := lerna.BuildFrontendPackages(version, edition, grafanaDir); err != nil {
|
||||||
|
return fmt.Errorf("failed to build %s frontend packages: %v", edition, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Finished building %s frontend packages", string(edition))
|
||||||
|
return nil
|
||||||
|
}))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Build builds the Grafana front-end
|
// Build builds the Grafana front-end
|
||||||
func Build(edition config.Edition, grafanaDir string, p syncutil.WorkerPool, g *errutil.Group) error {
|
func Build(edition config.Edition, grafanaDir string, p syncutil.WorkerPool, g *errutil.Group) error {
|
||||||
log.Printf("Building %s frontend in %q", edition, grafanaDir)
|
log.Printf("Building %s frontend in %q", edition, grafanaDir)
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package lerna
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/build/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BuildFrontendPackages will bump the version for the package to the latest canary build
|
||||||
|
// and build the packages so they are ready for being published, used for generating docs etc.
|
||||||
|
func BuildFrontendPackages(version string, mode config.Edition, grafanaDir string) error {
|
||||||
|
err := bumpLernaVersion(version, grafanaDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cmd := exec.Command("yarn", "run", "packages:build")
|
||||||
|
cmd.Dir = grafanaDir
|
||||||
|
if output, err := cmd.CombinedOutput(); err != nil {
|
||||||
|
return fmt.Errorf("failed to build %s frontend packages: %s", mode, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func bumpLernaVersion(version string, grafanaDir string) error {
|
||||||
|
//nolint:gosec
|
||||||
|
cmd := exec.Command("yarn", "run", "lerna", "version", version, "--exact", "--no-git-tag-version", "--no-push", "--force-publish", "-y")
|
||||||
|
cmd.Dir = grafanaDir
|
||||||
|
if output, err := cmd.CombinedOutput(); err != nil {
|
||||||
|
return fmt.Errorf("failed to bump version for frontend packages: %s\n%s", err, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetLernaVersion(grafanaDir string) (string, error) {
|
||||||
|
lernaJSONPath := filepath.Join(grafanaDir, "lerna.json")
|
||||||
|
//nolint:gosec
|
||||||
|
lernaJSONB, err := os.ReadFile(lernaJSONPath)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to read %q: %w", lernaJSONPath, err)
|
||||||
|
}
|
||||||
|
pkgObj := map[string]interface{}{}
|
||||||
|
if err := json.Unmarshal(lernaJSONB, &pkgObj); err != nil {
|
||||||
|
return "", fmt.Errorf("failed decoding %q: %w", lernaJSONPath, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
version := pkgObj["version"].(string)
|
||||||
|
if version == "" {
|
||||||
|
return "", fmt.Errorf("failed to read version from %q", lernaJSONPath)
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(version), nil
|
||||||
|
}
|
||||||
@@ -415,12 +415,12 @@ def build_frontend_package_step(edition, ver_mode):
|
|||||||
# TODO: Use percentage for num jobs
|
# TODO: Use percentage for num jobs
|
||||||
if ver_mode == 'release':
|
if ver_mode == 'release':
|
||||||
cmds = [
|
cmds = [
|
||||||
'./bin/grabpl build-frontend-packages --jobs 8 ' + \
|
'./bin/build build-frontend-packages --jobs 8 ' + \
|
||||||
'--edition {} ${{DRONE_TAG}}'.format(edition),
|
'--edition {} ${{DRONE_TAG}}'.format(edition),
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
cmds = [
|
cmds = [
|
||||||
'./bin/grabpl build-frontend-packages --jobs 8 --edition {} '.format(edition) + \
|
'./bin/build build-frontend-packages --jobs 8 --edition {} '.format(edition) + \
|
||||||
'--build-id {}'.format(build_no),
|
'--build-id {}'.format(build_no),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user