Skip to content

Commit a5bcbaa

Browse files
authored
ci: Fix runner for publish-to-pypi (#532)
The `pypa/gh-action-pypi-publish` action needs docker to run, and the ubuntu-slim runner doesn't provide docker, so we need to use a full ubuntu image instead. The migration script is also updated to update the runner to ubuntu-24.04 to get reproducible builds (it was ubuntu-latest before).
2 parents 13ff74d + 731fc90 commit a5bcbaa

9 files changed

Lines changed: 51 additions & 23 deletions

File tree

  • .github/workflows
  • cookiecutter
  • tests_golden/integration/test_cookiecutter_generation
    • actor/frequenz-actor-test/.github/workflows
    • api/frequenz-api-test/.github/workflows
    • app/frequenz-app-test/.github/workflows
    • lib/frequenz-test-python/.github/workflows
    • model/frequenz-model-test/.github/workflows

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ jobs:
314314
publish-to-pypi:
315315
name: Publish packages to PyPI
316316
needs: ["create-github-release"]
317-
runs-on: ubuntu-slim
317+
runs-on: ubuntu-24.04
318318
permissions:
319319
# For trusted publishing. See:
320320
# https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/

RELEASE_NOTES.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Frequenz Repository Configuration Release Notes
22

3+
> [!NOTE]
4+
> This is a bugfix release for v0.15.0. This release was never published to PyPI, so we keep the entire release notes for v0.15.0 here (updated to the new changes) to make it easier for users to upgrade from v0.14.0 to v0.15.x.
5+
>
6+
> The only change with respect to v0.15.0 is using the appropriate job runner for the `publish-to-pypi` job in `ci.yaml`. v0.15.0 updated it to `ubuntu-slim` but that didn't work because it requires Docker, and it is not installed on the `ubuntu-slim` runner.
7+
38
## Summary
49

510
This release reduces CI cost by moving lightweight GitHub Actions jobs to the new `ubuntu-slim` runner, fixes Dependabot auto-merge/merge-queue issues by switching to a GitHub App installation token, and introduces an automated repo-config migration workflow (including updating existing repos' version-branch protection defaults).
@@ -28,13 +33,15 @@ But you might still need to adapt your code:
2833

2934
- Migrated lightweight workflow jobs to use the new `ubuntu-slim` runner for cost savings.
3035
The following jobs now use `ubuntu-slim`:
31-
- `ci.yaml`: `protolint`, `nox-all`, `test-installation-all`, `create-github-release`, `publish-to-pypi`
36+
- `ci.yaml`: `protolint`, `nox-all`, `test-installation-all`, `create-github-release`
3237
- `ci-pr.yaml`: `protolint`
3338
- `auto-dependabot.yaml`: `auto-merge`
3439
- `release-notes-check.yml`: `check-release-notes`
3540
- `dco-merge-queue.yml`: `DCO`
3641
- `labeler.yml`: `Label`
3742

43+
- Migrated the `publish-to-pypi` job in `ci.yaml` from `ubuntu-latest` to `ubuntu-24.04` to get reproducible builds.
44+
3845
- Added the [`flake8-datetimez`](https://github.com/pjknkda/flake8-datetimez) plugin to the `flake8` session. This plugin prevents accidental use of naive `datetime` objects by flagging calls that create or return datetimes without timezone information.
3946

4047
- The CI workflow now uses a simpler matrix.

cookiecutter/migrate.py

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ def main() -> None:
4242
print("Migrating workflows to use ubuntu-slim runner for lightweight jobs...")
4343
migrate_to_ubuntu_slim()
4444
print("=" * 72)
45+
print("Migrating publish-to-pypi workflow runner to ubuntu-24.04...")
46+
migrate_publish_to_pypi_runner()
47+
print("=" * 72)
4548
print("Migrating pyproject license metadata to SPDX format...")
4649
migrate_pyproject_license()
4750
print("=" * 72)
@@ -94,9 +97,7 @@ def migrate_to_ubuntu_slim() -> None:
9497
"""
9598
workflows_dir = Path(".github") / "workflows"
9699
project_type = read_project_type()
97-
github_org = read_cookiecutter_github_org()
98100
include_protolint = project_type == "api"
99-
include_publish_to_pypi = github_org == "frequenz-floss"
100101
if project_type is None:
101102
include_protolint = True
102103
manual_step(
@@ -178,19 +179,6 @@ def migrate_to_ubuntu_slim() -> None:
178179
}
179180
],
180181
}
181-
if include_publish_to_pypi:
182-
migrations["ci.yaml"].append(
183-
{
184-
"job": "publish-to-pypi",
185-
"old": (
186-
' needs: ["create-github-release"]\n runs-on: ubuntu-24.04'
187-
),
188-
"new": (
189-
' needs: ["create-github-release"]\n runs-on: ubuntu-slim'
190-
),
191-
}
192-
)
193-
194182
if include_protolint:
195183
protolint_rule = {
196184
"job": "protolint",
@@ -238,6 +226,39 @@ def migrate_to_ubuntu_slim() -> None:
238226
)
239227

240228

229+
def migrate_publish_to_pypi_runner() -> None:
230+
"""Migrate the publish-to-pypi CI job runner to ubuntu-24.04."""
231+
github_org = read_cookiecutter_github_org()
232+
if github_org != "frequenz-floss":
233+
print(" Skipping .github/workflows/ci.yaml (publish-to-pypi not expected)")
234+
return
235+
236+
filepath = Path(".github") / "workflows" / "ci.yaml"
237+
if not filepath.exists():
238+
print(f" Skipping {filepath} (file not found)")
239+
return
240+
241+
old = ' needs: ["create-github-release"]\n runs-on: ubuntu-latest'
242+
new = ' needs: ["create-github-release"]\n runs-on: ubuntu-24.04'
243+
content = filepath.read_text(encoding="utf-8")
244+
245+
if old in content:
246+
replace_file_contents_atomically(filepath, old, new)
247+
print(f" Updated {filepath}: migrated runner for job publish-to-pypi")
248+
return
249+
250+
if new in content:
251+
print(
252+
f" Skipped {filepath}: runner already up to date for job publish-to-pypi"
253+
)
254+
return
255+
256+
manual_step(
257+
f" Pattern not found in {filepath}: please switch the runner for job "
258+
"publish-to-pypi according to the latest template."
259+
)
260+
261+
241262
def migrate_pyproject_license() -> None: # pylint: disable=too-many-branches
242263
"""Migrate pyproject license metadata to SPDX expressions."""
243264
pyproject_path = Path("pyproject.toml")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ jobs:
366366
publish-to-pypi:
367367
name: Publish packages to PyPI
368368
needs: ["create-github-release"]
369-
runs-on: ubuntu-slim
369+
runs-on: ubuntu-24.04
370370
permissions:
371371
# For trusted publishing. See:
372372
# https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ jobs:
333333
publish-to-pypi:
334334
name: Publish packages to PyPI
335335
needs: ["create-github-release"]
336-
runs-on: ubuntu-slim
336+
runs-on: ubuntu-24.04
337337
permissions:
338338
# For trusted publishing. See:
339339
# https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/

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
@@ -363,7 +363,7 @@ jobs:
363363
publish-to-pypi:
364364
name: Publish packages to PyPI
365365
needs: ["create-github-release"]
366-
runs-on: ubuntu-slim
366+
runs-on: ubuntu-24.04
367367
permissions:
368368
# For trusted publishing. See:
369369
# https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ jobs:
333333
publish-to-pypi:
334334
name: Publish packages to PyPI
335335
needs: ["create-github-release"]
336-
runs-on: ubuntu-slim
336+
runs-on: ubuntu-24.04
337337
permissions:
338338
# For trusted publishing. See:
339339
# https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ jobs:
333333
publish-to-pypi:
334334
name: Publish packages to PyPI
335335
needs: ["create-github-release"]
336-
runs-on: ubuntu-slim
336+
runs-on: ubuntu-24.04
337337
permissions:
338338
# For trusted publishing. See:
339339
# https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ jobs:
333333
publish-to-pypi:
334334
name: Publish packages to PyPI
335335
needs: ["create-github-release"]
336-
runs-on: ubuntu-slim
336+
runs-on: ubuntu-24.04
337337
permissions:
338338
# For trusted publishing. See:
339339
# https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/

0 commit comments

Comments
 (0)