Skip to content

Use the new private ARM runner for private repositories #413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: v0.x.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
matrix:
arch:
- amd64
- arm
- arm64
os:
- ubuntu-24.04
python:
Expand All @@ -41,7 +41,7 @@ jobs:
# that uses the same venv to run multiple linting sessions
- "ci_checks_max"
- "pytest_min"
runs-on: ${{ matrix.os }}${{ matrix.arch != 'amd64' && format('-{0}', matrix.arch) || '' }}
runs-on: ${{ matrix.os }}${{ matrix.arch == 'arm64' && (github.repository_visibility == 'private' && '-arm64' || '-arm') || '' }}

steps:
- name: Run nox
Expand Down Expand Up @@ -107,13 +107,13 @@ jobs:
matrix:
arch:
- amd64
- arm
- arm64
os:
- ubuntu-24.04
python:
- "3.11"
- "3.12"
runs-on: ${{ matrix.os }}${{ matrix.arch != 'amd64' && format('-{0}', matrix.arch) || '' }}
runs-on: ${{ matrix.os }}${{ matrix.arch == 'arm64' && (github.repository_visibility == 'private' && '-arm64' || '-arm') || '' }}

steps:
- name: Setup Git
Expand Down
4 changes: 3 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ But you might still need to adapt your code:
### Cookiecutter template

- New warning ignores for protobuf gencode versions in pytest.
- mkdocstrings: Updated the deprecated `import` config key to `inventories` in `mkdocs.yml`.

## Bug Fixes

<!-- Here goes notable bug fixes that are worth a special mention or explanation -->

### Cookiecutter template

<!-- Here bug fixes for cookiecutter specifically -->
- mkdocstrings: Move `paths` key to the right section in `mkdocs.yml`.
- The CI workflow now uses the new private ARM runner for private repositories (and the public ARM runners for public repositories).
108 changes: 108 additions & 0 deletions cookiecutter/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ def main() -> None:
# Add a separation line like this one after each migration step.
print("=" * 72)
migrate_filterwarnings(Path("pyproject.toml"))
print(
"Renaming the deprecated mkdocstrings `import` to `inventories` in `mkdocs.yml`..."
)
print("=" * 72)
replace_file_contents_atomically(
"mkdocs.yml", " import:", " inventories:"
)
print("=" * 72)
print("Fixing wrongly located `paths` keys in mkdocs.yml...")
migrate_mkdocs_yaml(Path("mkdocs.yml"))
print("=" * 72)
print("Migrating GitHub workflows to use the new arm64 runner...")
workflow_dir = Path(".github/workflows")
for workflow_file in [workflow_dir / "release.yaml", workflow_dir / "ci.yaml"]:
migrate_arm64_ci_yaml(workflow_file)
print("=" * 72)
print("Migration script finished. Remember to follow any manual instructions.")
print("=" * 72)
Expand Down Expand Up @@ -152,6 +167,99 @@ def migrate_filterwarnings(path: Path) -> None:
)


def migrate_mkdocs_yaml(file_path: Path) -> None:
"""Migrate the mkdocs.yml file to fix the `paths` key location."""
if not file_path.is_file():
manual_step(f"File {file_path} does not exist, skipping automatic migration.")
return

python_section = " python:"
options_section = " options:"
bad_paths_config = " paths:"

lines = file_path.read_text(encoding="utf-8").splitlines(keepends=True)
needs_migration = False
paths = ""
in_python = False
in_options = False

# 1) Detect whether there's a python_section followed by options_section
# and then bad_paths_config in that block.
for line in lines:
if line.startswith(python_section):
in_python = True
in_options = False
continue
if in_python and line.startswith(options_section):
in_options = True
continue
if in_options and line.startswith(bad_paths_config):
needs_migration = True
paths = line[len(bad_paths_config) :].strip()
break
# If indentation drops back below python-level, stop looking in this block
if in_python and not line.startswith(" ") and not line.isspace():
in_python = False
in_options = False

if not needs_migration:
return

# 2) Perform the line-based rewrite:
new_lines: list[str] = []
inserted_paths = False

for line in lines:
# When we hit the python_section line, insert new paths config directly under it
if line.startswith(python_section) and not inserted_paths:
new_lines.append(line)
new_lines.append(f" paths: {paths}\n")
inserted_paths = True
continue

# After inserting, drop the old " paths:" line
if inserted_paths and line.startswith(bad_paths_config):
continue

new_lines.append(line)

file_path.write_text("".join(new_lines), encoding="utf-8")


def migrate_arm64_ci_yaml(file_path: Path) -> None:
"""Migrate the CI YAML file to use arm64 architecture."""
print(f" - {file_path}")
if not file_path.is_file():
manual_step(f"File {file_path} does not exist, skipping automatic migration.")
return

lines = file_path.read_text(encoding="utf-8").splitlines(keepends=True)
new_lines: list[str] = []

for line in lines:
# 1) Replace "- arm" with "- arm64" (preserve indentation)
if match := re.match(r"^(\s*)-\s*arm(64)?\s*$", line):
indent = match.group(1)
new_lines.append(f"{indent}- arm64\n")
continue

# 2) Update the runs-on line
if match := re.match(r"^(\s*)runs-on:\s*\$\{\{.*matrix\.arch.*\}\}\s*$", line):
indent = match.group(1)
new_line = (
f"{indent}runs-on: ${{{{ matrix.os }}}}"
f"${{{{ matrix.arch == 'arm64' && "
f"(github.repository_visibility == 'private' && '-arm64' || '-arm') || '' }}}}\n"
)
new_lines.append(new_line)
continue

# Otherwise, keep the line as-is
new_lines.append(line)

file_path.write_text("".join(new_lines), encoding="utf-8")


def apply_patch(patch_content: str) -> None:
"""Apply a patch using the patch utility."""
subprocess.run(["patch", "-p1"], input=patch_content.encode(), check=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
matrix:
arch:
- amd64
- arm
- arm64
os:
- ubuntu-24.04
python:
Expand All @@ -74,7 +74,7 @@ jobs:
# that uses the same venv to run multiple linting sessions
- "ci_checks_max"
- "pytest_min"
runs-on: ${{ matrix.os }}${{ matrix.arch != 'amd64' && format('-{0}', matrix.arch) || '' }}
runs-on: ${{ matrix.os }}${{ matrix.arch == 'arm64' && (github.repository_visibility == 'private' && '-arm64' || '-arm') || '' }}

steps:
- name: Run nox
Expand Down Expand Up @@ -147,13 +147,13 @@ jobs:
matrix:
arch:
- amd64
- arm
- arm64
os:
- ubuntu-24.04
python:
- "3.11"
- "3.12"
runs-on: ${{ matrix.os }}${{ matrix.arch != 'amd64' && format('-{0}', matrix.arch) || '' }}
runs-on: ${{ matrix.os }}${{ matrix.arch == 'arm64' && (github.repository_visibility == 'private' && '-arm64' || '-arm') || '' }}

steps:
- name: Setup Git
Expand Down
4 changes: 2 additions & 2 deletions cookiecutter/{{cookiecutter.github_repo_name}}/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ plugins:
default_handler: python
handlers:
python:
paths: ["{{cookiecutter | src_path}}"]
options:
paths: ["{{cookiecutter | src_path}}"]
docstring_section_style: spacy
inherited_members: true
merge_init_into_class: false
Expand All @@ -116,7 +116,7 @@ plugins:
show_source: true
show_symbol_type_toc: true
signature_crossrefs: true
import:
inventories:
# TODO(cookiecutter): You might want to add other external references here
# See https://mkdocstrings.github.io/python/usage/#import for details
- https://docs.python.org/3/objects.inv
Expand Down
4 changes: 2 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ plugins:
default_handler: python
handlers:
python:
paths: ["src"]
options:
paths: ["src"]
docstring_section_style: spacy
inherited_members: true
merge_init_into_class: false
Expand All @@ -114,7 +114,7 @@ plugins:
show_source: true
show_symbol_type_toc: true
signature_crossrefs: true
import:
inventories:
- https://cookiecutter.readthedocs.io/en/stable/objects.inv
- https://docs.python.org/3/objects.inv
- https://mkdocstrings.github.io/objects.inv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
matrix:
arch:
- amd64
- arm
- arm64
os:
- ubuntu-24.04
python:
Expand All @@ -41,7 +41,7 @@ jobs:
# that uses the same venv to run multiple linting sessions
- "ci_checks_max"
- "pytest_min"
runs-on: ${{ matrix.os }}${{ matrix.arch != 'amd64' && format('-{0}', matrix.arch) || '' }}
runs-on: ${{ matrix.os }}${{ matrix.arch == 'arm64' && (github.repository_visibility == 'private' && '-arm64' || '-arm') || '' }}

steps:
- name: Run nox
Expand Down Expand Up @@ -114,13 +114,13 @@ jobs:
matrix:
arch:
- amd64
- arm
- arm64
os:
- ubuntu-24.04
python:
- "3.11"
- "3.12"
runs-on: ${{ matrix.os }}${{ matrix.arch != 'amd64' && format('-{0}', matrix.arch) || '' }}
runs-on: ${{ matrix.os }}${{ matrix.arch == 'arm64' && (github.repository_visibility == 'private' && '-arm64' || '-arm') || '' }}

steps:
- name: Setup Git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ plugins:
default_handler: python
handlers:
python:
paths: ["src"]
options:
paths: ["src"]
docstring_section_style: spacy
inherited_members: true
merge_init_into_class: false
Expand All @@ -116,7 +116,7 @@ plugins:
show_source: true
show_symbol_type_toc: true
signature_crossrefs: true
import:
inventories:
# TODO(cookiecutter): You might want to add other external references here
# See https://mkdocstrings.github.io/python/usage/#import for details
- https://docs.python.org/3/objects.inv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
matrix:
arch:
- amd64
- arm
- arm64
os:
- ubuntu-24.04
python:
Expand All @@ -71,7 +71,7 @@ jobs:
# that uses the same venv to run multiple linting sessions
- "ci_checks_max"
- "pytest_min"
runs-on: ${{ matrix.os }}${{ matrix.arch != 'amd64' && format('-{0}', matrix.arch) || '' }}
runs-on: ${{ matrix.os }}${{ matrix.arch == 'arm64' && (github.repository_visibility == 'private' && '-arm64' || '-arm') || '' }}

steps:
- name: Run nox
Expand Down Expand Up @@ -144,13 +144,13 @@ jobs:
matrix:
arch:
- amd64
- arm
- arm64
os:
- ubuntu-24.04
python:
- "3.11"
- "3.12"
runs-on: ${{ matrix.os }}${{ matrix.arch != 'amd64' && format('-{0}', matrix.arch) || '' }}
runs-on: ${{ matrix.os }}${{ matrix.arch == 'arm64' && (github.repository_visibility == 'private' && '-arm64' || '-arm') || '' }}

steps:
- name: Setup Git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ plugins:
default_handler: python
handlers:
python:
paths: ["py"]
options:
paths: ["py"]
docstring_section_style: spacy
inherited_members: true
merge_init_into_class: false
Expand All @@ -116,7 +116,7 @@ plugins:
show_source: true
show_symbol_type_toc: true
signature_crossrefs: true
import:
inventories:
# TODO(cookiecutter): You might want to add other external references here
# See https://mkdocstrings.github.io/python/usage/#import for details
- https://docs.python.org/3/objects.inv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
matrix:
arch:
- amd64
- arm
- arm64
os:
- ubuntu-24.04
python:
Expand All @@ -41,7 +41,7 @@ jobs:
# that uses the same venv to run multiple linting sessions
- "ci_checks_max"
- "pytest_min"
runs-on: ${{ matrix.os }}${{ matrix.arch != 'amd64' && format('-{0}', matrix.arch) || '' }}
runs-on: ${{ matrix.os }}${{ matrix.arch == 'arm64' && (github.repository_visibility == 'private' && '-arm64' || '-arm') || '' }}

steps:
- name: Run nox
Expand Down Expand Up @@ -114,13 +114,13 @@ jobs:
matrix:
arch:
- amd64
- arm
- arm64
os:
- ubuntu-24.04
python:
- "3.11"
- "3.12"
runs-on: ${{ matrix.os }}${{ matrix.arch != 'amd64' && format('-{0}', matrix.arch) || '' }}
runs-on: ${{ matrix.os }}${{ matrix.arch == 'arm64' && (github.repository_visibility == 'private' && '-arm64' || '-arm') || '' }}

steps:
- name: Setup Git
Expand Down
Loading
Loading