Skip to content

Commit 3a52416

Browse files
authored
Fix a few bugs in run_example_ci_config tooling (#2577)
* Fix a few bugs in run_example_ci_config tooling Github-deploy.yml had a fix to make it work out-of-the-box. * Add flaky marker on test_ssl (due to external internet access during the test, it does occasionally fail)
1 parent c294bab commit 3a52416

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

bin/run_example_ci_configs.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
import os
5+
import re
56
import shutil
67
import subprocess
78
import sys
@@ -13,7 +14,7 @@
1314

1415
import click
1516

16-
DIR = Path(__file__).parent.resolve()
17+
DIR = Path(__file__).parent.parent.resolve()
1718

1819

1920
def 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

4367
services = [
@@ -54,7 +78,8 @@ class CIService(typing.NamedTuple):
5478
CIService(
5579
name="github",
5680
dst_config_path=".github/workflows/example.yml",
57-
badge_md="[![Build](https://github.com/pypa/cibuildwheel/workflows/Build/badge.svg?branch={branch})](https://github.com/pypa/cibuildwheel/actions)",
81+
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})",
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}

examples/github-deploy.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,6 @@ jobs:
9898
merge-multiple: true
9999

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

test/test_ssl.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import socket
22
import textwrap
33

4+
import pytest
5+
46
from . import test_projects, utils
57

68
project_with_ssl_tests = test_projects.new_c_project(
@@ -19,6 +21,7 @@
1921
)
2022

2123

24+
@pytest.mark.flaky(reruns=2)
2225
def test(tmp_path):
2326
# this test checks that SSL is working in the build environment using
2427
# some checks in setup.py.

0 commit comments

Comments
 (0)