2
2
3
3
4
4
import os
5
+ import re
5
6
import shutil
6
7
import subprocess
7
8
import sys
13
14
14
15
import click
15
16
16
- DIR = Path (__file__ ).parent .resolve ()
17
+ DIR = Path (__file__ ).parent .parent . resolve ()
17
18
18
19
19
20
def shell (cmd : str , * , check : bool , ** kwargs : object ) -> subprocess .CompletedProcess [str ]:
@@ -38,6 +39,29 @@ class CIService(typing.NamedTuple):
38
39
name : str
39
40
dst_config_path : str
40
41
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
41
65
42
66
43
67
services = [
@@ -54,7 +78,8 @@ class CIService(typing.NamedTuple):
54
78
CIService (
55
79
name = "github" ,
56
80
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 ,
58
83
),
59
84
CIService (
60
85
name = "travis-ci" ,
@@ -93,6 +118,8 @@ def run_example_ci_configs(config_files=None):
93
118
94
119
if len (config_files ) == 0 :
95
120
config_files = Path ("examples" ).glob ("*-minimal.yml" )
121
+ else :
122
+ config_files = [Path (f ) for f in config_files ]
96
123
97
124
# check each CI service has at most 1 config file
98
125
configs_by_service = set ()
@@ -125,12 +152,15 @@ def run_example_ci_configs(config_files=None):
125
152
dst_config_file = example_project / service .dst_config_path
126
153
127
154
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" )
129
159
130
160
subprocess .run (["git" , "add" , example_project ], check = True )
131
161
message = textwrap .dedent (
132
162
f"""\
133
- Test example minimal configs
163
+ Test example CI configs
134
164
135
165
Testing files: { [str (f ) for f in config_files ]}
136
166
Generated from branch: { previous_branch }
0 commit comments