Skip to content

Commit 60aa7a8

Browse files
committed
Only apply ubuntu-slim to publish-to-pypy for public repos
Private repos don't have a publish-to-pypi job. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
1 parent 7d0435d commit 60aa7a8

1 file changed

Lines changed: 37 additions & 5 deletions

File tree

cookiecutter/migrate.py

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ def migrate_to_ubuntu_slim() -> None:
8686
"""
8787
workflows_dir = Path(".github") / "workflows"
8888
project_type = read_project_type()
89+
github_org = read_cookiecutter_github_org()
8990
include_protolint = project_type == "api"
91+
include_publish_to_pypi = github_org == "frequenz-floss"
9092
if project_type is None:
9193
include_protolint = True
9294
manual_step(
@@ -125,11 +127,6 @@ def migrate_to_ubuntu_slim() -> None:
125127
"old": " discussions: write\n runs-on: ubuntu-24.04",
126128
"new": " discussions: write\n runs-on: ubuntu-slim",
127129
},
128-
{
129-
"job": "publish-to-pypi",
130-
"old": ' needs: ["create-github-release"]\n runs-on: ubuntu-24.04',
131-
"new": ' needs: ["create-github-release"]\n runs-on: ubuntu-slim',
132-
},
133130
],
134131
"release-notes-check.yml": [
135132
{
@@ -173,6 +170,19 @@ def migrate_to_ubuntu_slim() -> None:
173170
}
174171
],
175172
}
173+
if include_publish_to_pypi:
174+
migrations["ci.yaml"].append(
175+
{
176+
"job": "publish-to-pypi",
177+
"old": (
178+
' needs: ["create-github-release"]\n runs-on: ubuntu-24.04'
179+
),
180+
"new": (
181+
' needs: ["create-github-release"]\n runs-on: ubuntu-slim'
182+
),
183+
}
184+
)
185+
176186
if include_protolint:
177187
protolint_rule = {
178188
"job": "protolint",
@@ -517,6 +527,28 @@ def read_project_type() -> str | None:
517527
return project_type
518528

519529

530+
def read_cookiecutter_github_org() -> str | None:
531+
"""Read the cookiecutter GitHub organization from the replay file."""
532+
replay_path = Path(".cookiecutter-replay.json")
533+
if not replay_path.exists():
534+
return None
535+
536+
try:
537+
data = json.loads(replay_path.read_text(encoding="utf-8"))
538+
except (json.JSONDecodeError, OSError):
539+
return None
540+
541+
cookiecutter_data = data.get("cookiecutter")
542+
if not isinstance(cookiecutter_data, dict):
543+
return None
544+
545+
github_org = cookiecutter_data.get("github_org")
546+
if not isinstance(github_org, str):
547+
return None
548+
549+
return github_org
550+
551+
520552
def read_cookiecutter_license() -> str | None:
521553
"""Read the cookiecutter license from the replay file."""
522554
replay_path = Path(".cookiecutter-replay.json")

0 commit comments

Comments
 (0)