CI: Add artifacts npm commands from grabpl (#61908)

This commit is contained in:
Horst Gutmann
2023-01-23 11:32:51 +01:00
committed by GitHub
parent 0be920e61c
commit e32cd6d4ff
8 changed files with 645 additions and 13 deletions
+28
View File
@@ -1,6 +1,7 @@
package lerna
import (
"context"
"encoding/json"
"fmt"
"os"
@@ -9,6 +10,7 @@ import (
"strings"
"github.com/grafana/grafana/pkg/build/config"
"github.com/grafana/grafana/pkg/build/fsutil"
)
// BuildFrontendPackages will bump the version for the package to the latest canary build
@@ -56,3 +58,29 @@ func GetLernaVersion(grafanaDir string) (string, error) {
}
return strings.TrimSpace(version), nil
}
func PackFrontendPackages(ctx context.Context, tag, grafanaDir, artifactsDir string) error {
exists, err := fsutil.Exists(artifactsDir)
if err != nil {
return err
}
if exists {
err = os.RemoveAll(artifactsDir)
if err != nil {
return err
}
}
// nolint:gosec
if err = os.MkdirAll(artifactsDir, 0755); err != nil {
return err
}
// nolint:gosec
cmd := exec.CommandContext(ctx, "yarn", "lerna", "exec", "--no-private", "--", "yarn", "pack", "--out", fmt.Sprintf("../../npm-artifacts/%%s-%v.tgz", tag))
cmd.Dir = grafanaDir
if output, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("command '%s' failed to run, output: %s, err: %q", cmd.String(), output, err)
}
return nil
}