Skip to content

Commit 3d94c10

Browse files
authored
Refactor example CI setup. (#437)
This change: - Adds many more `build_test` targets to ensure non-tests will still be built and checked. - Some of these are not working and are currently disabled. - Splits each top-level package into a separate CI action so that it's easier to spot failures and ensure other tests continue - Adds a new tag-based way to disable tests: - `no-ci` will skip the test in CI entirely - `no-remote-ci` and `no-local-ci` will skip based on remote execution - `no-linux-ci` and `no-macos-ci` will skip based on the OS
1 parent 7982c28 commit 3d94c10

19 files changed

Lines changed: 277 additions & 60 deletions

File tree

.github/workflows/main.yml

Lines changed: 81 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,32 @@ env:
2121
OPAL_RPC_CREDENTIALS: ${{ secrets.OPAL_RPC_CREDENTIALS }}
2222

2323
jobs:
24-
test-matrix:
24+
macos-test-matrix:
2525
runs-on:
2626
- self-hosted
27-
- "os=${{ matrix.os }}"
28-
- "arch=${{ matrix.arch }}"
29-
- "os_distribution=${{ matrix.os_distribution }}"
30-
- "os_version=${{ matrix.os_version }}"
31-
- "revision=${{ matrix.revision }}"
27+
- "os=macos"
28+
- "arch=arm64"
29+
- "os_distribution=sonoma"
30+
- "os_version=14"
31+
- "revision=4edc10aa8f8ca239699aaf1078832208fb3b7efe"
3232
timeout-minutes: 10
3333
strategy:
3434
fail-fast: false
3535
matrix:
36-
include:
37-
- os: macos
38-
arch: arm64
39-
os_distribution: sonoma
40-
os_version: "14"
41-
revision: 4edc10aa8f8ca239699aaf1078832208fb3b7efe
42-
remote_execution: 'false'
43-
44-
- os: macos
45-
arch: arm64
46-
os_distribution: sonoma
47-
os_version: "14"
48-
revision: 4edc10aa8f8ca239699aaf1078832208fb3b7efe
49-
remote_execution: 'true'
36+
test_package:
37+
- cpp
38+
- csharp
39+
- docker
40+
- genrules
41+
- go
42+
#- ios # TODO: fix ios builds
43+
- java
44+
- kotlin
45+
- perl
46+
- scala
47+
- swift
48+
- typescript
49+
execution_type: [remote, local]
5050

5151
steps:
5252
- uses: "actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd"
@@ -61,36 +61,81 @@ jobs:
6161

6262
- name: Build and test
6363
env:
64-
ARCH: ${{ matrix.arch }}
65-
OS: ${{ matrix.os }}
66-
REMOTE_EXECUTION: ${{ matrix.remote_execution }}
67-
run: python3 infra/test-all.py
64+
ARCH: arm64
65+
OS: macos
66+
EXECUTION_TYPE: ${{ matrix.execution_type }}
67+
run: python3 infra/test-all.py --package=${{ matrix.test_package }}
6868

69-
ci-runners-test-matrix:
69+
linux-test-matrix:
7070
runs-on:
7171
- self-hosted
7272
- "os=linux"
7373
- "arch=x64"
74-
- "remote_execution=${{ matrix.remote_execution }}"
7574
- "engflow-bento-name=example-gh-x64"
7675
- "engflow-cluster=glass"
77-
- "engflow-job-name=ci-runners-test-matrix-${{matrix.remote_execution}}_${{matrix.allow_bento_snapshot}}"
76+
- "engflow-job-name=linux-test-matrix-${{matrix.execution_type}}"
77+
- "engflow-job-type=${{github.event_name}}-${{github.ref_name}}"
78+
- "engflow-run-id=${{ github.run_id }}"
79+
- "engflow-bento-allow-save=false"
80+
81+
timeout-minutes: 10
82+
strategy:
83+
fail-fast: false
84+
matrix:
85+
test_package:
86+
- cpp
87+
- csharp
88+
- docker
89+
- genrules
90+
- go
91+
#- ios # TODO: fix ios builds
92+
- java
93+
- kotlin
94+
- perl
95+
- scala
96+
- swift
97+
- typescript
98+
execution_type: [remote, local]
99+
100+
steps:
101+
- uses: "actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd"
102+
103+
- name: Set up authentication
104+
shell: bash
105+
run: cp infra/bazelrc .bazelrc.user
106+
107+
- name: Generate python requirements lock
108+
shell: bash
109+
run: bazel run //python:requirements.update
110+
111+
- name: Build and test
112+
env:
113+
ARCH: x64
114+
OS: linux
115+
EXECUTION_TYPE: ${{ matrix.execution_type }}
116+
run: python3 infra/test-all.py --package=${{ matrix.test_package }}
117+
118+
bento-snapshot:
119+
runs-on:
120+
- self-hosted
121+
- "os=linux"
122+
- "arch=x64"
123+
- "remote_execution=true"
124+
- "engflow-bento-name=example-gh-x64"
125+
- "engflow-cluster=glass"
126+
- "engflow-job-name=bento-snapshot"
78127
- "engflow-job-type=${{github.event_name}}-${{github.ref_name}}"
79128
- "engflow-run-id=${{ github.run_id }}"
80129
# To avoid a race condition, among all the jobs that use the same Bento in the same repo, only
81130
# one should specify "engflow-bento-allow-save=true".
82-
- "engflow-bento-allow-save=${{ matrix.allow_bento_snapshot }}"
131+
- "engflow-bento-allow-save=true"
83132

84133
timeout-minutes: 10
85134
strategy:
86135
fail-fast: false
87136
matrix:
88-
include:
89-
- remote_execution: 'false'
90-
allow_bento_snapshot: 'false'
91-
92-
- remote_execution: 'true'
93-
allow_bento_snapshot: 'true'
137+
test_package: [cpp]
138+
execution_type: [remote]
94139

95140
steps:
96141
- uses: "actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd"
@@ -107,8 +152,8 @@ jobs:
107152
env:
108153
ARCH: x64
109154
OS: linux
110-
REMOTE_EXECUTION: ${{ matrix.remote_execution }}
111-
run: python3 infra/test-all.py
155+
EXECUTION_TYPE: ${{ matrix.execution_type }}
156+
run: python3 infra/test-all.py --package=${{ matrix.test_package }}
112157

113158
buck2-test:
114159
runs-on:

cpp/BUILD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@bazel_skylib//rules:build_test.bzl", "build_test")
12
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
23
load("@rules_cc//cc:cc_library.bzl", "cc_library")
34
load("@rules_cc//cc:cc_test.bzl", "cc_test")
@@ -16,6 +17,13 @@ cc_library(
1617
],
1718
)
1819

20+
build_test(
21+
name = "cpp_build_test",
22+
targets = [
23+
":cpp",
24+
],
25+
)
26+
1927
cc_test(
2028
name = "cpp_test",
2129
size = "small",

csharp/BUILD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@bazel_skylib//rules:build_test.bzl", "build_test")
12
load("@rules_dotnet//dotnet:defs.bzl", "csharp_binary")
23

34
csharp_binary(
@@ -9,3 +10,10 @@ csharp_binary(
910
"net8.0",
1011
],
1112
)
13+
14+
build_test(
15+
name = "csharp_test",
16+
targets = [
17+
":csharp.exe",
18+
],
19+
)

docker/BUILD

Whitespace-only changes.

docker/network/BUILD

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ DOCKER_JDK_PSQL = "docker://gcr.io/YOUR-IMAGE-NAME@sha256:b6ed8f68abd6e23409ee7a
2222
java_test(
2323
name = "docker-network-test",
2424
srcs = ["DockerNetworkTest.java"],
25-
tags = ["manual"],
25+
tags = [
26+
"manual",
27+
"no-ci", # Consistent NPE
28+
],
2629
test_class = "docker.network.DockerNetworkTest",
2730
)
2831

docker/sandbox/BUILD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@bazel_skylib//rules:build_test.bzl", "build_test")
12
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
23
load("@rules_java//java:java_binary.bzl", "java_binary")
34

@@ -25,3 +26,11 @@ cc_binary(
2526
name = "hello-cc",
2627
srcs = ["hello.cc"],
2728
)
29+
30+
build_test(
31+
name = "hello_test",
32+
tags = ["no-macos-ci"],
33+
targets = [
34+
":hello",
35+
],
36+
)

docker/sysbox/dind_test/BUILD

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,9 @@ sh_test(
3030
# DO NOT ENABLE!!! "dockerPrivileged": "True",
3131
# sysbox containers will refuse to start
3232
},
33-
tags = ["manual"],
33+
tags = [
34+
"manual",
35+
"no-local-ci",
36+
"no-macos-ci",
37+
],
3438
)

genrules/BUILD

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
# on the user's input.
1717
# This can be used for stress testing your build infrastructure.
1818
# Change the upper bound of the range and enjoy!
19+
load("@bazel_skylib//rules:build_test.bzl", "build_test")
20+
1921
UPPER_BOUND = 10
2022

2123
[genrule(
@@ -55,3 +57,11 @@ UPPER_BOUND = 10
5557
tags = ["manual"],
5658
tools = ["@ubuntu_20.04_1.3GB//file"],
5759
) for x in range(1, 2)]
60+
61+
# Only test a few to ensure they build, without creating undue load.
62+
build_test(
63+
name = "foo_TXT_test",
64+
targets = [
65+
":foo_TXT_4KB_1",
66+
],
67+
)

go/BUILD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@bazel_skylib//rules:build_test.bzl", "build_test")
12
load("@rules_go//go:def.bzl", "go_binary", "go_library")
23

34
go_binary(
@@ -12,3 +13,10 @@ go_library(
1213
importpath = "github.com/EngFlow/example/go",
1314
visibility = ["//visibility:private"],
1415
)
16+
17+
build_test(
18+
name = "go_build_test",
19+
targets = [
20+
":go",
21+
],
22+
)

infra/test-all.py

100644100755
Lines changed: 80 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,57 @@
11
#!/usr/bin/env python3
22

3+
import argparse
34
import os
45
import subprocess
56
import sys
67

7-
def main():
8-
# All targets that can run in any environment, except ios examples.
9-
targets = [
10-
"//...",
11-
# TODO: Add testing configuration for ios tests.
12-
"-//ios/...",
13-
]
14-
15-
for key in ("ARCH", "OPAL_RPC_CREDENTIALS", "OS", "REMOTE_EXECUTION"):
8+
EXTRA_FLAGS = {
9+
"ios": ["--config=ios"],
10+
"swift": ["--config=clang"],
11+
}
12+
13+
14+
def report_error(msg):
15+
print(msg, file=sys.stderr)
16+
sys.exit(1)
17+
18+
19+
def validate_env():
20+
for key in ("ARCH", "OS", "EXECUTION_TYPE", "OPAL_RPC_CREDENTIALS"):
1621
if not os.getenv(key):
17-
sys.stderr.write(f"{key} not set\n")
18-
sys.exit(1)
22+
report_error(f"{key} not set")
23+
24+
25+
def find_tests(package):
26+
os_name = os.getenv("OS")
27+
remote = os.getenv("EXECUTION_TYPE")
28+
29+
# Remove tests based on tags and environment
30+
query = f"""
31+
let t = tests(//{package}/...) in
32+
$t
33+
- attr(tags, no-ci, $t)
34+
- attr(tags, no-{os_name}-ci, $t)
35+
- attr(tags, no-{remote}-ci, $t)
36+
""".strip()
37+
38+
print(f"Executing query to find test targets:\n{query}")
39+
args = ["bazel", "query", "--output=label", "--", query]
40+
result = subprocess.run(args, capture_output=True)
41+
output = result.stdout.decode()
42+
return [t for t in output.split("\n") if t]
43+
44+
45+
def run_tests(package):
46+
targets = find_tests(package)
47+
if not targets:
48+
print(f"No targets found for {package}, skipping.")
49+
return 0
50+
print(f"Executing tests {targets}")
1951

2052
os_arch = os.getenv("OS") + "_" + os.getenv("ARCH")
2153
flags = ["--config=ci"]
22-
if os.getenv("REMOTE_EXECUTION") == "true":
54+
if os.getenv("EXECUTION_TYPE") == "remote":
2355
flags += [
2456
"--config=remote_" + os_arch,
2557
"--config=opal",
@@ -29,13 +61,44 @@ def main():
2961
"--config=opal_bes",
3062
"--config=opal_auth",
3163
]
32-
# The //docker/sysbox/... targets should only run in linux + remote
33-
if os.getenv("REMOTE_EXECUTION") == "true" and os.getenv("OS") == "linux":
34-
targets += ["//docker/sysbox/dind_test:check_docker",]
64+
65+
if package in EXTRA_FLAGS:
66+
flags += EXTRA_FLAGS[package]
67+
68+
print(f"---------------\nTesting {package}...")
69+
sys.stdout.flush()
70+
3571
args = ["bazel", "test"] + flags + ["--"] + targets
72+
result = subprocess.run(args, check=False)
73+
sys.stdout.flush()
74+
sys.stderr.flush()
75+
return result.returncode
76+
77+
78+
def main():
79+
parser = argparse.ArgumentParser(
80+
description="Runs example test suites", fromfile_prefix_chars="@"
81+
)
82+
parser.add_argument(
83+
"--package",
84+
required=False,
85+
help="Package to test.",
86+
)
87+
parser.add_argument(
88+
"--validate-env",
89+
action=argparse.BooleanOptionalAction,
90+
help="Whether to validate environment variables",
91+
)
92+
opts = parser.parse_args()
93+
94+
if opts.validate_env:
95+
validate_env()
96+
97+
package = opts.package
3698

37-
result = subprocess.run(args)
38-
sys.exit(result.returncode)
99+
returncode = run_tests(opts.package)
100+
if returncode != 0:
101+
sys.exit(returncode)
39102

40103

41104
if __name__ == "__main__":

0 commit comments

Comments
 (0)