Files
nyaterm/scripts/ci/test_scripts.py
T
Kang c092b70736 feat(ci): add Rust toolchain and formatting configuration
- Introduced `rust-toolchain.toml` to specify Rust version 1.99.1 with a minimal profile.
- Added `rustfmt.toml` to enforce the 2024 edition style for Rust formatting.
- Updated GitHub Actions workflows to read the Rust toolchain version dynamically and adjusted caching strategies accordingly.
- Enhanced CI workflows with orchestrate jobs for better job selection and dependency management.
- Implemented scheduled runs for CI workflows to ensure regular checks.
2026-11-07 10:55:14 +08:00

58 lines
2.3 KiB
Python

"""Discover script regressions and explicitly select native build integration tests."""
from __future__ import annotations
import argparse
import os
from pathlib import Path
import shutil
import sys
import unittest
ROOT = Path(__file__).resolve().parents[2]
NATIVE = {
"windows-resources": ("scripts.tests.test_windows_resources.WindowsResourcesTests", ("cargo", "rustc")),
"windows-msi": ("scripts.tests.test_windows_msi.CompiledWindowsMsiTests", ("wix",)),
"diagnostic": ("scripts.tests.test_package_diagnostic.DiagnosticRuntimeTests", ("cargo", "rustc")),
}
def cases(suite):
for item in suite:
if isinstance(item, unittest.TestSuite):
yield from cases(item)
else:
yield item
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--suite", choices=("common", *NATIVE), default="common")
args = parser.parse_args()
sys.path.insert(0, str(ROOT))
if args.suite != "common":
name, tools = NATIVE[args.suite]
if sys.platform != "win32" or any(shutil.which(tool) is None for tool in tools):
if summary := os.environ.get("GITHUB_STEP_SUMMARY"):
with open(summary, "a", encoding="utf-8") as stream:
stream.write(f"\nScript tests ({args.suite}): blocked, 0 run. "
f"Requires Windows and tools: {', '.join(tools)}.\n")
parser.error(f"{args.suite} requires Windows and tools: {', '.join(tools)}")
suite = unittest.defaultTestLoader.loadTestsFromName(name)
else:
discovered = unittest.defaultTestLoader.discover(str(ROOT / "scripts/tests"), top_level_dir=str(ROOT))
excluded = tuple(name + "." for name, _ in NATIVE.values())
suite = unittest.TestSuite(test for test in cases(discovered) if not test.id().startswith(excluded))
result = unittest.TextTestRunner(verbosity=2).run(suite)
if summary := os.environ.get("GITHUB_STEP_SUMMARY"):
with open(summary, "a", encoding="utf-8") as stream:
stream.write(f"\nScript tests ({args.suite}): {result.testsRun} run, "
f"{len(result.skipped)} skipped, {len(result.failures)} failures, "
f"{len(result.errors)} errors.\n")
return 0 if result.wasSuccessful() else 1
if __name__ == "__main__":
raise SystemExit(main())