Skip to content

Commit 85c0478

Browse files
authored
Update gomod path in script (#11376)
1 parent 319e0f5 commit 85c0478

File tree

1 file changed

+51
-22
lines changed

1 file changed

+51
-22
lines changed

docs/scripts/update-docs/update-components-docs.py

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,47 @@
3333
DEFAULT_CONFIG_FILE = '../../../docs/reference/edot-collector/config/default-config-standalone.md'
3434
COMPONENTS_YAML = '../../../internal/pkg/otel/components.yml'
3535

36+
# Path migration: EDOT code moved from internal/pkg/otel to internal/edot
37+
# in PR #10922 (merged Nov 7, 2025, backported to 8.19, 9.1, 9.2)
38+
# - go.mod with OTEL components moved to internal/edot/go.mod
39+
# - components.yml remains at internal/pkg/otel/components.yml
40+
GOMOD_NEW_PATH = 'internal/edot/go.mod'
41+
GOMOD_OLD_PATH = 'go.mod'
42+
COMPONENTS_YAML_PATH = 'internal/pkg/otel/components.yml'
43+
44+
45+
def check_file_exists_at_tag(file_path, tag):
46+
"""Check if a file exists at a specific Git tag"""
47+
try:
48+
subprocess.run(
49+
['git', 'cat-file', '-e', f'{tag}:{file_path}'],
50+
capture_output=True,
51+
check=True
52+
)
53+
return True
54+
except subprocess.CalledProcessError:
55+
return False
56+
57+
58+
def get_gomod_path_for_tag(tag):
59+
"""Determine the correct path for go.mod with OTEL components based on the tag.
60+
61+
The EDOT go.mod file was created at internal/edot/go.mod in PR #10922.
62+
Prior to that, OTEL components were in the root go.mod.
63+
64+
Args:
65+
tag: Git tag to check
66+
67+
Returns:
68+
The correct path string for go.mod at that tag
69+
"""
70+
# Try new path first (for newer versions)
71+
if check_file_exists_at_tag(GOMOD_NEW_PATH, tag):
72+
return GOMOD_NEW_PATH
73+
# Fall back to old path
74+
else:
75+
return GOMOD_OLD_PATH
76+
3677

3778
def read_file_from_git_tag(file_path, tag):
3879
"""Read a file from a specific Git tag"""
@@ -78,8 +119,8 @@ def get_core_components(version='main'):
78119
latest_version = get_latest_version()
79120
version_tag = f"v{latest_version}"
80121

81-
# Always read from Git tag
82-
components_path = 'internal/pkg/otel/components.yml'
122+
# components.yml path hasn't changed
123+
components_path = COMPONENTS_YAML_PATH
83124
print(f"Reading core components from tag {version_tag}: {components_path}")
84125
content = read_file_from_git_tag(components_path, version_tag)
85126
if content is None:
@@ -96,8 +137,8 @@ def get_deprecated_components(version='main'):
96137
latest_version = get_latest_version()
97138
version_tag = f"v{latest_version}"
98139

99-
# Always read from Git tag
100-
components_path = 'internal/pkg/otel/components.yml'
140+
# components.yml path hasn't changed
141+
components_path = COMPONENTS_YAML_PATH
101142
print(f"Reading deprecated components from tag {version_tag}: {components_path}")
102143
content = read_file_from_git_tag(components_path, version_tag)
103144
if content is None:
@@ -118,8 +159,8 @@ def get_component_annotations(version='main'):
118159
latest_version = get_latest_version()
119160
version_tag = f"v{latest_version}"
120161

121-
# Always read from Git tag
122-
components_path = 'internal/pkg/otel/components.yml'
162+
# components.yml path hasn't changed
163+
components_path = COMPONENTS_YAML_PATH
123164
print(f"Reading component annotations from tag {version_tag}: {components_path}")
124165
content = read_file_from_git_tag(components_path, version_tag)
125166
if content is None:
@@ -167,8 +208,8 @@ def get_otel_col_upstream_version():
167208
latest_version = get_latest_version()
168209
version_tag = f"v{latest_version}"
169210

170-
# Always read from Git tag
171-
go_mod_path = 'go.mod'
211+
# Determine correct go.mod path for this version (handles path migration)
212+
go_mod_path = get_gomod_path_for_tag(version_tag)
172213
print(f"Reading go.mod from tag {version_tag}: {go_mod_path}")
173214
content = read_file_from_git_tag(go_mod_path, version_tag)
174215
if content is None:
@@ -190,8 +231,8 @@ def get_otel_components(version='main', component_docs_mapping=None):
190231
latest_version = get_latest_version()
191232
version_tag = f"v{latest_version}"
192233

193-
# Always read from Git tag
194-
go_mod_path = 'go.mod'
234+
# Determine correct go.mod path for this version (handles path migration)
235+
go_mod_path = get_gomod_path_for_tag(version_tag)
195236
print(f"Reading go.mod from tag {version_tag}: {go_mod_path}")
196237
elastic_agent_go_mod = read_file_from_git_tag(go_mod_path, version_tag)
197238
if elastic_agent_go_mod is None:
@@ -414,18 +455,6 @@ def get_minor_versions_above(major_version, min_minor):
414455
filtered = [v for v in all_versions if v['minor'] >= min_minor]
415456
return filtered
416457

417-
def check_file_exists_at_tag(file_path, tag):
418-
"""Check if a file exists at a specific Git tag"""
419-
try:
420-
subprocess.run(
421-
['git', 'cat-file', '-e', f'{tag}:{file_path}'],
422-
capture_output=True,
423-
check=True
424-
)
425-
return True
426-
except subprocess.CalledProcessError:
427-
return False
428-
429458
def get_gateway_versions(major_version, min_minor):
430459
"""Get version data for gateway configuration table
431460

0 commit comments

Comments
 (0)