Skip to content

Commit 33a6218

Browse files
committed
Use Circle CI dynamic configuration
Now `.circleci/config.continue.yml.j2` is a Jinja2 template that will get various variables depending on the branch. This allows finer-grained control on which jobs we run for each type of pipeline.
1 parent 6cecaf8 commit 33a6218

File tree

3 files changed

+110
-45
lines changed

3 files changed

+110
-45
lines changed

Diff for: .circleci/config.yml renamed to .circleci/config.continue.yml.j2

+21-45
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ defaults: &defaults
77

88
test_matrix: &test_matrix
99
parameters:
10-
testJvm: [ "ibm8", "semeru8", "zulu8", "oracle8", "11", "zulu11", "17", "ubuntu17" ]
10+
testJvm:
11+
{% for jdk in nocov_jdks %}
12+
- "{{ jdk }}"
13+
{% endfor %}
1114

1215
profiling_test_matrix: &profiling_test_matrix
1316
parameters:
14-
testJvm: [ "8", "zulu8", "oracle8", "11", "zulu11", "17", "ubuntu17" ]
17+
testJvm:
18+
{% for jdk in all_jdks %}
19+
- "{{ jdk }}"
20+
{% endfor %}
1521

1622
system_test_matrix: &system_test_matrix
1723
parameters:
@@ -179,6 +185,7 @@ commands:
179185
# 2) Cache keys are prefix matched, and the most recently updated cache that matches will be picked
180186
#
181187
# There is a weekly job that runs on Monday mornings that builds a new cache from scratch.
188+
{% raw %}
182189
restore_dependency_cache:
183190
parameters:
184191
cacheType:
@@ -239,6 +246,7 @@ commands:
239246
# Workspace
240247
- ~/dd-trace-java/.gradle
241248
- ~/dd-trace-java/workspace
249+
{% endraw %}
242250

243251
setup_system_tests:
244252
parameters:
@@ -1048,6 +1056,7 @@ build_test_jobs: &build_test_jobs
10481056
maxWorkers: 4
10491057
testJvm: "8"
10501058
1059+
{% if flaky %}
10511060
- tests:
10521061
requires:
10531062
- ok_to_test
@@ -1088,6 +1097,7 @@ build_test_jobs: &build_test_jobs
10881097
parallelism: 4
10891098
maxWorkers: 4
10901099
testJvm: "8"
1100+
{% endif %}
10911101
10921102
- tests:
10931103
requires:
@@ -1128,30 +1138,6 @@ build_test_jobs: &build_test_jobs
11281138
matrix:
11291139
<<: *test_matrix
11301140
1131-
- tests:
1132-
requires:
1133-
- ok_to_test
1134-
name: test_semeru11_smoke
1135-
gradleTarget: "stageMainDist :smokeTest"
1136-
gradleParameters: "-PskipFlakyTests"
1137-
stage: smoke
1138-
cacheType: smoke
1139-
parallelism: 4
1140-
maxWorkers: 3
1141-
testJvm: "semeru11"
1142-
1143-
- tests:
1144-
requires:
1145-
- ok_to_test
1146-
name: test_semeru17_smoke
1147-
gradleTarget: "stageMainDist :smokeTest"
1148-
gradleParameters: "-PskipFlakyTests"
1149-
stage: smoke
1150-
cacheType: smoke
1151-
parallelism: 4
1152-
maxWorkers: 3
1153-
testJvm: "semeru17"
1154-
11551141
- tests:
11561142
requires:
11571143
- ok_to_test
@@ -1231,24 +1217,18 @@ build_test_jobs: &build_test_jobs
12311217
- fan_in:
12321218
requires:
12331219
- test_published_artifacts
1234-
- test_8_profiling
1235-
- test_oracle8_profiling
1236-
- test_zulu8_profiling
1237-
- test_zulu11_profiling
1238-
- test_11_profiling
1239-
- test_17_profiling
1220+
{% for jdk in all_jdks %}
1221+
- "test_{{ jdk }}_profiling"
1222+
{% endfor %}
12401223
name: profiling
12411224
stage: profiling
12421225
12431226
- fan_in:
12441227
requires:
12451228
- test_published_artifacts
1246-
- test_8_debugger
1247-
- test_oracle8_debugger
1248-
- test_zulu8_debugger
1249-
- test_zulu11_debugger
1250-
- test_11_debugger
1251-
- test_17_debugger
1229+
{% for jdk in all_jdks %}
1230+
- "test_{{ jdk }}_debugger"
1231+
{% endfor %}
12521232
name: debugger
12531233
stage: debugger
12541234
@@ -1259,13 +1239,9 @@ build_test_jobs: &build_test_jobs
12591239
- check
12601240
- test_published_artifacts
12611241
- agent_integration_tests
1262-
- test_8
1263-
- test_ibm8
1264-
- test_11
1265-
- test_semeru11_smoke
1266-
- test_17
1267-
- test_semeru17_smoke
1268-
- test_zulu8
1242+
{% for jdk in all_jdks %}
1243+
- "test_{{ jdk }}"
1244+
{% endfor %}
12691245
- profiling
12701246
- debugger
12711247
name: required

Diff for: .circleci/render_config.py

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import os.path
5+
import time
6+
7+
import jinja2
8+
import requests
9+
10+
SCRIPT_DIR = os.path.dirname(__file__)
11+
12+
TPL_FILENAME = "config.continue.yml.j2"
13+
OUT_FILENAME = "config.continue.yml"
14+
GENERATED_CONFIG_PATH = os.path.join(SCRIPT_DIR, OUT_FILENAME)
15+
16+
# JDKs that will run on every pipeline.
17+
ALWAYS_ON_JDKS = {"8", "11", "17"}
18+
# And these will run only in master and release/ branches.
19+
MASTER_ONLY_JDKS = {
20+
"ibm8",
21+
"oracle8",
22+
"semeru8",
23+
"zulu8",
24+
"semeru11",
25+
"zulu11",
26+
"semeru17",
27+
"ubuntu17",
28+
}
29+
30+
# Get labels from pull requests to override some defaults for jobs to run.
31+
# `run-tests: all` will run all tests.
32+
# `run-tests: ibm8` will run the IBM 8 tests.
33+
# `run-tests: flaky` for flaky tests jobs.
34+
pr_url = os.environ.get("CIRCLE_PULL_REQUEST")
35+
if pr_url:
36+
pr_num = int(pr_url.split("/")[-1])
37+
headers = {}
38+
gh_token = os.environ.get("GH_TOKEN")
39+
if gh_token:
40+
headers["Authorization"] = gh_token
41+
else:
42+
print("Missing GH_TOKEN, trying anonymously")
43+
for _ in range(20):
44+
try:
45+
resp = requests.get(
46+
f"https://api.github.com/repos/DataDog/dd-trace-java/pulls/{pr_num}",
47+
timeout=1,
48+
headers=headers,
49+
)
50+
resp.raise_for_status()
51+
except Exception as e:
52+
print(f"Request filed: {e}")
53+
time.sleep(1)
54+
continue
55+
data = resp.json()
56+
break
57+
58+
labels = data.get("labels", [])
59+
labels = [l["name"] for l in labels]
60+
labels = {
61+
l.replace("run-tests: ", "") for l in labels if l.startswith("run-tests: ")
62+
}
63+
else:
64+
labels = set()
65+
66+
67+
branch = os.environ.get("CIRCLE_BRANCH", "")
68+
if branch == "master" or branch.startswith("release/v") or "all" in labels:
69+
all_jdks = ALWAYS_ON_JDKS | MASTER_ONLY_JDKS
70+
else:
71+
all_jdks = ALWAYS_ON_JDKS | (MASTER_ONLY_JDKS & labels)
72+
nocov_jdks = [j for j in all_jdks if j != "8"]
73+
74+
vars = {
75+
"all_jdks": all_jdks,
76+
"nocov_jdks": nocov_jdks,
77+
"flaky": branch == "master" or "flaky" in labels or "all" in labels,
78+
}
79+
80+
print(f"Variables for this build: {vars}")
81+
82+
loader = jinja2.FileSystemLoader(searchpath=SCRIPT_DIR)
83+
env = jinja2.Environment(loader=loader)
84+
tpl = env.get_template(TPL_FILENAME)
85+
out = tpl.render(**vars)
86+
87+
with open(GENERATED_CONFIG_PATH, "w", encoding="utf-8") as f:
88+
f.write(out)

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ replay_pid*
6868
############
6969
_circle_ci_cache_*
7070
upstream.env
71+
/.circleci/config.continue.yml
7172

7273
# Benchmarks #
7374
benchmark/reports

0 commit comments

Comments
 (0)