Skip to content

Commit 540298c

Browse files
Copilotjaydeluca
andauthored
fix: preserve *.starter.json files during clean build of explorer database
Agent-Logs-Url: https://github.com/open-telemetry/opentelemetry-ecosystem-explorer/sessions/f308c7e8-4bb4-4611-b711-7274dc017716 Co-authored-by: jaydeluca <7630696+jaydeluca@users.noreply.github.com>
1 parent fb565d0 commit 540298c

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

ecosystem-automation/explorer-db-builder/src/explorer_db_builder/configuration_builder.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,26 @@ def run_configuration_builder(
5353
output_path = Path(output_dir)
5454

5555
if clean and output_path.exists():
56+
# Preserve hand-crafted starter files before wiping generated output
57+
starter_files: dict[Path, str] = {}
58+
for f in output_path.rglob("*.starter.json"):
59+
try:
60+
starter_files[f.relative_to(output_path)] = f.read_text(encoding="utf-8")
61+
except OSError as e:
62+
logger.warning(f"Could not back up starter file {f}: {e}")
63+
5664
shutil.rmtree(output_path)
5765
logger.info(f"Cleaned {output_path}")
5866

67+
for relative_path, content in starter_files.items():
68+
try:
69+
restored = output_path / relative_path
70+
restored.parent.mkdir(parents=True, exist_ok=True)
71+
restored.write_text(content, encoding="utf-8")
72+
logger.info(f"Restored starter file: {relative_path}")
73+
except OSError as e:
74+
logger.warning(f"Could not restore starter file {relative_path}: {e}")
75+
5976
inventory = BaseInventoryManager(registry_dir)
6077
versions = inventory.list_release_versions()
6178

ecosystem-automation/explorer-db-builder/tests/test_configuration_builder.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,24 @@ def test_multiple_versions_latest_flag(self, config_registry, output_dir):
144144
else:
145145
assert entry["is_latest"] is False
146146

147+
def test_clean_preserves_starter_files(self, config_registry, output_dir):
148+
run_configuration_builder(
149+
registry_dir=str(config_registry),
150+
output_dir=str(output_dir),
151+
)
152+
starter_file = output_dir / "versions" / "1.0.0.starter.json"
153+
starter_content = '{"enabledSections": {}, "values": {}}'
154+
starter_file.write_text(starter_content)
155+
156+
run_configuration_builder(
157+
registry_dir=str(config_registry),
158+
output_dir=str(output_dir),
159+
clean=True,
160+
)
161+
162+
assert starter_file.exists()
163+
assert starter_file.read_text() == starter_content
164+
147165
def test_clean_removes_output_dir(self, config_registry, output_dir):
148166
run_configuration_builder(
149167
registry_dir=str(config_registry),

0 commit comments

Comments
 (0)