diff --git a/buildbuddy.yaml b/buildbuddy.yaml index e58dba5d3c3..b255260269b 100644 --- a/buildbuddy.yaml +++ b/buildbuddy.yaml @@ -1,4 +1,15 @@ actions: + - name: Maggie + container_image: ubuntu-20.04 + triggers: + push: + branches: + - "master" + pull_request: + branches: + - "*" + bazel_commands: + - test cli/remotebazel/integration/... --test_env=BB_PROBER_ORG_API_KEY --config=linux-workflows --config=race --test_tag_filters=-performance,-webdriver,-docker,-bare - name: Test container_image: ubuntu-20.04 triggers: diff --git a/cli/remotebazel/integration/BUILD b/cli/remotebazel/integration/BUILD new file mode 100644 index 00000000000..b6bb7256133 --- /dev/null +++ b/cli/remotebazel/integration/BUILD @@ -0,0 +1,24 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_test") + +package(default_visibility = ["//cli:__subpackages__"]) + +go_test( + name = "integration_test", + srcs = ["remote_bazel_test.go"], + exec_properties = { + "test.workload-isolation-type": "firecracker", + "test.recycle-runner": "true", + "test.runner-recycling-key": "remote-bazel-integration", + # The tests clone git repos, so make sure they have enough resources to do so + "test.EstimatedComputeUnits": "4", + "test.EstimatedFreeDiskBytes": "10GB", + # Use an image with bazelisk installed + "test.container-image": "docker://gcr.io/flame-public/rbe-ubuntu20-04-workflows@sha256:271e5e3704d861159c75b8dd6713dbe5a12272ec8ee73d17f89ed7be8026553f", + "include-secrets": "true", + }, + deps = [ + "//cli/remotebazel", + "//server/testutil/testshell", + "@com_github_stretchr_testify//require", + ], +) diff --git a/cli/remotebazel/integration/remote_bazel_test.go b/cli/remotebazel/integration/remote_bazel_test.go new file mode 100644 index 00000000000..fe0ed200982 --- /dev/null +++ b/cli/remotebazel/integration/remote_bazel_test.go @@ -0,0 +1,38 @@ +package integration_test + +import ( + "fmt" + "os" + "testing" + + "github.com/buildbuddy-io/buildbuddy/cli/remotebazel" + "github.com/buildbuddy-io/buildbuddy/server/testutil/testshell" + "github.com/stretchr/testify/require" +) + +func TestWithPublicRepo(t *testing.T) { + apiKey := os.Getenv("BB_PROD_PROBER_ORG_API_KEY") + fmt.Printf("Api key is %s", apiKey) + // Root dir is persisted on recycled runners + rootDir := "/root/workspace/remote-bazel-integration-test" + err := os.Setenv("HOME", rootDir) + require.NoError(t, err) + + err = os.MkdirAll(rootDir, 0755) + require.NoError(t, err) + err = os.Chdir(rootDir) + require.NoError(t, err) + + if _, err := os.Stat(fmt.Sprintf("%s/bazel-gazelle", rootDir)); os.IsNotExist(err) { + output := testshell.Run(t, rootDir, "git clone https://github.com/bazelbuild/bazel-gazelle --filter=blob:none --depth=1") + require.NotContains(t, output, "fatal") + } + + err = os.Chdir(fmt.Sprintf("%s/bazel-gazelle", rootDir)) + require.NoError(t, err) + + // TODO: Run a server and executor locally to run this against + exitCode, err := remotebazel.HandleRemoteBazel([]string{"help", fmt.Sprintf("--remote_header=x-buildbuddy-api-key=%s", apiKey)}) + require.NoError(t, err) + require.Equal(t, 0, exitCode) +} diff --git a/server/testutil/testshell/testshell.go b/server/testutil/testshell/testshell.go index 2ef100c8c53..57024c41ea4 100644 --- a/server/testutil/testshell/testshell.go +++ b/server/testutil/testshell/testshell.go @@ -1,6 +1,7 @@ package testshell import ( + "fmt" "os/exec" "testing" @@ -12,6 +13,9 @@ func Run(t testing.TB, workDir, script string) string { cmd := exec.Command("/usr/bin/env", "bash", "-e", "-c", script) cmd.Dir = workDir b, err := cmd.CombinedOutput() + if err != nil { + fmt.Printf("Script %q failed: %s", script, string(b)) + } require.NoError(t, err, "script %q failed: %s", script, string(b)) return string(b) }