Skip to content

Commit e07f362

Browse files
committed
template: Add migration step for the new job matrix
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
1 parent 6c14338 commit e07f362

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

cookiecutter/migrate.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ def main() -> None:
4646
print("Adding flake8-datetimez plugin to dev-flake8 dependencies...")
4747
migrate_add_flake8_datetimez()
4848
print("=" * 72)
49+
print("Migrating the CI workflows to use a platform matrix...")
50+
migrate_platform_matrix()
51+
print("=" * 72)
4952
print()
5053

5154
if _manual_steps:
@@ -398,6 +401,55 @@ def replace_setuptools_pin(content: str, new_version: str) -> tuple[str, bool]:
398401
return new_content, count > 0
399402

400403

404+
def migrate_platform_matrix() -> None:
405+
"""Migrate CI matrix from arch+os to a single platform entry.
406+
407+
This replaces the old matrix definition that used separate `arch` and `os`
408+
entries with a single `platform` entry using GitHub's native arm64 runners
409+
that are now available to both public and private repositories.
410+
"""
411+
workflow_file = Path(".github/workflows/ci.yaml")
412+
print(f" - {workflow_file}")
413+
if not workflow_file.is_file():
414+
manual_step(
415+
f"Could not find {workflow_file}; please manually migrate to use a"
416+
"please manually migrate to use a `platform` matrix entry."
417+
)
418+
return
419+
420+
content = workflow_file.read_text(encoding="utf-8")
421+
new_content = content
422+
423+
# Replace the arch+os matrix block with platform.
424+
# Handle both "arm" (old) and "arm64" (intermediate) variants.
425+
new_content = re.sub(
426+
r"( +)arch:\n\1 - amd64\n\1 - arm(?:64)?\n\1os:\n\1 - ubuntu-24\.04\n",
427+
r"\g<1>platform:\n\g<1> - ubuntu-24.04\n\g<1> - ubuntu-24.04-arm\n",
428+
new_content,
429+
)
430+
431+
# Replace any runs-on expression referencing matrix.arch with the simpler
432+
# matrix.platform reference.
433+
new_content = re.sub(
434+
r"runs-on: \$\{\{.*matrix\.arch.*\}\}",
435+
"runs-on: ${{ matrix.platform }}",
436+
new_content,
437+
)
438+
439+
if new_content == content:
440+
if "matrix.platform" in content:
441+
print(" Already uses platform matrix")
442+
else:
443+
manual_step(
444+
f"Could not find arch+os matrix pattern in {workflow_file}; "
445+
"please manually migrate to use a `platform` matrix entry."
446+
)
447+
return
448+
449+
replace_file_contents_atomically(workflow_file, content, new_content, count=1)
450+
print(" Migrated arch+os matrix to platform")
451+
452+
401453
def apply_patch(patch_content: str) -> None:
402454
"""Apply a patch using the patch utility."""
403455
subprocess.run(["patch", "-p1"], input=patch_content.encode(), check=True)

0 commit comments

Comments
 (0)