Skip to content

Commit 014c1bb

Browse files
authored
Merge pull request #1001 from block/myron/ci-matrix-optimization
Reduce CI jobs from 11 to 8 and speed up 3 of them
2 parents 9725235 + 87e9f07 commit 014c1bb

File tree

3 files changed

+55
-17
lines changed

3 files changed

+55
-17
lines changed

.github/workflows/ci.yaml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,19 @@ jobs:
3434
- "4.0"
3535
datastore:
3636
- "elasticsearch:9.2.4"
37-
- "elasticsearch:9.0.0"
38-
- "opensearch:3.4.0"
39-
- "opensearch:2.19.0"
4037
include:
41-
# We have 4 build parts. The "primary" one is `run_each_gem_spec`, and we need that to be run on
42-
# every supported Ruby version and against every supported datastore. It's not necessary to run
43-
# these others against every combination of `ruby` and `datastore` so we just run each with one
44-
# configuration here.
38+
# Datastore-specific tests on non-primary datastores.
39+
# These run only `:uses_datastore` tagged tests since non-datastore tests don't vary by datastore.
40+
- build_part: "run_datastore_specs"
41+
ruby: "4.0"
42+
datastore: "elasticsearch:9.0.0"
43+
- build_part: "run_datastore_specs"
44+
ruby: "4.0"
45+
datastore: "opensearch:3.4.0"
46+
- build_part: "run_datastore_specs"
47+
ruby: "4.0"
48+
datastore: "opensearch:2.19.0"
49+
# Other build parts run on max Ruby and primary datastore only.
4550
- build_part: "run_misc_checks"
4651
ruby: "4.0"
4752
datastore: "elasticsearch:9.2.4"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
# This script runs only the datastore-specific tests (tagged with :uses_datastore).
4+
# It's used for non-primary datastores where we only need to verify datastore compatibility,
5+
# not run the full test suite (which would be redundant since non-datastore tests don't vary
6+
# by datastore).
7+
8+
source "script/ci_parts/setup_env" "test" $1 $2
9+
10+
# No coverage checking for datastore-specific tests. Coverage is verified by run_each_gem_spec
11+
# on the primary datastore.
12+
unset COVERAGE
13+
14+
script/run_specs --tag uses_datastore

script/update_ci_yaml

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@ module ElasticGraph
3333
def updated_content
3434
content = @content.dup
3535
content = update_datastore_matrix(content)
36-
content = update_primary_datastore(content)
36+
content = update_includes_primary_datastore(content)
37+
content = update_run_datastore_specs_includes(content)
3738
update_opensearch_version(content)
3839
end
3940

41+
def non_primary_datastore_versions
42+
datastore_versions - [primary_datastore_version]
43+
end
44+
4045
def show_diff
4146
tmp_path = PROJECT_ROOT / "tmp" / "ci.yaml"
4247
FileUtils.mkdir_p(tmp_path.dirname)
@@ -76,22 +81,36 @@ module ElasticGraph
7681
end
7782

7883
def update_datastore_matrix(content)
79-
# Find the datastore matrix section and preserve its exact indentation
84+
# Matrix now has single primary datastore only.
85+
# Non-primary datastores use run_datastore_specs via includes.
8086
matrix_pattern = /( datastore:\n)([^\n]*\n)*? include:/m
8187
match = content.match(matrix_pattern)
8288
return content unless match
8389

8490
matrix_start = match[1]
85-
new_versions = datastore_versions.map { |v| ' - "' + v + "\"\n" }.join
86-
content.sub(matrix_pattern, "#{matrix_start}#{new_versions} include:")
91+
new_version = ' - "' + primary_datastore_version + "\"\n"
92+
content.sub(matrix_pattern, "#{matrix_start}#{new_version} include:")
8793
end
8894

89-
def update_primary_datastore(content)
90-
# Update each primary datastore version in the includes section
91-
content.gsub(
92-
/(?<=datastore: ")[^"]+(?="\n)/,
93-
primary_datastore_version
94-
)
95+
def update_includes_primary_datastore(content)
96+
# Update ALL datastore entries in includes section to primary.
97+
# run_datastore_specs entries will be overridden by update_run_datastore_specs_includes.
98+
parts = content.split(/^ include:\n/, 2)
99+
return content unless parts.size == 2
100+
101+
updated = parts[1].gsub(/(?<=datastore: ")[^"]+(?=")/, primary_datastore_version)
102+
parts[0] + " include:\n" + updated
103+
end
104+
105+
def update_run_datastore_specs_includes(content)
106+
# Override run_datastore_specs entries with non-primary datastores
107+
versions = non_primary_datastore_versions
108+
idx = 0
109+
content.gsub(/(?<=build_part: "run_datastore_specs"\n ruby: "4.0"\n datastore: ")[^"]+(?=")/) do
110+
version = versions[idx]
111+
idx += 1
112+
version
113+
end
95114
end
96115

97116
def update_opensearch_version(content)

0 commit comments

Comments
 (0)