Skip to content

Commit 389887c

Browse files
committed
Migrate lightweight workflow jobs to ubuntu-slim runner
Use the new 1 vCPU ubuntu-slim runner for lightweight jobs that don't need full resources: - protolint (api only) - nox-all (aggregator job) - test-installation-all (aggregator job) - create-github-release - publish-to-pypi - auto-merge (dependabot) - check-release-notes - DCO - Label The ubuntu-slim runner is more cost-effective for these simple jobs that primarily do API calls, artifact downloads, or run short scripts. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
1 parent c3200bf commit 389887c

34 files changed

Lines changed: 203 additions & 54 deletions

File tree

RELEASE_NOTES.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Summary
44

5-
<!-- Here goes a general summary of what this release is about -->
5+
This release migrates lightweight GitHub Actions workflow jobs to use the new cost-effective `ubuntu-slim` runner.
66

77
## Upgrading
88

@@ -26,7 +26,14 @@ But you might still need to adapt your code:
2626

2727
### Cookiecutter template
2828

29-
<!-- Here new features for cookiecutter specifically -->
29+
- Migrated lightweight workflow jobs to use the new `ubuntu-slim` runner for cost savings.
30+
The following jobs now use `ubuntu-slim`:
31+
- `ci.yaml`: `protolint`, `nox-all`, `test-installation-all`, `create-github-release`, `publish-to-pypi`
32+
- `ci-pr.yaml`: `protolint`
33+
- `auto-dependabot.yaml`: `auto-merge`
34+
- `release-notes-check.yml`: `check-release-notes`
35+
- `dco-merge-queue.yml`: `DCO`
36+
- `labeler.yml`: `Label`
3037

3138
## Bug Fixes
3239

cookiecutter/migrate.py

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,152 @@ def main() -> None:
3232
"""Run the migration steps."""
3333
# Add a separation line like this one after each migration step.
3434
print("=" * 72)
35+
print("Migrating workflows to use ubuntu-slim runner for lightweight jobs...")
36+
migrate_to_ubuntu_slim()
37+
print("=" * 72)
3538
print("Migration script finished. Remember to follow any manual instructions.")
3639
print("=" * 72)
3740

3841

42+
def migrate_to_ubuntu_slim() -> None:
43+
"""Migrate workflow files to use ubuntu-slim runner for lightweight jobs.
44+
45+
This updates several workflow files to use the new cost-effective ubuntu-slim
46+
runner for jobs that are lightweight (e.g., labeling, release notes checks,
47+
simple API calls).
48+
"""
49+
workflows_dir = Path(".github") / "workflows"
50+
51+
# Define the migration rules: (filename, old_runner, new_runner, job_patterns)
52+
# job_patterns is a list of job identifiers to help locate the right runs-on line
53+
migrations = [
54+
(
55+
"ci.yaml",
56+
[
57+
# nox-all job
58+
(
59+
" if: always() && needs.nox.result != 'skipped'\n"
60+
" runs-on: ubuntu-24.04",
61+
" if: always() && needs.nox.result != 'skipped'\n"
62+
" runs-on: ubuntu-slim",
63+
),
64+
# test-installation-all job
65+
(
66+
" if: always() && needs.test-installation.result != 'skipped'\n"
67+
" runs-on: ubuntu-24.04",
68+
" if: always() && needs.test-installation.result != 'skipped'\n"
69+
" runs-on: ubuntu-slim",
70+
),
71+
# create-github-release job
72+
(
73+
" discussions: write\n runs-on: ubuntu-24.04",
74+
" discussions: write\n runs-on: ubuntu-slim",
75+
),
76+
# publish-to-pypi job
77+
(
78+
' needs: ["create-github-release"]\n runs-on: ubuntu-24.04',
79+
' needs: ["create-github-release"]\n runs-on: ubuntu-slim',
80+
),
81+
# protolint job (for API projects)
82+
(
83+
" protolint:\n"
84+
" name: Check proto files with protolint\n"
85+
" runs-on: ubuntu-24.04",
86+
" protolint:\n"
87+
" name: Check proto files with protolint\n"
88+
" runs-on: ubuntu-slim",
89+
),
90+
],
91+
),
92+
(
93+
"ci-pr.yaml",
94+
[
95+
# protolint job (for API projects)
96+
(
97+
" protolint:\n"
98+
" name: Check proto files with protolint\n"
99+
" runs-on: ubuntu-24.04",
100+
" protolint:\n"
101+
" name: Check proto files with protolint\n"
102+
" runs-on: ubuntu-slim",
103+
),
104+
],
105+
),
106+
(
107+
"auto-dependabot.yaml",
108+
[
109+
(
110+
" auto-merge:\n"
111+
" if: github.actor == 'dependabot[bot]'\n"
112+
" runs-on: ubuntu-latest",
113+
" auto-merge:\n"
114+
" if: github.actor == 'dependabot[bot]'\n"
115+
" runs-on: ubuntu-slim",
116+
),
117+
],
118+
),
119+
(
120+
"release-notes-check.yml",
121+
[
122+
(
123+
" check-release-notes:\n"
124+
" name: Check release notes are updated\n"
125+
" runs-on: ubuntu-latest",
126+
" check-release-notes:\n"
127+
" name: Check release notes are updated\n"
128+
" runs-on: ubuntu-slim",
129+
),
130+
],
131+
),
132+
(
133+
"dco-merge-queue.yml",
134+
[
135+
(
136+
"jobs:\n DCO:\n runs-on: ubuntu-latest",
137+
"jobs:\n DCO:\n runs-on: ubuntu-slim",
138+
),
139+
],
140+
),
141+
(
142+
"labeler.yml",
143+
[
144+
(
145+
" Label:\n"
146+
" permissions:\n"
147+
" contents: read\n"
148+
" pull-requests: write\n"
149+
" runs-on: ubuntu-latest",
150+
" Label:\n"
151+
" permissions:\n"
152+
" contents: read\n"
153+
" pull-requests: write\n"
154+
" runs-on: ubuntu-slim",
155+
),
156+
],
157+
),
158+
]
159+
160+
for filename, replacements in migrations:
161+
filepath = workflows_dir / filename
162+
if not filepath.exists():
163+
print(f" Skipping {filename} (file not found)")
164+
continue
165+
166+
updated = False
167+
for old, new in replacements:
168+
try:
169+
content = filepath.read_text(encoding="utf-8")
170+
if old in content:
171+
replace_file_contents_atomically(filepath, old, new)
172+
updated = True
173+
print(f" Updated {filename}: migrated to ubuntu-slim")
174+
except FileNotFoundError:
175+
pass
176+
177+
if not updated:
178+
print(f" Skipping {filename} (already migrated or pattern not found)")
179+
180+
39181
def apply_patch(patch_content: str) -> None:
40182
"""Apply a patch using the patch utility."""
41183
subprocess.run(["patch", "-p1"], input=patch_content.encode(), check=True)

cookiecutter/{{cookiecutter.github_repo_name}}/.github/workflows/auto-dependabot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ permissions:
1010
jobs:
1111
auto-merge:
1212
if: github.actor == 'dependabot[bot]'
13-
runs-on: ubuntu-latest
13+
runs-on: ubuntu-slim
1414
steps:
1515
- name: Auto-merge Dependabot PR
1616
uses: frequenz-floss/dependabot-auto-approve@3cad5f42e79296505473325ac6636be897c8b8a1 # v1.3.2

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-24.04
18+
runs-on: ubuntu-slim
1919

2020
steps:
2121
- name: Setup Git

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

Lines changed: 5 additions & 5 deletions
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-24.04
30+
runs-on: ubuntu-slim
3131

3232
steps:
3333
- name: Setup Git
@@ -96,7 +96,7 @@ jobs:
9696
needs: ["nox"]
9797
# We skip this job only if nox was also skipped
9898
if: always() && needs.nox.result != 'skipped'
99-
runs-on: ubuntu-24.04
99+
runs-on: ubuntu-slim
100100
env:
101101
DEPS_RESULT: ${{ needs.nox.result }}
102102
steps:
@@ -205,7 +205,7 @@ jobs:
205205
needs: ["test-installation"]
206206
# We skip this job only if test-installation was also skipped
207207
if: always() && needs.test-installation.result != 'skipped'
208-
runs-on: ubuntu-24.04
208+
runs-on: ubuntu-slim
209209
env:
210210
DEPS_RESULT: ${{ needs.test-installation.result }}
211211
steps:
@@ -328,7 +328,7 @@ jobs:
328328
# discussions to create the release announcement in the discussion forums
329329
contents: write
330330
discussions: write
331-
runs-on: ubuntu-24.04
331+
runs-on: ubuntu-slim
332332
steps:
333333
- name: Download distribution files
334334
uses: actions/download-artifact@v4
@@ -370,7 +370,7 @@ jobs:
370370
publish-to-pypi:
371371
name: Publish packages to PyPI
372372
needs: ["create-github-release"]
373-
runs-on: ubuntu-24.04
373+
runs-on: ubuntu-slim
374374
permissions:
375375
# For trusted publishing. See:
376376
# https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/

cookiecutter/{{cookiecutter.github_repo_name}}/.github/workflows/dco-merge-queue.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66

77
jobs:
88
DCO:
9-
runs-on: ubuntu-latest
9+
runs-on: ubuntu-slim
1010
if: ${{ github.actor != 'dependabot[bot]' }}
1111
steps:
1212
- run: echo "This DCO job runs on merge_queue event and doesn't check PR contents"

cookiecutter/{{cookiecutter.github_repo_name}}/.github/workflows/labeler.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
permissions:
99
contents: read
1010
pull-requests: write
11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-slim
1212
steps:
1313
- name: Labeler
1414
# XXX: !!! SECURITY WARNING !!!

cookiecutter/{{cookiecutter.github_repo_name}}/.github/workflows/release-notes-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ on:
1616
jobs:
1717
check-release-notes:
1818
name: Check release notes are updated
19-
runs-on: ubuntu-latest
19+
runs-on: ubuntu-slim
2020
permissions:
2121
pull-requests: read
2222
steps:

tests_golden/integration/test_cookiecutter_generation/actor/frequenz-actor-test/.github/workflows/auto-dependabot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ permissions:
1010
jobs:
1111
auto-merge:
1212
if: github.actor == 'dependabot[bot]'
13-
runs-on: ubuntu-latest
13+
runs-on: ubuntu-slim
1414
steps:
1515
- name: Auto-merge Dependabot PR
1616
uses: frequenz-floss/dependabot-auto-approve@3cad5f42e79296505473325ac6636be897c8b8a1 # v1.3.2

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
needs: ["nox"]
6464
# We skip this job only if nox was also skipped
6565
if: always() && needs.nox.result != 'skipped'
66-
runs-on: ubuntu-24.04
66+
runs-on: ubuntu-slim
6767
env:
6868
DEPS_RESULT: ${{ needs.nox.result }}
6969
steps:
@@ -172,7 +172,7 @@ jobs:
172172
needs: ["test-installation"]
173173
# We skip this job only if test-installation was also skipped
174174
if: always() && needs.test-installation.result != 'skipped'
175-
runs-on: ubuntu-24.04
175+
runs-on: ubuntu-slim
176176
env:
177177
DEPS_RESULT: ${{ needs.test-installation.result }}
178178
steps:
@@ -295,7 +295,7 @@ jobs:
295295
# discussions to create the release announcement in the discussion forums
296296
contents: write
297297
discussions: write
298-
runs-on: ubuntu-24.04
298+
runs-on: ubuntu-slim
299299
steps:
300300
- name: Download distribution files
301301
uses: actions/download-artifact@v4
@@ -337,7 +337,7 @@ jobs:
337337
publish-to-pypi:
338338
name: Publish packages to PyPI
339339
needs: ["create-github-release"]
340-
runs-on: ubuntu-24.04
340+
runs-on: ubuntu-slim
341341
permissions:
342342
# For trusted publishing. See:
343343
# https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/

0 commit comments

Comments
 (0)