Skip to content

Commit 68183cd

Browse files
committed
Adding CI.
1 parent c1765c1 commit 68183cd

70 files changed

Lines changed: 5560 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/scripts/build_and_test.py

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/usr/bin/env python3
2+
"""Build and test mp313 packages using MonolithPy."""
3+
4+
import json
5+
import os
6+
import platform
7+
import shutil
8+
import subprocess
9+
import sys
10+
from pathlib import Path
11+
12+
13+
def get_monolithpy_executable(monolithpy_dir: Path) -> Path:
14+
"""Get the MonolithPy executable path."""
15+
if platform.system() == "Windows":
16+
return monolithpy_dir / "python.exe"
17+
else:
18+
return monolithpy_dir / "bin" / "python3.13"
19+
20+
21+
def get_tests_from_index(index_path: Path) -> list[str]:
22+
"""Read test files from index.json."""
23+
if not index_path.exists():
24+
return []
25+
try:
26+
with open(index_path) as f:
27+
data = json.load(f)
28+
return data.get("tests", [])
29+
except (json.JSONDecodeError, KeyError):
30+
return []
31+
32+
33+
def clear_pip_cache():
34+
"""Clear pip cache, ignoring errors."""
35+
try:
36+
subprocess.run([sys.executable, "-m", "pip", "cache", "purge"],
37+
capture_output=True, check=False)
38+
except Exception:
39+
pass
40+
41+
42+
def run_build(monolithpy: Path, package_name: str) -> bool:
43+
"""Attempt to build a package. Returns True on success."""
44+
try:
45+
result = subprocess.run(
46+
[str(monolithpy), "-m", "pip", "install", "--verbose", package_name],
47+
capture_output=True, text=True
48+
)
49+
print(result.stdout)
50+
if result.stderr:
51+
print(result.stderr, file=sys.stderr)
52+
return result.returncode == 0
53+
except Exception as e:
54+
print(f"Build error: {e}", file=sys.stderr)
55+
return False
56+
57+
58+
def run_test(monolithpy: Path, test_path: Path) -> bool:
59+
"""Run a test file. Returns True on success."""
60+
try:
61+
result = subprocess.run(
62+
[str(monolithpy), str(test_path)],
63+
capture_output=True, text=True
64+
)
65+
print(result.stdout)
66+
if result.stderr:
67+
print(result.stderr, file=sys.stderr)
68+
return result.returncode == 0
69+
except Exception as e:
70+
print(f"Test error: {e}", file=sys.stderr)
71+
return False
72+
73+
74+
def main():
75+
root_dir = Path.cwd()
76+
monolithpy_dir = root_dir / "monolithpy"
77+
78+
# Determine platform-specific package directory
79+
if platform.system() == "Windows":
80+
packages_dir = root_dir / "packages" / "mp313-windows"
81+
elif platform.system() == "Darwin":
82+
packages_dir = root_dir / "packages" / "mp313-macos"
83+
else:
84+
print(f"Unsupported platform: {platform.system()}", file=sys.stderr)
85+
sys.exit(1)
86+
87+
# Get MonolithPy executable
88+
monolithpy = get_monolithpy_executable(monolithpy_dir)
89+
print(f"MonolithPy location: {monolithpy}")
90+
if not monolithpy.exists():
91+
print(f"::error::MonolithPy executable not found at {monolithpy}", file=sys.stderr)
92+
sys.exit(1)
93+
94+
work_dir = root_dir / "work"
95+
96+
for pkg_dir in sorted(packages_dir.iterdir()):
97+
if not pkg_dir.is_dir():
98+
continue
99+
100+
pkg_name = pkg_dir.name
101+
print(f"::group::Building {pkg_name}")
102+
103+
# Make a fresh copy of MonolithPy
104+
pkg_work_dir = work_dir / pkg_name
105+
pkg_work_dir.mkdir(parents=True, exist_ok=True)
106+
shutil.copytree(monolithpy_dir, pkg_work_dir / "monolithpy", dirs_exist_ok=True)
107+
108+
clear_pip_cache()
109+
110+
build_script = pkg_dir / "build.py"
111+
if not build_script.exists():
112+
print(f"No build.py found for {pkg_name}, skipping")
113+
print("::endgroup::")
114+
continue
115+
116+
print(f"Building {pkg_name}...")
117+
if run_build(monolithpy, pkg_name):
118+
print(f"Build successful for {pkg_name}")
119+
120+
# Check for and run tests
121+
tests = get_tests_from_index(pkg_dir / "index.json")
122+
for test_file in tests:
123+
test_path = pkg_dir / test_file
124+
if test_path.exists():
125+
print(f"Running test: {test_file}")
126+
if run_test(monolithpy, test_path):
127+
print(f"Test passed for {pkg_name}/{test_file}")
128+
else:
129+
print(f"::warning::Test failed for {pkg_name}/{test_file}")
130+
else:
131+
print(f"::warning::Build failed for {pkg_name}")
132+
133+
print("::endgroup::")
134+
135+
136+
if __name__ == "__main__":
137+
main()
138+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: mp313 Build and Test
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build-and-test-windows:
8+
runs-on: windows-latest
9+
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v4
13+
14+
- name: Get MonolithPy artifact
15+
uses: dawidd6/action-download-artifact@v6
16+
with:
17+
repo: Nuitka/MonolithPy
18+
workflow: main.yml
19+
workflow_conclusion: success
20+
branch: 3.13
21+
name: MonolithPy313_windows_x64
22+
path: monolithpy
23+
24+
- name: Set MONOLITHPY_PACKAGE_URL
25+
shell: pwsh
26+
run: |
27+
$packageUrl = "file:///$($pwd.Path -replace '\\','/')"
28+
echo "MONOLITHPY_PACKAGE_URL=$packageUrl" >> $env:GITHUB_ENV
29+
30+
- name: Build and test packages
31+
run: python .github/scripts/build_and_test.py
32+
33+
build-and-test-macos:
34+
runs-on: macos-14
35+
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v4
39+
40+
- name: Get MonolithPy artifact
41+
uses: dawidd6/action-download-artifact@v6
42+
with:
43+
repo: Nuitka/MonolithPy
44+
workflow: main.yml
45+
workflow_conclusion: success
46+
branch: 3.13
47+
name: MonolithPy313_mac_arm64_No_LTO
48+
path: monolithpy
49+
50+
- name: Set MONOLITHPY_PACKAGE_URL
51+
run: echo "MONOLITHPY_PACKAGE_URL=file://${PWD}" >> $GITHUB_ENV
52+
53+
- name: Make MonolithPy executable
54+
run: |
55+
chmod +x monolithpy/* 2>/dev/null || true
56+
find monolithpy -type f -name "python*" -exec chmod +x {} \; 2>/dev/null || true
57+
58+
- name: Build and test packages
59+
run: python3 .github/scripts/build_and_test.py
60+

packages/mp313-macos/certifi/index.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"tests": ["test.py"],
23
"scripts": [
34
{
45
"metadata": {
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
"""
2+
Basic sanity tests for certifi package.
3+
Tests certificate bundle functionality without extra dependencies.
4+
"""
5+
6+
import certifi
7+
import os
8+
9+
10+
def test_version():
11+
"""Test version is accessible."""
12+
assert hasattr(certifi, '__version__')
13+
assert certifi.__version__ is not None
14+
15+
16+
def test_where():
17+
"""Test certificate bundle path retrieval."""
18+
ca_bundle_path = certifi.where()
19+
20+
assert ca_bundle_path is not None
21+
assert isinstance(ca_bundle_path, str)
22+
assert os.path.isfile(ca_bundle_path)
23+
24+
25+
def test_contents():
26+
"""Test certificate bundle contents."""
27+
ca_bundle_path = certifi.where()
28+
29+
with open(ca_bundle_path, 'r') as f:
30+
contents = f.read()
31+
32+
# Should contain certificate markers
33+
assert '-----BEGIN CERTIFICATE-----' in contents
34+
assert '-----END CERTIFICATE-----' in contents
35+
36+
37+
def test_bundle_size():
38+
"""Test certificate bundle has reasonable size."""
39+
ca_bundle_path = certifi.where()
40+
41+
size = os.path.getsize(ca_bundle_path)
42+
43+
# Bundle should be at least 100KB (contains many certificates)
44+
assert size > 100000
45+
46+
47+
def test_multiple_certificates():
48+
"""Test bundle contains multiple certificates."""
49+
ca_bundle_path = certifi.where()
50+
51+
with open(ca_bundle_path, 'r') as f:
52+
contents = f.read()
53+
54+
# Count certificates
55+
cert_count = contents.count('-----BEGIN CERTIFICATE-----')
56+
57+
# Should have many root CA certificates
58+
assert cert_count > 50
59+
60+
61+
def test_path_consistency():
62+
"""Test path is consistent across calls."""
63+
path1 = certifi.where()
64+
path2 = certifi.where()
65+
66+
assert path1 == path2
67+
68+
69+
if __name__ == "__main__":
70+
test_version()
71+
test_where()
72+
test_contents()
73+
test_bundle_size()
74+
test_multiple_certificates()
75+
test_path_consistency()
76+
print("All certifi tests passed!")
77+

packages/mp313-macos/cffi/index.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"tests": ["test.py"],
23
"scripts": [
34
{
45
"metadata": {

0 commit comments

Comments
 (0)