CI Migration: Backport pkg/build (daggerbuild) and GHAs to release-12.0.3 (#107997)

* CI: move grafana-build into pkg/build (#105640)

* move grafana-build into pkg/build

* Update go.mod/go.sum files after cherry-pick build

- Updates from workspace sync after cherry-picking daggerbuild package
- Resolves dependency conflicts from pkg/build integration
- Required for successful build after CI migration backport

* CI Migration: Replace .github with main branch version

- Complete replacement of .github directory from main branch
- Includes updated workflows, actions, and configuration files
- Ensures all CI improvements from main are included
- Next step: fix branch-specific issues in separate commits

* Fix branch triggers: Update workflows to target release branches

- Update 8 workflows to trigger on release-* instead of main
- Ensures workflows run on pull requests to release branches
- Workflows updated: documentation-ci, pr-codeql-analysis-*, pr-dependabot-update-go-workspace, pr-go-workspace-check, pr-k8s-codegen-check, verify-kinds, codeowners-validator

* Fix branch triggers: Update workflows to target both main and release branches

- CORRECTED: Include both main and release-* branch patterns
- Ensures workflows run on both main branch (original functionality) and release branches (needed for backport)
- Previous commit incorrectly removed main branch support
- Workflows updated: documentation-ci, pr-codeql-analysis-*, pr-dependabot-update-go-workspace, pr-go-workspace-check, pr-k8s-codegen-check, verify-kinds, codeowners-validator

* CI Migration: Update .gitignore to allow OSS wire file to be committed

- Remove **/wire_gen.go (allow pkg/server/wire_gen.go to be committed)
- Add /pkg/server/enterprise_wire_gen.go (keep enterprise wire file ignored)
- This enables the new committed wire files architecture for CI

* CI Migration: Add enhanced wire tool with automatic build constraints

- Backport enhanced wire tool from main branch with -gen_tags flag
- This enables automatic regeneration with proper constraints to prevent conflicts
- Wire file contains all required functions: Initialize, InitializeDocumentBuilders, etc.
- Solves the missing wire functions issue causing CI failures
- Enhanced tool ensures build constraints persist on regeneration

* CI Migration: Update Makefile to use enhanced wire tool with build constraints

- Update gen-go target to use -gen_tags flag for automatic build constraints
- Ensures future engineers get proper build constraints when running 'make gen-go'
- Matches main branch approach for consistent wire file generation
- Removes dependency on WIRE_TAGS variable and GO_RACE_FLAG for simplicity

* Add gen-enterprise-go target to Makefile for release-12.0.3

- Backports gen-enterprise-go target from main branch
- Enables enterprise wire file generation in release branches
- Part of CI migration backport wire infrastructure fixes
- Resolves CI issues where enterprise wire functions were missing

* Fix wire tool golden file format for Drone CI compatibility

- Update all 43 golden test files to match main branch format
- Change go:generate command from github.com/google/wire/cmd/wire to ./pkg/build/wire/cmd/wire/main.go
- Remove legacy '// +build !wireinject' constraints
- Fixes Drone CI test failures that were blocking OSS PR merge
- All wire tests now pass successfully

This aligns the backport branch with the golden file format updates
that were made in main branch when the wire tool was enhanced.

* Update swagger specs to include enterprise APIs

- Regenerated api-enterprise-spec.json with enterprise API definitions
- Updated api-merged.json with merged OSS and enterprise specs
- Regenerated openapi3.json with complete API specifications
- Fixes enterprise CI swagger generation validation failures
- Enterprise APIs now properly detected and documented

* Fix OSS integration tests missing enterprise build tags in Drone CI

- Add -tags=enterprise to all integration test steps in lib.star
- Fixes test-backend-integration, postgres-integration-tests, and mysql-integration-tests
- Regenerate .drone.yml with proper enterprise build tags
- Resolves 'server could not find the requested resource' errors for enterprise APIs
- Ensures enterprise APIs (querylibrary, reporting, banners, scim) are registered during tests
- Aligns OSS Drone CI with GitHub Actions behavior and enterprise repository

* Fix CODEOWNERS for release-12.0.3 compatibility

- Remove 21 entries that reference files/directories not present in release branch
- Resolves File Exist Checker failures in codeowners-validator workflow
- Maintains team ownership assignments from main branch for existing files
- Lines removed: .air.toml, apps/secret/, apps/iam/, e2e-playwright/, packages/grafana-alerting/, etc.

* baldm0mma/ update releasefinder

* Add i18n-extract script for release branch compatibility

- Add 'i18n-extract': 'make i18n-extract' to package.json scripts
- Resolves i18n-verify workflow failure that expects this script
- The make target already exists and handles OSS + enterprise i18n extraction
- Maintains i18n verification functionality from main branch workflows
- Simple safe addition that calls existing make infrastructure

* Phase 4: Fix GitHub Actions workflow branch triggers

- Add release-*.*.* pattern to 8 workflows missing it
- Fix duplicate release branch patterns in 3 workflows
- Ensure consistent branch trigger format across all workflows
- Critical workflows now properly trigger on release branches

Fixes workflows: actionlint, backend-code-checks, go-lint, reject-gh-secrets,
run-schema-v2-e2e, shellcheck, swagger-gen, trivy-scan

* Fix: Backport E2E runner infrastructure for Enterprise CI

- Add e2e/main.go and e2e/internal/ directory from main branch
- Add urfave/cli/v3 dependency required by E2E runner
- Fixes Enterprise CI failure: 'Build E2E test runner' and 'Build & package Grafana for e2e tests'
- Root cause: E2E runner infrastructure was added to main after release-12.0.3 branch creation
- Solution: Backport missing E2E runner files to enable Enterprise CI completion

Resolves: no Go files in /opt/actions-runner/_work/grafana-enterprise/grafana-enterprise/grafana/e2e

* Fix: Update go.mod dependency classification for urfave/cli/v3

- Change urfave/cli/v3 from indirect to direct dependency
- Fixes Go Workspace Check failure in CI
- Required after adding E2E runner infrastructure that directly imports urfave/cli/v3
- Resolves: make update-workspace corrects dependency classification

* Fix: Add team ownership for urfave/cli/v3 dependency

- Assign @grafana/grafana-backend-group as owner for github.com/urfave/cli/v3@v3.3.8
- Follows existing pattern: urfave/cli v1 and v2 also owned by grafana-backend-group
- Resolves Backend Code Checks / Validate Backend Configs CI failure
- Required for E2E runner infrastructure dependency ownership compliance

Fixes: modowners check requiring team assignment for newly added dependencies

* Fix: Revert experimental E2E playwright infrastructure to stable version

- Revert pr-e2e-tests.yml to stable Cypress-based E2E testing
- Remove experimental storybook-verification-playwright.yml workflow
- Revert run-dashboard-search-e2e.yml and release-pr.yml to use e2e/test-plugins/
- Keep stable E2E runner infrastructure (e2e/main.go + e2e/internal/)
- Remove experimental playwright features per team recommendation

Team feedback: Playwright tests are experimental and shouldn't be backported to stable release branches

* Fix: Complete cleanup of experimental playwright dependencies

- Revert package.json to stable version (remove e2e-playwright scripts and path references)
- Revert playwright.config.ts to stable plugin-e2e configuration
- Remove all experimental playwright infrastructure dependencies
- Ensure clean stable E2E testing environment

All experimental features removed per team recommendation for stable release branches

* Fix: Restore working package.json configuration

- Revert package.json to version 12.0.3 (working release branch version)
- Fix workspace dependency resolution issues caused by incorrect revert to main branch version
- FE tests, betterer, and linting should now work correctly

Issue was caused by reverting package.json to main branch (12.1.0-pre) instead of keeping
the working release branch configuration (12.0.3)

* CI: mirror some CI dependencies (#106148)

* mirror some CI dependencies
* remove -v from go build

* Fix: Backport missing e2e/run-suite script for daggerbuild E2E system

The daggerbuild E2E system (used by OSS workflows) expects ./e2e/run-suite
to exist, but we only backported the new E2E runner infrastructure.

This script is needed for:
- OSS workflow: 'go run ./pkg/build/e2e --suite=dashboards-suite'
- Legacy Cypress configuration with video support
- Integration between daggerbuild and existing Cypress test suites

Resolves E2E test failures in OSS workflows where videos directory
cannot be found because run-suite script was missing.

* Fix: Resolve daggerbuild E2E path doubling issue

- Extract just suite name from full path using filepath.Base()
- Prevents doubled paths like './e2e/e2e/dashboards-suite/videos'
- Resolves 'no spec files found' and 'no such file or directory' errors
- GitHub Actions passes full paths like 'e2e/dashboards-suite' but run-suite script expects just 'dashboards-suite'

* Infrastructure: Wholesale copy pkg/build/ from main

COMPLETE DAGGERBUILD SYSTEM UPDATE:
- Modern E2E system with CLI framework and --flags support
- New accessibility testing system (a11y/)
- New Playwright E2E testing system (e2e-playwright/)
- External infrastructure improvements (musl.cc → dl.grafana.com/ci)
- Updated daggerbuild core components with latest fixes
- Updated Go dependencies and wire modules

ARCHITECTURAL COMPATIBILITY VERIFIED:
- Modern pkg/build calls: ./e2e-runner cypress --start-grafana=false --cypress-video
- Our e2e runner supports: All required parameters including --suite, --env flags
- GitHub Actions workflows: Pass compatible arguments
- Binary builds: Successfully creates working e2e-runner

RESOLVES ISSUES:
- Fixes --flags parameter compatibility with GitHub Actions
- Includes all follow-up infrastructure improvements
- Provides complete, tested system with modern CLI framework
- Eliminates external dependency failures (musl.cc timeouts)
- Removes need for path doubling workarounds (modern system handles full paths correctly)

Replaces incremental cherry-picking with complete, tested system from main.

* Dependencies: Update Go modules after pkg/build wholesale copy

DEPENDENCY UPDATES:
- Updated go.work.sum with new dependencies from modern pkg/build system
- Updated all workspace module dependencies (go.mod/go.sum files)
- Removed pkg/build/cmd/enterprise.go (enterprise-only file, gets copied during enterprise development)

ENTERPRISE INTEGRATION FIX:
- enterprise.go file doesn't belong in OSS repository
- Gets copied from grafana-enterprise during development mode
- Main branch doesn't have this file, explaining module compatibility

All Go modules now properly resolved and compatible with modern pkg/build architecture.

* Dependencies: Update workspace Go module checksums after pkg/build wholesale copy

- Synchronizes all go.sum files across workspace modules
- Adds missing .mod.h1 entries that were required after infrastructure update
- Resolves Go Workspace Check CI failures
- Updates 22 modules: .citools/, apps/, pkg/ subdirectories plus go.work.sum

Addresses CI error: 'Please run make update-workspace and commit the changes'

* Infrastructure: Revert to pre-Playwright E2E system for release branch compatibility

Strategic combination of modern daggerbuild with stable E2E infrastructure:

**Modern Daggerbuild (from main):**
- Latest CLI framework (github.com/urfave/cli/v3)
- External infrastructure fixes (musl.cc → dl.grafana.com/ci)
- Complete pkg/build/ system with all enhancements
- Updated dependencies and architecture improvements

**Stable E2E Infrastructure (pre-Playwright):**
- pkg/build/e2e/service.go: Reverted to version before commit b6580ccb10
- pkg/build/a11y/: Reverted to stable version compatible with existing infrastructure
- Removed experimental pkg/build/e2e-playwright/ system
- Removed experimental e2e-playwright/ test infrastructure

**Why This Approach:**
- GitHub Actions workflows call 'go run ./pkg/build/e2e' (modern system)
- Modern system now expects only standard e2e/ directory (compatible)
- Release branches have standard e2e/ infrastructure (dashboards-suite, various-suite, etc.)
- Eliminates dependency on experimental Playwright infrastructure

**Key Dependencies Met:**
- e2e/pa11yci.conf.js: Added for a11y test compatibility
- /src/e2e directory: Standard directory structure (no e2e-playwright needed)
- Existing test plugins: Uses stable e2e/test-plugins/

**Result:**
Best of both worlds - modern, reliable daggerbuild infrastructure with
proven E2E testing that works across all release branches without
requiring experimental dependencies.

* Fix: Remove unused embed.go file causing golangci-lint failure

- Removes pkg/build/daggerbuild/msi/embed.go with unused embed.FS variable
- MSI build process uses directory mounting instead of embedded filesystem
- Resolves 'var resources is unused (unused)' linting error

* Fix: Update Node.js version to match working E2E configuration

- Changes from v22.11.0 to v22.16.0 to match commit 17952d45e4
- Working commit had all E2E tests passing with same daggerbuild infrastructure
- Node.js version differences can affect frontend builds and UI rendering
- Ensures consistent environment between working reference and current branch

* Fix: Use conditional container base for E2E compatibility

- Alpine for OSS tests (better old arch dashboardScene=false compatibility)
- Ubuntu for Enterprise tests (when image renderer needed)
- Restores original release-12.0.3 Alpine behavior for OSS
- Should resolve old arch E2E test failures

* Fix: Go fmt formatting for conditional container logic

* Revert: Remove unnecessary Alpine/Ubuntu conditional logic

- Real issue was wrong environment variable name (dashboardScene vs DISABLE_SCENES)
- Keep Ubuntu base (original main branch behavior) for simplicity
- Container base was not the root cause of old arch failures

* Experiment: Copy scripts/ from pre-Playwright commit (ea0ddb3fc9)

- Copied scripts directory from commit ea0ddb3fc9 (just before Playwright migration)
- This overwrites some CI migration fixes but testing if it's actually needed
- Can revert back to b9b4602dbd if CI breaks

Test commit to see real impact on GitHub Actions workflows.

* trigger ci 01

* Fix: Copy .drone.star from main to match scripts structure

- Resolves Starlark evaluation error for missing integration_test_pipelines
- Aligns .drone.star with main branch scripts structure
- Same fix applied to both OSS and Enterprise repositories

* make drone

* Fix ARM/v7 Docker build failures by using dagger run for cross-compilation

- Change artifacts_cmd() in scripts/drone/steps/rgm.star to use 'dagger run go run' instead of 'go run'
- Add --max-execution-steps 100000 to make drone target in Makefile to properly regenerate .drone.yml
- This fixes CGO cross-compilation issues with SQLite for ARM/v7 Docker builds
- Matches the approach already used successfully in Enterprise builds

* Fix Docker base image references in rgm build steps

- Change from symbolic names (alpine-base, ubuntu-base) to actual Docker images
- alpine-base → alpine:3.21.3
- ubuntu-base → ubuntu:22.04
- Add ubuntu and alpine parameters to rgm_artifacts_step and rgm_build_docker_step functions
- Fixes Docker pull errors: 'repository does not exist or may require authorization'
- Aligns OSS configuration with Enterprise approach

---------

Co-authored-by: Kevin Minehart <5140827+kminehart@users.noreply.github.com>
This commit is contained in:
Jev Forsberg
2025-07-18 09:14:14 -06:00
committed by GitHub
co-authored by Kevin Minehart
parent aee6b20c7f
commit dc6bd2a20a
432 changed files with 24660 additions and 16787 deletions
+135
View File
@@ -0,0 +1,135 @@
package a11y
import (
"context"
"fmt"
"io"
"os"
"os/exec"
"path"
"github.com/grafana/grafana/e2e/internal/fpaths"
"github.com/grafana/grafana/e2e/internal/outs"
"github.com/urfave/cli/v3"
)
func NewCmd() *cli.Command {
return &cli.Command{
Name: "a11y",
Usage: "Run accessibility tests on the Grafana frontend",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Usage: "Path to the accessibility test configuration file",
Required: true,
TakesFile: true,
},
&cli.BoolFlag{
Name: "json",
Usage: "Output results in JSON format",
Value: false,
},
&cli.StringFlag{
Name: "grafana-host",
Usage: "Host for the Grafana server",
Value: "localhost",
},
&cli.Uint16Flag{
Name: "grafana-port",
Usage: "Port for the Grafana server",
Value: 3001,
},
&cli.BoolFlag{
Name: "start-grafana",
Usage: "Start and wait for Grafana before running the tests",
Value: true,
Category: "Grafana Server",
},
&cli.StringFlag{
Name: "license-path",
Usage: "Path to the Grafana Enterprise license file (optional; requires --start-grafana)",
Value: "",
TakesFile: true,
Category: "Grafana Server",
},
},
Action: runAction,
}
}
func runAction(ctx context.Context, c *cli.Command) error {
cfgPath, err := fpaths.NormalisePath(c.String("config"))
if err != nil {
return fmt.Errorf("failed to normalise config path %q: %w", c.String("config"), err)
}
repoRoot, err := fpaths.RepoRoot(ctx, ".")
if err != nil {
return fmt.Errorf("failed to get repository root: %w", err)
}
ctx, cancel := context.WithCancel(ctx)
defer cancel()
if c.Bool("start-grafana") {
startServerPath := path.Join(repoRoot, "scripts", "grafana-server", "start-server")
waitForGrafanaPath := path.Join(repoRoot, "scripts", "grafana-server", "wait-for-grafana")
go func() {
defer cancel()
var args []string
if c.String("license-path") != "" {
args = append(args, c.String("license-path"))
}
//nolint:gosec
cmd := exec.CommandContext(ctx, startServerPath, args...)
cmd.Dir = repoRoot
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, fmt.Sprintf("TZ=%s", c.String("timezone")))
cmd.Stdout = prefixGrafana(os.Stdout)
cmd.Stderr = prefixGrafana(os.Stderr)
cmd.Stdin = nil
if err := cmd.Run(); err != nil {
fmt.Println("Error running Grafana:", err)
}
}()
//nolint:gosec
cmd := exec.CommandContext(ctx, waitForGrafanaPath)
cmd.Dir = repoRoot
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, fmt.Sprintf("TZ=%s", c.String("timezone")))
cmd.Stdout = prefixGrafana(os.Stdout)
cmd.Stderr = prefixGrafana(os.Stderr)
cmd.Stdin = nil
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to wait for Grafana: %w", err)
}
}
args := []string{"run", "pa11y-ci", "--config", cfgPath}
if c.Bool("json") {
args = append(args, "--json")
}
//nolint:gosec
cmd := exec.CommandContext(ctx, "yarn", args...)
cmd.Dir = repoRoot
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env,
fmt.Sprintf("HOST=%s", c.String("grafana-host")),
fmt.Sprintf("PORT=%d", c.Uint16("grafana-port")))
cmd.Stdout = prefixA11y(os.Stdout)
cmd.Stderr = prefixA11y(os.Stderr)
cmd.Stdin = os.Stdin
return cmd.Run()
}
func prefixA11y(w io.Writer) io.Writer {
return outs.Prefix(w, "A11y", outs.CyanColor)
}
func prefixGrafana(w io.Writer) io.Writer {
return outs.Prefix(w, "Grafana", outs.YellowColor)
}
+251
View File
@@ -0,0 +1,251 @@
package cypress
import (
"context"
"fmt"
"io"
"os"
"os/exec"
"path"
"regexp"
"strings"
"time"
"github.com/grafana/grafana/e2e/internal/fpaths"
"github.com/grafana/grafana/e2e/internal/outs"
"github.com/urfave/cli/v3"
)
func NewCmd() *cli.Command {
return &cli.Command{
Name: "cypress",
Usage: "Run a Cypress test suite",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "command",
Usage: "Cypress command to run. 'open' can be useful for development (enum: run, open)",
Value: "run",
Validator: func(s string) error {
if s != "run" && s != "open" {
return fmt.Errorf("invalid command: %s, must be 'run' or 'open'", s)
}
return nil
},
},
&cli.StringFlag{
Name: "browser",
Usage: "Browser to run tests with (e.g.: chrome, electron)",
Value: "chrome",
},
&cli.StringFlag{
Name: "grafana-base-url",
Usage: "Base URL for Grafana",
Value: "http://localhost:3001",
},
&cli.BoolFlag{
Name: "cypress-video",
Usage: "Enable Cypress video recordings",
Value: false,
},
&cli.BoolFlag{
Name: "smtp-plugin",
Usage: "Enable SMTP plugin",
Value: false,
},
&cli.BoolFlag{
Name: "benchmark-plugin",
Usage: "Enable Benchmark plugin",
Value: false,
},
&cli.BoolFlag{
Name: "slowmo",
Usage: "Slow down the test run",
Value: false,
},
&cli.StringSliceFlag{
Name: "env",
Usage: "Additional Cypress environment variables to set (format: KEY=VALUE)",
Validator: func(s []string) error {
pattern := regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_]*=.*`)
for _, v := range s {
if !pattern.MatchString(v) {
return fmt.Errorf("invalid environment variable format: %s, must be KEY=VALUE", v)
}
}
return nil
},
},
&cli.StringSliceFlag{
Name: "parameters",
Usage: "Additional parameters to pass to the Cypress command (e.g. --headed)",
},
&cli.DurationFlag{
Name: "timeout",
Usage: "Timeout for the Cypress command (precision: milliseconds)",
Value: time.Second * 30,
Validator: func(d time.Duration) error {
if d < 0 {
return fmt.Errorf("timeout must be a positive duration")
}
if d.Round(time.Millisecond) != d {
return fmt.Errorf("timeout must be a whole number of milliseconds")
}
return nil
},
},
&cli.BoolFlag{
Name: "start-grafana",
Usage: "Start and wait for Grafana before running the tests",
Value: true,
Category: "Grafana Server",
},
&cli.StringFlag{
Name: "license-path",
Usage: "Path to the Grafana Enterprise license file (optional; requires --start-grafana)",
Value: "",
TakesFile: true,
Category: "Grafana Server",
},
&cli.BoolFlag{
Name: "image-renderer",
Usage: "Install the image renderer plugin (requires --start-grafana)",
Category: "Grafana Server",
},
&cli.StringFlag{
Name: "suite",
Usage: "Path to the suite to run (e.g. './e2e/dashboards-suite')",
TakesFile: true,
Required: true,
},
},
Action: runAction,
}
}
func runAction(ctx context.Context, c *cli.Command) error {
suitePath := c.String("suite")
suitePath, err := fpaths.NormalisePath(suitePath)
if err != nil {
return fmt.Errorf("failed to normalise suite path: %w", err)
}
repoRoot, err := fpaths.RepoRoot(ctx, suitePath)
if err != nil {
return fmt.Errorf("failed to get git repo root: %w", err)
}
screenshotsFolder := path.Join(suitePath, "screenshots")
videosFolder := path.Join(suitePath, "videos")
fileServerFolder := path.Join(repoRoot, "e2e", "cypress")
fixturesFolder := path.Join(fileServerFolder, "fixtures")
downloadsFolder := path.Join(fileServerFolder, "downloads")
benchmarkPluginResultsFolder := path.Join(suitePath, "benchmark-results")
reporter := path.Join(repoRoot, "e2e", "log-reporter.js")
env := map[string]string{
"BENCHMARK_PLUGIN_ENABLED": fmt.Sprintf("%t", c.Bool("benchmark-plugin")),
"SMTP_PLUGIN_ENABLED": fmt.Sprintf("%t", c.Bool("smtp-plugin")),
"BENCHMARK_PLUGIN_RESULTS_FOLDER": benchmarkPluginResultsFolder,
"SLOWMO": "0",
"BASE_URL": c.String("grafana-base-url"),
}
for _, v := range c.StringSlice("env") {
parts := strings.SplitN(v, "=", 2)
if len(parts) != 2 {
return fmt.Errorf("invalid environment variable format: %s, must be KEY=VALUE", v)
}
env[parts[0]] = parts[1]
}
cypressConfig := map[string]string{
"screenshotsFolder": screenshotsFolder,
"fixturesFolder": fixturesFolder,
"videosFolder": videosFolder,
"downloadsFolder": downloadsFolder,
"fileServerFolder": fileServerFolder,
"reporter": reporter,
"specPattern": path.Join(suitePath, "*.spec.ts"),
"defaultCommandTimeout": fmt.Sprintf("%d", c.Duration("timeout").Milliseconds()),
"viewportWidth": "1920",
"viewportHeight": "1080",
"trashAssetsBeforeRuns": "false",
"baseUrl": c.String("grafana-base-url"),
"video": fmt.Sprintf("%t", c.Bool("cypress-video")),
}
ctx, cancel := context.WithCancel(ctx)
defer cancel()
if c.Bool("start-grafana") {
startServerPath := path.Join(repoRoot, "scripts", "grafana-server", "start-server")
waitForGrafanaPath := path.Join(repoRoot, "scripts", "grafana-server", "wait-for-grafana")
go func() {
defer cancel()
var args []string
if c.String("license-path") != "" {
args = append(args, c.String("license-path"))
}
//nolint:gosec
cmd := exec.CommandContext(ctx, startServerPath, args...)
cmd.Dir = repoRoot
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, fmt.Sprintf("TZ=%s", c.String("timezone")))
if c.Bool("image-renderer") {
cmd.Env = append(cmd.Env, "INSTALL_IMAGE_RENDERER=true")
}
cmd.Stdout = prefixGrafana(os.Stdout)
cmd.Stderr = prefixGrafana(os.Stderr)
cmd.Stdin = nil
if err := cmd.Run(); err != nil {
fmt.Println("Error running Grafana:", err)
}
}()
//nolint:gosec
cmd := exec.CommandContext(ctx, waitForGrafanaPath)
cmd.Dir = repoRoot
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, fmt.Sprintf("TZ=%s", c.String("timezone")))
cmd.Stdout = prefixGrafana(os.Stdout)
cmd.Stderr = prefixGrafana(os.Stderr)
cmd.Stdin = nil
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to wait for Grafana: %w", err)
}
}
args := []string{"run", "cypress", c.String("command"),
"--env", joinCypressCfg(env),
"--config", joinCypressCfg(cypressConfig),
"--browser", c.String("browser")}
args = append(args, c.StringSlice("parameters")...)
//nolint:gosec
cmd := exec.CommandContext(ctx, "yarn", args...)
cmd.Dir = repoRoot
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, fmt.Sprintf("TZ=%s", c.String("timezone")))
cmd.Stdout = prefixCypress(os.Stdout)
cmd.Stderr = prefixCypress(os.Stderr)
cmd.Stdin = os.Stdin
return cmd.Run()
}
func joinCypressCfg(cfg map[string]string) string {
config := make([]string, 0, len(cfg))
for k, v := range cfg {
config = append(config, fmt.Sprintf("%s=%s", k, v))
}
return strings.Join(config, ",")
}
func prefixCypress(w io.Writer) io.Writer {
return outs.Prefix(w, "Cypress", outs.CyanColor)
}
func prefixGrafana(w io.Writer) io.Writer {
return outs.Prefix(w, "Grafana", outs.YellowColor)
}
+25
View File
@@ -0,0 +1,25 @@
package cmd
import (
"github.com/grafana/grafana/e2e/internal/cmd/a11y"
"github.com/grafana/grafana/e2e/internal/cmd/cypress"
"github.com/urfave/cli/v3"
)
func Root() *cli.Command {
return &cli.Command{
Name: "e2e",
Usage: "Run an end-to-end test suite",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "timezone",
Usage: "Timezone to set for all containers (e.g. 'America/New_York')",
Value: "Pacific/Honolulu",
},
},
Commands: []*cli.Command{
a11y.NewCmd(),
cypress.NewCmd(),
},
}
}
+35
View File
@@ -0,0 +1,35 @@
package fpaths
import (
"context"
"fmt"
"os/exec"
"path"
"path/filepath"
"strings"
)
// RepoRoot finds the root directory of the git repository.
func RepoRoot(ctx context.Context, dir string) (string, error) {
cmd := exec.CommandContext(ctx, "git", "rev-parse", "--show-toplevel")
cmd.Dir = dir
out, err := cmd.Output()
if err != nil {
return "", fmt.Errorf("failed to get git repo root: %w", err)
}
p := strings.TrimSpace(string(out))
p, err = NormalisePath(p)
if err != nil {
return "", fmt.Errorf("failed to normalise git repo root path: %w", err)
}
return p, nil
}
// NormalisePath converts a path to an absolute path, cleans it, and converts it to a forward-slash format.
func NormalisePath(p string) (string, error) {
absPath, err := filepath.Abs(p)
if err != nil {
return "", fmt.Errorf("failed to get absolute path: %w", err)
}
return path.Clean(filepath.ToSlash(absPath)), nil
}
+65
View File
@@ -0,0 +1,65 @@
package outs
import (
"bytes"
"io"
"os"
"sync"
)
const (
ResetColor = "\033[0m"
YellowColor = "\033[0;33m"
CyanColor = "\033[0;36m"
)
func Prefix(w io.Writer, name, colour string) io.Writer {
if _, ok := os.LookupEnv("CI"); ok {
return newWrappingOutput(name+": ", "", w)
}
return newWrappingOutput(colour+name+": ", ResetColor, w)
}
var _ io.Writer = (*wrappingOutput)(nil)
type wrappingOutput struct {
prefix string
suffix string
mu *sync.Mutex
inner io.Writer
writtenPrefix bool
}
func newWrappingOutput(prefix, suffix string, inner io.Writer) *wrappingOutput {
return &wrappingOutput{
prefix: prefix,
suffix: suffix,
mu: &sync.Mutex{},
inner: inner,
}
}
func (p *wrappingOutput) Write(b []byte) (int, error) {
p.mu.Lock()
defer p.mu.Unlock()
for line := range bytes.Lines(b) {
if !p.writtenPrefix {
if _, err := p.inner.Write([]byte(p.prefix)); err != nil {
return 0, err
}
p.writtenPrefix = true
}
if _, err := p.inner.Write(line); err != nil {
return 0, err
}
if bytes.HasSuffix(line, []byte("\n")) {
p.writtenPrefix = false
if _, err := p.inner.Write([]byte(p.suffix)); err != nil {
return 0, err
}
}
}
return len(b), nil
}
+21
View File
@@ -0,0 +1,21 @@
package main
import (
"context"
"fmt"
"os"
"os/signal"
"github.com/grafana/grafana/e2e/internal/cmd"
)
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
if err := cmd.Root().Run(ctx, os.Args); err != nil {
cancel()
fmt.Println(err)
os.Exit(1)
}
}
+140
View File
@@ -0,0 +1,140 @@
const config = {
defaults: {
concurrency: 1,
runners: ['axe'],
useIncognitoBrowserContext: false,
standard: 'WCAG2AA',
chromeLaunchConfig: {
executablePath: '/usr/bin/google-chrome',
args: ['--no-sandbox'],
},
// see https://github.com/grafana/grafana/pull/41693#issuecomment-979921463 for context
// on why we're ignoring singleValue/react-select-*-placeholder elements
hideElements: '#updateVersion, [class*="-singleValue"], [id^="react-select-"][id$="-placeholder"]',
reporters: ['cli', ['json', { fileName: './pa11y-ci-results.json' }]],
},
urls: [
{
url: '${HOST}/login',
threshold: 0,
},
{
url: '${HOST}/login',
actions: [
"wait for element input[name='user'] to be added",
"set field input[name='user'] to admin",
"set field input[name='password'] to admin",
"click element button[data-testid='data-testid Login button']",
"wait for element button[data-testid='data-testid Skip change password button'] to be visible",
],
threshold: 2,
},
{
url: '${HOST}/?orgId=1',
threshold: 0,
},
{
url: '${HOST}/d/O6f11TZWk/panel-tests-bar-gauge',
threshold: 0,
},
// Dashboard settings
{
url: '${HOST}/d/O6f11TZWk/panel-tests-bar-gauge?orgId=1&editview=settings',
threshold: 0,
},
{
url: '${HOST}/d/O6f11TZWk/panel-tests-bar-gauge?orgId=1&editview=annotations',
threshold: 0,
},
{
url: '${HOST}/d/O6f11TZWk/panel-tests-bar-gauge?orgId=1&editview=variables',
threshold: 0,
},
{
url: '${HOST}/d/O6f11TZWk/panel-tests-bar-gauge?orgId=1&editview=links',
threshold: 0,
},
{
url: '${HOST}/d/O6f11TZWk/panel-tests-bar-gauge?orgId=1&editview=versions',
threshold: 0,
},
{
url: '${HOST}/d/O6f11TZWk/panel-tests-bar-gauge?orgId=1&editview=permissions',
// TODO: improve the accessibility of the permission tab https://github.com/grafana/grafana/issues/77203
threshold: 5,
},
{
url: '${HOST}/d/O6f11TZWk/panel-tests-bar-gauge?orgId=1&editview=dashboard_json',
threshold: 2,
},
// Misc
{
url: '${HOST}/?orgId=1&search=open',
threshold: 0,
},
{
url: '${HOST}/alerting/list',
// the unified alerting promotion alert's content contrast is too low
// see https://github.com/grafana/grafana/pull/41829
threshold: 7,
},
{
url: '${HOST}/datasources',
threshold: 0,
},
{
url: '${HOST}/org/users',
threshold: 2,
},
{
url: '${HOST}/org/teams',
threshold: 1,
},
{
url: '${HOST}/plugins',
threshold: 0,
},
{
url: '${HOST}/org',
threshold: 2,
},
{
url: '${HOST}/org/apikeys',
threshold: 4,
},
{
url: '${HOST}/dashboards',
threshold: 2,
},
],
};
function myPa11yCiConfiguration(urls, defaults) {
const HOST_SERVER = process.env.HOST || 'localhost';
const PORT_SERVER = process.env.PORT || '3001';
const noThresholds = process.env.NO_THRESHOLDS === 'true';
urls = urls.map((test, index) => {
return {
...test,
url: test.url.replace('${HOST}', `${HOST_SERVER}:${PORT_SERVER}`),
screenCapture: `./screenshots/screenshot-${index}.png`,
rootElement: '.main-view',
wait: 500,
// Depending on NO_THRESHOLDS (--no-threshold-fail in the dagger command), clear the thresholds
// to allow pa11y to fail the check and include error details in the results file
threshold: noThresholds ? undefined : test.threshold,
};
});
return {
defaults: defaults,
urls: urls,
};
}
module.exports = myPa11yCiConfiguration(config.urls, config.defaults);
+27 -6
View File
@@ -26,10 +26,11 @@ declare -A env=(
)
testFilesForSingleSuite="*.spec.ts"
rootForEnterpriseSuite="./e2e/extensions-suite"
rootForEnterpriseSuite="./e2e/extensions"
rootForOldArch="./e2e/old-arch"
rootForKubernetesDashboards="./e2e/dashboards-suite"
rootForSearchDashboards="./e2e/dashboards-search-suite"
rootForDashboardNewLayouts="./e2e/dashboard-new-layouts"
declare -A cypressConfig=(
[screenshotsFolder]=./e2e/"${args[0]}"/screenshots
@@ -44,6 +45,7 @@ declare -A cypressConfig=(
[trashAssetsBeforeRuns]=false
[reporter]=./e2e/log-reporter.js
[baseUrl]=${BASE_URL:-"http://$HOST:$PORT"}
[video]=${CYPRESS_VIDEO:-false}
)
case "$1" in
@@ -69,8 +71,6 @@ case "$1" in
"enterprise")
echo "Enterprise"
env[SMTP_PLUGIN_ENABLED]=true
CLEANUP="rm -rf ./e2e/extensions-suite"
SETUP="cp -Lr ./e2e/extensions ./e2e/extensions-suite"
enterpriseSuite=$(basename "${args[1]}")
case "$2" in
"debug")
@@ -86,12 +86,11 @@ case "$1" in
;;
esac
cypressConfig[specPattern]=$rootForEnterpriseSuite/$enterpriseSuite/*-suite/*.spec.ts
$CLEANUP && $SETUP
;;
"")
;;
"old-arch")
env[DISABLE_SCENES]=true
env[dashboardScene]=false
cypressConfig[specPattern]=$rootForOldArch/*/$testFilesForSingleSuite
cypressConfig[video]=false
case "$2" in
@@ -111,7 +110,7 @@ case "$1" in
"old-arch/"*)
cypressConfig[specPattern]=./e2e/"${args[0]}"/$testFilesForSingleSuite
cypressConfig[video]=${args[1]}
env[DISABLE_SCENES]=true
env[dashboardScene]=false
;;
"dashboards-schema-v2")
env[kubernetesDashboards]=true
@@ -149,6 +148,28 @@ case "$1" in
;;
esac
;;
"dashboard-new-layouts")
env[kubernetesDashboards]=true
env[dashboardNewLayouts]=true
env[groupByVariable]=true
cypressConfig[specPattern]=$rootForDashboardNewLayouts/$testFilesForSingleSuite
cypressConfig[video]=false
case "$2" in
"debug")
echo -e "Debug mode"
env[SLOWMO]=1
PARAMS="--no-exit"
enterpriseSuite=$(basename "${args[2]}")
;;
"dev")
echo "Dev mode"
# remove comment to run in slomo ( demo mode )
# env[SLOWMO]=1
CMD="cypress open"
enterpriseSuite=$(basename "${args[2]}")
;;
esac
;;
"enterprise-smtp")
env[SMTP_PLUGIN_ENABLED]=true
cypressConfig[specPattern]=./e2e/extensions/enterprise/smtp-suite/$testFilesForSingleSuite