Skip to content
Open
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
38 changes: 34 additions & 4 deletions bin/run_example_ci_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import os
import re
import shutil
import subprocess
import sys
Expand All @@ -13,7 +14,7 @@

import click

DIR = Path(__file__).parent.resolve()
DIR = Path(__file__).parent.parent.resolve()


def shell(cmd: str, *, check: bool, **kwargs: object) -> subprocess.CompletedProcess[str]:
Expand All @@ -38,6 +39,29 @@ class CIService(typing.NamedTuple):
name: str
dst_config_path: str
badge_md: str
config_file_transform: typing.Callable[[str], str] = lambda x: x # identity by default


def github_config_file_transform(content: str) -> str:
# one of the the github configs only builds on main, so we need to remove that restriction
# so our example build will run on the test branch.
#
# replace:
# """
# push:
# branches:
# - main
# """
# with:
# """
# push:
# """"
content = re.sub(
r"push:\n\s+branches:\n\s+- main",
"push:",
content,
)
return content


services = [
Expand All @@ -54,7 +78,8 @@ class CIService(typing.NamedTuple):
CIService(
name="github",
dst_config_path=".github/workflows/example.yml",
badge_md="[![Build](https://github.com/pypa/cibuildwheel/workflows/Build/badge.svg?branch={branch})](https://github.com/pypa/cibuildwheel/actions)",
badge_md="[![Build](https://github.com/pypa/cibuildwheel/actions/workflows/example.yml/badge.svg?branch={branch})](https://github.com/pypa/cibuildwheel/actions?query=branch%3A{branch})",
config_file_transform=github_config_file_transform,
),
CIService(
name="travis-ci",
Expand Down Expand Up @@ -93,6 +118,8 @@ def run_example_ci_configs(config_files=None):

if len(config_files) == 0:
config_files = Path("examples").glob("*-minimal.yml")
else:
config_files = [Path(f) for f in config_files]

# check each CI service has at most 1 config file
configs_by_service = set()
Expand Down Expand Up @@ -125,12 +152,15 @@ def run_example_ci_configs(config_files=None):
dst_config_file = example_project / service.dst_config_path

dst_config_file.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(config_file, dst_config_file)

contents = config_file.read_text(encoding="utf8")
contents = service.config_file_transform(contents)
dst_config_file.write_text(contents, encoding="utf8")

subprocess.run(["git", "add", example_project], check=True)
message = textwrap.dedent(
f"""\
Test example minimal configs
Test example CI configs

Testing files: {[str(f) for f in config_files]}
Generated from branch: {previous_branch}
Expand Down
5 changes: 3 additions & 2 deletions examples/github-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@ jobs:
merge-multiple: true

- uses: pypa/gh-action-pypi-publish@release/v1
with:
# To test: repository-url: https://test.pypi.org/legacy/
# To test uploads to TestPyPI, uncomment the following:
# with:
# repository-url: https://test.pypi.org/legacy/
Loading