Skip to content

Commit 675b22f

Browse files
committed
migrate: Update runners for Docker jobs
Move Docker-based jobs that were wrongly moved to `ubuntu-slim` by v0.15.0 back to `ubuntu-24.04`, as `ubuntu-slim` doesn't provide Docker. Both the cookiecutter template and the migration script were updated. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
1 parent ec16404 commit 675b22f

6 files changed

Lines changed: 127 additions & 4 deletions

File tree

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ But you might still need to adapt your code:
3535
### Cookiecutter template
3636

3737
- Added a migration step for api repositories to fix `mkdocs.yml` when the previous `mkdocstrings-python` v2 migration moved only `paths: ["src"]` under `handlers.python.options` but not `paths: ["py"]`.
38+
- Fixed runners for jobs that require Docker and where wrongly converted to `ubuntu-slim` in v0.15.0, changing them back to `ubuntu-24.04` to avoid Docker-related failures. The template and the migration script were both updated to reflect this change.

cookiecutter/migrate.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ def main() -> None:
4141
print("Fixing mkdocstrings-python v2 paths for api repos...")
4242
migrate_api_mkdocs_mkdocstrings_paths()
4343
print("=" * 72)
44+
print("Migrating protolint and publish-to-pypi runners to ubuntu-24.04...")
45+
migrate_docker_based_runners()
46+
print("=" * 72)
4447
print()
4548

4649
if _manual_steps:
@@ -111,6 +114,125 @@ def migrate_api_mkdocs_mkdocstrings_paths() -> None:
111114
)
112115

113116

117+
def migrate_docker_based_runners() -> None:
118+
"""Migrate Docker-based jobs to use ubuntu-24.04 runners.
119+
120+
The ``protolint`` and ``publish-to-pypi`` jobs need Docker, which is not
121+
available on ``ubuntu-slim``. They should therefore run on
122+
``ubuntu-24.04`` instead.
123+
"""
124+
workflows_dir = Path(".github") / "workflows"
125+
protolint_new = (
126+
" protolint:\n"
127+
" name: Check proto files with protolint\n"
128+
" runs-on: ubuntu-24.04"
129+
)
130+
publish_to_pypi_new = (
131+
' needs: ["create-github-release"]\n runs-on: ubuntu-24.04'
132+
)
133+
migrations: dict[str, list[dict[str, Any]]] = {}
134+
135+
protolint_rule = {
136+
"job": "protolint",
137+
"required_for": "api repos",
138+
"job_marker": " protolint:\n",
139+
"old": [
140+
(
141+
" protolint:\n"
142+
" name: Check proto files with protolint\n"
143+
" runs-on: ubuntu-slim"
144+
),
145+
(
146+
" protolint:\n"
147+
" name: Check proto files with protolint\n"
148+
" runs-on: ubuntu-latest"
149+
),
150+
],
151+
"new": protolint_new,
152+
}
153+
project_type = read_cookiecutter_str_var("type")
154+
if project_type is None:
155+
manual_step(
156+
"Unable to detect the cookiecutter project type from "
157+
".cookiecutter-replay.json; cannot determine whether the protolint "
158+
"runner migration applies."
159+
)
160+
elif project_type == "api":
161+
migrations.setdefault("ci-pr.yaml", []).append(protolint_rule)
162+
migrations.setdefault("ci.yaml", []).append(protolint_rule)
163+
else:
164+
print(" Skipping protolint runner migration (not an api project)")
165+
166+
github_org = read_cookiecutter_str_var("github_org")
167+
if github_org is None:
168+
manual_step(
169+
"Unable to detect the cookiecutter GitHub organization from "
170+
".cookiecutter-replay.json; cannot determine whether the "
171+
"publish-to-pypi runner migration applies."
172+
)
173+
elif github_org == "frequenz-floss":
174+
migrations.setdefault("ci.yaml", []).append(
175+
{
176+
"job": "publish-to-pypi",
177+
"required_for": "frequenz-floss repos",
178+
"job_marker": " publish-to-pypi:\n",
179+
"old": [
180+
(' needs: ["create-github-release"]\n runs-on: ubuntu-slim'),
181+
(
182+
' needs: ["create-github-release"]\n'
183+
" runs-on: ubuntu-latest"
184+
),
185+
],
186+
"new": publish_to_pypi_new,
187+
}
188+
)
189+
else:
190+
print(" Skipping publish-to-pypi runner migration (not a frequenz-floss repo)")
191+
192+
for filename, rules in migrations.items():
193+
filepath = workflows_dir / filename
194+
if not filepath.exists():
195+
for rule in rules:
196+
manual_step(
197+
f" Expected to find {filepath} for job {rule['job']} in "
198+
f"{rule['required_for']}. Please add or update that job to use "
199+
"`runs-on: ubuntu-24.04`."
200+
)
201+
continue
202+
203+
for rule in rules:
204+
job = rule["job"]
205+
required_for = rule["required_for"]
206+
job_marker = rule["job_marker"]
207+
new = rule["new"]
208+
content = filepath.read_text(encoding="utf-8")
209+
210+
if job_marker not in content:
211+
manual_step(
212+
f" Expected to find job {job} in {filepath} for "
213+
f"{required_for}. Please update it to use "
214+
"`runs-on: ubuntu-24.04`."
215+
)
216+
continue
217+
218+
if new in content:
219+
print(f" Skipped {filepath}: runner already up to date for job {job}")
220+
continue
221+
222+
for old in rule["old"]:
223+
if old in content:
224+
replace_file_contents_atomically(
225+
filepath, old, new, content=content
226+
)
227+
print(f" Updated {filepath}: migrated runner for job {job}")
228+
break
229+
else:
230+
manual_step(
231+
f" Pattern not found in {filepath}: please switch the runner "
232+
f"for job {job} to `runs-on: ubuntu-24.04`."
233+
)
234+
235+
114236
def apply_patch(patch_content: str) -> None:
115237
"""Apply a patch using the patch utility."""
116238
subprocess.run(["patch", "-p1"], input=patch_content.encode(), check=True)

cookiecutter/{{cookiecutter.github_repo_name}}/.github/workflows/ci-pr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
{% endraw %}{% if cookiecutter.type == "api" %}{% raw -%}
1616
protolint:
1717
name: Check proto files with protolint
18-
runs-on: ubuntu-slim
18+
runs-on: ubuntu-24.04
1919

2020
steps:
2121
- name: Setup Git

cookiecutter/{{cookiecutter.github_repo_name}}/.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
{% endraw %}{% if cookiecutter.type == "api" %}{% raw -%}
2828
protolint:
2929
name: Check proto files with protolint
30-
runs-on: ubuntu-slim
30+
runs-on: ubuntu-24.04
3131

3232
steps:
3333
- name: Setup Git

tests_golden/integration/test_cookiecutter_generation/api/frequenz-api-test/.github/workflows/ci-pr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ env:
1313
jobs:
1414
protolint:
1515
name: Check proto files with protolint
16-
runs-on: ubuntu-slim
16+
runs-on: ubuntu-24.04
1717

1818
steps:
1919
- name: Setup Git

tests_golden/integration/test_cookiecutter_generation/api/frequenz-api-test/.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ env:
2525
jobs:
2626
protolint:
2727
name: Check proto files with protolint
28-
runs-on: ubuntu-slim
28+
runs-on: ubuntu-24.04
2929

3030
steps:
3131
- name: Setup Git

0 commit comments

Comments
 (0)