Skip to content

Commit 5d5b13e

Browse files
authored
Perform string interpolation for matrix task display names (#2188)
1 parent 51acca1 commit 5d5b13e

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

buildkite/bazelci.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,8 @@ def get_expanded_task(task, combination):
877877
if res:
878878
attr = res.groups()[0]
879879
expanded_task[key] = combination[attr]
880+
if "name" in expanded_task:
881+
expanded_task["name"] = expanded_task.get("name", "").format(**combination)
880882
return expanded_task
881883

882884

buildkite/bazelci_test.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,46 @@ def test_merge(self):
171171
)
172172
self.assertEqual(build_targets, ["//...", "-//experimental/...", "//experimental/good/..."])
173173

174+
class MatrixExpansion(unittest.TestCase):
175+
_CONFIGS = yaml.safe_load(
176+
"""
177+
matrix:
178+
bazel: ["1.2.3", "2.3.4"]
179+
platform: ["pf1", "pf2"]
180+
tasks:
181+
basic:
182+
name: "Basic"
183+
unformatted:
184+
name: "Unformatted"
185+
bazel: ${{ bazel }}
186+
without_name:
187+
bazel: ${{ bazel }}
188+
formatted:
189+
name: "Formatted w/ Bazel v{bazel} on {platform}"
190+
bazel: ${{ bazel }}
191+
platform: ${{ platform }}
192+
"""
193+
)
194+
195+
def test_basic_functionality(self):
196+
config = self._CONFIGS
197+
198+
bazelci.expand_task_config(config)
199+
expanded_tasks = config["tasks"]
200+
self.assertEqual(len(expanded_tasks), 9)
201+
expanded_task_names = [task.get("name", None) for id, task in expanded_tasks.items()]
202+
self.assertEqual(expanded_task_names, [
203+
"Basic", # no matrix expansion
204+
"Unformatted", # bazel v1.2.3
205+
"Unformatted", # bazel v2.3.4
206+
None, # no name, bazel v1.2.3
207+
None, # no name, bazel v2.3.4
208+
"Formatted w/ Bazel v1.2.3 on pf1",
209+
"Formatted w/ Bazel v1.2.3 on pf2",
210+
"Formatted w/ Bazel v2.3.4 on pf1",
211+
"Formatted w/ Bazel v2.3.4 on pf2",
212+
])
213+
174214

175215
if __name__ == "__main__":
176216
unittest.main()

0 commit comments

Comments
 (0)