22
33
44import os
5+ import re
56import shutil
67import subprocess
78import sys
1314
1415import click
1516
16- DIR = Path (__file__ ).parent .resolve ()
17+ DIR = Path (__file__ ).parent .parent . resolve ()
1718
1819
1920def shell (cmd : str , * , check : bool , ** kwargs : object ) -> subprocess .CompletedProcess [str ]:
@@ -38,6 +39,29 @@ class CIService(typing.NamedTuple):
3839 name : str
3940 dst_config_path : str
4041 badge_md : str
42+ config_file_transform : typing .Callable [[str ], str ] = lambda x : x # identity by default
43+
44+
45+ def github_config_file_transform (content : str ) -> str :
46+ # one of the the github configs only builds on main, so we need to remove that restriction
47+ # so our example build will run on the test branch.
48+ #
49+ # replace:
50+ # """
51+ # push:
52+ # branches:
53+ # - main
54+ # """
55+ # with:
56+ # """
57+ # push:
58+ # """"
59+ content = re .sub (
60+ r"push:\n\s+branches:\n\s+- main" ,
61+ "push:" ,
62+ content ,
63+ )
64+ return content
4165
4266
4367services = [
@@ -54,7 +78,8 @@ class CIService(typing.NamedTuple):
5478 CIService (
5579 name = "github" ,
5680 dst_config_path = ".github/workflows/example.yml" ,
57- badge_md = "[](https://github.com/pypa/cibuildwheel/actions)" ,
81+ badge_md = "[](https://github.com/pypa/cibuildwheel/actions?query=branch%3A{branch})" ,
82+ config_file_transform = github_config_file_transform ,
5883 ),
5984 CIService (
6085 name = "travis-ci" ,
@@ -93,6 +118,8 @@ def run_example_ci_configs(config_files=None):
93118
94119 if len (config_files ) == 0 :
95120 config_files = Path ("examples" ).glob ("*-minimal.yml" )
121+ else :
122+ config_files = [Path (f ) for f in config_files ]
96123
97124 # check each CI service has at most 1 config file
98125 configs_by_service = set ()
@@ -125,12 +152,15 @@ def run_example_ci_configs(config_files=None):
125152 dst_config_file = example_project / service .dst_config_path
126153
127154 dst_config_file .parent .mkdir (parents = True , exist_ok = True )
128- shutil .copyfile (config_file , dst_config_file )
155+
156+ contents = config_file .read_text (encoding = "utf8" )
157+ contents = service .config_file_transform (contents )
158+ dst_config_file .write_text (contents , encoding = "utf8" )
129159
130160 subprocess .run (["git" , "add" , example_project ], check = True )
131161 message = textwrap .dedent (
132162 f"""\
133- Test example minimal configs
163+ Test example CI configs
134164
135165 Testing files: { [str (f ) for f in config_files ]}
136166 Generated from branch: { previous_branch }
0 commit comments