@@ -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