Skip to content

Commit 326cba9

Browse files
committed
Improve migration script results reporting
When the script succeeds, the message reporting the end of the script now is more visible by adding colors and emojis, and more clear about the script finishing **successfully**. When the script reports manual steps, the message reporting the end of the script now mentions manual steps are needed more visibly (adding colors and blinking emojis), and report the list of manual steps the user needs to perform. In this case the script will report the number of manual steps as exit status too, so the script fails if there are manual steps. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
1 parent fe49b18 commit 326cba9

2 files changed

Lines changed: 48 additions & 4 deletions

File tree

.github/cookiecutter-migrate.template.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,38 @@
2424
import json
2525
import os
2626
import subprocess
27+
import sys
2728
import tempfile
2829
from pathlib import Path
2930
from typing import SupportsIndex
3031

32+
_manual_steps: list[str] = [] # pylint: disable=invalid-name
33+
3134

3235
def main() -> None:
3336
"""Run the migration steps."""
3437
# Add a separation line like this one after each migration step.
3538
print("=" * 72)
36-
print("Migration script finished. Remember to follow any manual instructions.")
37-
print("=" * 72)
39+
print()
40+
41+
if _manual_steps:
42+
print(
43+
"\033[5;33m⚠️⚠️⚠️\033[0;33m Remember to check the manual steps: \033[5;33m⚠️⚠️⚠️\033[0m"
44+
)
45+
for n, step in enumerate(_manual_steps, start=1):
46+
print(f"\033[5;33m⚠️⚠️⚠️ \033[0;33m{n}. {step}\033[0m")
47+
print()
48+
49+
print(
50+
"\033[5;31m❌\033[0;31m Migration script finished but requires manual "
51+
"intervention \033[5;31m❌\033[0m"
52+
)
53+
print()
54+
55+
sys.exit(len(_manual_steps))
56+
57+
print("\033[0;32m ✅ Migration script finished successfully ✅\033[0m")
58+
print()
3859

3960

4061
def read_project_type() -> str | None:
@@ -146,6 +167,7 @@ def calculate_file_sha256_skip_lines(filepath: Path, skip_lines: int) -> str | N
146167

147168
def manual_step(message: str) -> None:
148169
"""Print a manual step message in yellow."""
170+
_manual_steps.append(message)
149171
print(f"\033[0;33m>>> {message}\033[0m")
150172

151173

cookiecutter/migrate.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@
2525
import os
2626
import re
2727
import subprocess
28+
import sys
2829
import tempfile
2930
from pathlib import Path
3031
from typing import SupportsIndex
3132

33+
_manual_steps: list[str] = [] # pylint: disable=invalid-name
34+
3235

3336
def main() -> None:
3437
"""Run the migration steps."""
@@ -40,8 +43,26 @@ def main() -> None:
4043
print("Migrating pyproject license metadata to SPDX format...")
4144
migrate_pyproject_license()
4245
print("=" * 72)
43-
print("Migration script finished. Remember to follow any manual instructions.")
44-
print("=" * 72)
46+
print()
47+
48+
if _manual_steps:
49+
print(
50+
"\033[5;33m⚠️⚠️⚠️\033[0;33m Remember to check the manual steps: \033[5;33m⚠️⚠️⚠️\033[0m"
51+
)
52+
for n, step in enumerate(_manual_steps, start=1):
53+
print(f"\033[5;33m⚠️⚠️⚠️ \033[0;33m{n}. {step}\033[0m")
54+
print()
55+
56+
print(
57+
"\033[5;31m❌\033[0;31m Migration script finished but requires manual "
58+
"intervention \033[5;31m❌\033[0m"
59+
)
60+
print()
61+
62+
sys.exit(len(_manual_steps))
63+
64+
print("\033[0;32m ✅ Migration script finished successfully ✅\033[0m")
65+
print()
4566

4667

4768
def migrate_to_ubuntu_slim() -> None:
@@ -427,6 +448,7 @@ def calculate_file_sha256_skip_lines(filepath: Path, skip_lines: int) -> str | N
427448

428449
def manual_step(message: str) -> None:
429450
"""Print a manual step message in yellow."""
451+
_manual_steps.append(message)
430452
print(f"\033[0;33m>>> {message}\033[0m")
431453

432454

0 commit comments

Comments
 (0)