Skip to content

Commit 832a912

Browse files
authored
ansible_test_splitter - minor changes (#115)
* update return format for ansible_test_splitter * add extra git base branch to test against * adding some debug
1 parent fde5cae commit 832a912

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

.github/actions/ansible_test_splitter/action.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,19 @@ inputs:
1212
description: The total number of jobs to share targets on
1313
required: false
1414
default: "3"
15+
base_ref:
16+
description: The git base branch to compare with.
17+
required: false
1518
outputs:
1619
test_targets:
17-
description: The list of targets to test
20+
description: The list of targets to test as concatenate string
1821
value: ${{ steps.splitter.outputs.test_targets }}
22+
test_targets_json:
23+
description: The list of targets to test as json string
24+
value: ${{ steps.splitter.outputs.test_targets_json }}
25+
test_jobs:
26+
description: The list of generate keys
27+
value: ${{ steps.splitter.outputs.test_jobs }}
1928

2029
runs:
2130
using: composite
@@ -42,5 +51,5 @@ runs:
4251
COLLECTIONS_TO_TEST: "${{ inputs.collections_to_test }}"
4352
TOTAL_JOBS: "${{ inputs.total_jobs }}"
4453
PULL_REQUEST_BODY: "${{ github.event.pull_request.body }}"
45-
PULL_REQUEST_BASE_REF: "${{ github.event.pull_request.base.ref }}"
54+
PULL_REQUEST_BASE_REF: "${{ inputs.base_ref || github.event.pull_request.base.ref }}"
4655
shell: bash

.github/actions/ansible_test_splitter/list_changed_common.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""Define collection module for list_changed_targets executable."""
33

44
import ast
5+
import json
56
import os
67
import re
78
import subprocess
@@ -469,7 +470,7 @@ def __init__(self, collections_items: list[Collection], number_jobs: int) -> Non
469470
self.total_jobs = number_jobs
470471
self.targets_per_slot = 10
471472

472-
def output(self) -> str:
473+
def output(self) -> dict[str, str]:
473474
"""Produce output for the targets to test.
474475
475476
:returns: a string describing the output
@@ -479,7 +480,10 @@ def output(self) -> str:
479480
slots = [f"{col.collection_name}-{i+1}" for i in range(self.total_jobs)]
480481
for batch in self.build_up_batches(slots, col):
481482
batches.append(batch)
482-
return ";".join([f"{x}:{','.join(y)}" for x, y in batches])
483+
raw_string = ";".join([f"{x}:{','.join(y)}" for x, y in batches])
484+
raw_json = json.dumps({x: " ".join(y) for x, y in batches})
485+
jobs = json.dumps([x for x, _ in batches])
486+
return {"raw": raw_string, "raw_json": raw_json, "jobs": jobs}
483487

484488
def build_up_batches(
485489
self, slots: list[str], my_collection: Collection

.github/actions/ansible_test_splitter/list_changed_targets.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def _add_changed_target(
123123
print("----------- Listed Changes -----------\n", json.dumps(listed_changes, indent=2))
124124
return {x: make_unique(y["targets"]) for x, y in listed_changes.items()}
125125

126-
def run(self) -> str:
126+
def run(self) -> dict[str, str]:
127127
"""List changes and divide targets into chunk.
128128
129129
:returns: resulting string of targets divide into chunks
@@ -156,8 +156,11 @@ def write_variable_to_github_output(name: str, value: str) -> None:
156156

157157
def main() -> None:
158158
"""Perform main process of the module."""
159-
output = ListChangedTargets().run()
160-
write_variable_to_github_output("test_targets", output)
159+
result = ListChangedTargets().run()
160+
print("----------- change targets result -----------\n", json.dumps(result, indent=2))
161+
write_variable_to_github_output("test_targets", result.get("raw", ""))
162+
write_variable_to_github_output("test_targets_json", result.get("raw_json", ""))
163+
write_variable_to_github_output("test_jobs", result.get("jobs", "[]"))
161164

162165

163166
if __name__ == "__main__":

0 commit comments

Comments
 (0)