|
12 | 12 | from httpx import HTTPError, HTTPStatusError |
13 | 13 | from packaging.version import Version |
14 | 14 |
|
| 15 | +from .build_agent import BUILD_AGENT_YAML_PATH, ensure_build_agent_yaml_updated |
| 16 | + |
15 | 17 | if TYPE_CHECKING: |
16 | 18 | from ddev.cli.application import Application |
17 | 19 |
|
18 | 20 | BRANCH_NAME_PATTERN = r"^\d+\.\d+\.x$" |
19 | 21 | BRANCH_NAME_REGEX = re.compile(BRANCH_NAME_PATTERN) |
20 | | -BUILD_AGENT_YAML_PATH = '.gitlab/build_agent.yaml' |
21 | | -BUILD_AGENT_TEMPLATE_PATTERN = r'^\.build-agent-tpl:\n(?:[^\S\n].*(?:\n|$))*' |
22 | | -BUILD_AGENT_MAIN_BRANCH_PATTERN = r'^(\s+branch:\s+)main([^\S\n]*)$' |
23 | | -BUILD_AGENT_TEMPLATE_REGEX = re.compile(BUILD_AGENT_TEMPLATE_PATTERN, re.MULTILINE) |
24 | | -BUILD_AGENT_MAIN_BRANCH_REGEX = re.compile(BUILD_AGENT_MAIN_BRANCH_PATTERN, re.MULTILINE) |
25 | 22 | GITHUB_LABEL_COLOR = '5319e7' |
26 | 23 |
|
27 | 24 |
|
@@ -108,6 +105,9 @@ def bump_milestone(app: Application, branch_name: str) -> None: |
108 | 105 | app.display_waiting(f"Updating release.json with new milestone `{next_milestone}`...") |
109 | 106 | app.repo.git.run('fetch', 'origin', 'master') |
110 | 107 | app.repo.git.run('checkout', '-B', bump_branch, 'origin/master') |
| 108 | + # Force-restore build_agent.yaml from origin/master so any prior in-process edit on the release |
| 109 | + # branch cannot leak into the milestone-bump commit (root cause of the leak on PR #23977). |
| 110 | + app.repo.git.run('checkout', 'origin/master', '--', BUILD_AGENT_YAML_PATH) |
111 | 111 | update_release_json(app.repo.path / 'release.json', next_milestone) |
112 | 112 | app.repo.git.run('add', 'release.json') |
113 | 113 | app.repo.git.run('commit', '-m', f'Update current_milestone to {next_milestone}') |
@@ -179,62 +179,3 @@ def suggest_next_branch(app: Application) -> str: |
179 | 179 | return suggestion |
180 | 180 |
|
181 | 181 | return f'{major}.{minors[-1] + 1}.x' |
182 | | - |
183 | | - |
184 | | -def ensure_build_agent_yaml_updated(app: Application, branch_name: str) -> bool: |
185 | | - """Update build_agent.yaml to point to the release branch when it still targets main.""" |
186 | | - from ddev.utils.fs import Path |
187 | | - |
188 | | - build_agent_yaml = Path(BUILD_AGENT_YAML_PATH) |
189 | | - |
190 | | - if not build_agent_yaml.exists(): |
191 | | - app.display_warning(f'Warning: {build_agent_yaml} not found') |
192 | | - return False |
193 | | - |
194 | | - with open(build_agent_yaml, 'r') as f: |
195 | | - content = f.read() |
196 | | - |
197 | | - matches = find_build_agent_template_main_branch_matches(content) |
198 | | - if not matches: |
199 | | - return False |
200 | | - if len(matches) > 1: |
201 | | - app.abort( |
202 | | - f'Expected exactly one `.build-agent-tpl` branch pointing to `main` in `{BUILD_AGENT_YAML_PATH}`; ' |
203 | | - f'found {len(matches)}.' |
204 | | - ) |
205 | | - return False |
206 | | - |
207 | | - updated_content, replacement_count = replace_build_agent_template_main_branch(content, branch_name) |
208 | | - assert replacement_count == 1 |
209 | | - |
210 | | - with open(build_agent_yaml, 'w') as f: |
211 | | - f.write(updated_content) |
212 | | - |
213 | | - app.display_success(f'Updated build_agent.yaml file to use Agent branch: {branch_name}') |
214 | | - return True |
215 | | - |
216 | | - |
217 | | -def find_build_agent_template_main_branch_matches(content: str) -> list[re.Match[str]]: |
218 | | - template_match = BUILD_AGENT_TEMPLATE_REGEX.search(content) |
219 | | - if template_match is None: |
220 | | - return [] |
221 | | - |
222 | | - return list(BUILD_AGENT_MAIN_BRANCH_REGEX.finditer(template_match.group(0))) |
223 | | - |
224 | | - |
225 | | -def replace_build_agent_template_main_branch(content: str, branch_name: str) -> tuple[str, int]: |
226 | | - template_match = BUILD_AGENT_TEMPLATE_REGEX.search(content) |
227 | | - if template_match is None: |
228 | | - return content, 0 |
229 | | - |
230 | | - def replacement(match: re.Match[str]) -> str: |
231 | | - return f'{match.group(1)}{branch_name}{match.group(2)}' |
232 | | - |
233 | | - updated_template, replacement_count = BUILD_AGENT_MAIN_BRANCH_REGEX.subn( |
234 | | - replacement, template_match.group(0), count=1 |
235 | | - ) |
236 | | - if replacement_count == 0: |
237 | | - return content, 0 |
238 | | - |
239 | | - updated_content = content[: template_match.start()] + updated_template + content[template_match.end() :] |
240 | | - return updated_content, replacement_count |
0 commit comments