Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 5 additions & 3 deletions .github/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pytest==9.1.1
PyYAML==6.0.3
ruff==0.17.1
docutils==0.22.4
pytest==9.2.0
PyYAML==6.0.4
ruff==0.17.6
Sphinx==9.0.4
2 changes: 1 addition & 1 deletion .github/ruff.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# CI 脚本和测试与后端使用相同的 Python 风格。
# CI scripts and tests follow the backend's Python style.
extend = "../ruoyi-fastapi-backend/ruff.toml"
8 changes: 2 additions & 6 deletions .github/scripts/check_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def validate_configuration(config: dict[str, Any], framework: str, engine: str,
:param framework: 本次选择的框架
:param engine: my 或 pg
:param root: 仓库根目录
:return: None
:raises ValueError: 前端构建目录、Dockerfile、nginx 配置或后端所选框架不匹配
"""
expected = (root / 'ruoyi-fastapi-frontend' / framework / 'web').resolve()
services = config['services']
Expand All @@ -44,11 +44,7 @@ def validate_configuration(config: dict[str, Any], framework: str, engine: str,


def main() -> None:
"""
使用全部框架解析生产和测试 Compose,无需启动容器。

:return: None
"""
"""使用全部框架解析生产和测试 Compose,无需启动容器。"""
parser = argparse.ArgumentParser()
parser.add_argument('--docker', default='docker')
args = parser.parse_args()
Expand Down
7 changes: 2 additions & 5 deletions .github/scripts/check_test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def check_report(path: Path, *, allow_skips: bool = False) -> tuple[int, int]:
:param path: pytest JUnit 报告路径
:param allow_skips: 是否允许普通跨平台回归中的预期跳过
:return: 实际执行及跳过的测试数量
:raises ValueError: 没有实际执行用例、存在失败,或跳过了必须执行的用例
"""
root = ET.parse(path).getroot()
cases = root.findall('.//testcase')
Expand All @@ -22,11 +23,7 @@ def check_report(path: Path, *, allow_skips: bool = False) -> tuple[int, int]:


def main() -> None:
"""
检查报告并将执行数量写入 CI 摘要。

:return: None
"""
"""检查报告并将执行数量写入 CI 摘要。"""
parser = argparse.ArgumentParser()
parser.add_argument('report', type=Path)
parser.add_argument('--allow-skips', action='store_true')
Expand Down
5 changes: 2 additions & 3 deletions .github/scripts/ci_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

ROOT = Path(__file__).resolve().parents[2]
FRAMEWORKS = ('vue2', 'vue3', 'react')
PYTHON_VERSIONS = ('3.10', '3.11', '3.12', '3.13', '3.14')
PYTHON_VERSIONS = ('3.11', '3.12', '3.13', '3.14', '3.15')
CATEGORIES = ('quality', 'backend', 'frontend', 'integration', 'e2e', 'native')
FRONTEND_FILE_PATH_PARTS = 4

Expand Down Expand Up @@ -198,7 +198,6 @@ def write_outputs(plan: dict[str, Any]) -> None:
输出 GitHub 任务参数及可审阅的执行摘要。

:param plan: 本次运行计划
:return: None
"""
payload = {
**plan['required'],
Expand All @@ -222,7 +221,7 @@ def main() -> None:
"""
执行变更选路或最终结果校验。

:return: None
:raises SystemExit: 变更选路或最终结果校验失败
"""
parser = argparse.ArgumentParser()
parser.add_argument('command', choices=('plan', 'gate'))
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/install_ai_test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def main() -> None:
"""
从 AI 插件清单安装测试依赖,避免 CI 维护第二份版本列表。

:return: None
:raises ValueError: AI 插件 Python 依赖清单无效
"""
backend = Path(__file__).resolve().parents[2] / 'ruoyi-fastapi-backend'
manifest = yaml.safe_load((backend / 'plugins/ai/plugin.yaml').read_text(encoding='utf-8'))
Expand Down
25 changes: 15 additions & 10 deletions .github/scripts/mobile_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
TOKEN = 'isolated-mobile-smoke-token'
LOGIN_BUTTON_MIN_WIDTH = 250
LOGIN_BUTTON_MIN_HEIGHT = 44
NICKNAME = '移动端 CI'
USER = {
'userId': 7,
'userName': 'ci-user',
'nickName': '移动端 CI',
'nickName': NICKNAME,
'avatar': '',
'phonenumber': '13800000000',
'email': 'mobile-ci@example.test',
Expand All @@ -48,7 +49,6 @@ async def api(route: Route) -> None:
隔离 API 边界,记录真实构建发出的认证和时区请求。

:param route: 当前浏览器 API 请求
:return: None
"""
request = route.request
path = urlparse(request.url).path.removeprefix('/dev-api')
Expand Down Expand Up @@ -109,7 +109,14 @@ async def api(route: Route) -> None:


async def check_login_styles(framework: str, page: Page, login_button: Locator) -> dict[str, Any]:
"""验证移动端构建确实生成了布局、渐变和图标样式。"""
"""
验证移动端构建确实生成了布局、渐变和图标样式。

:param framework: 目标前端框架
:param page: 浏览器页面或要查询的页码
:param login_button: 提交登录表单的按钮
:return: 供调用方使用的 ``styles``
"""
styles = await login_button.evaluate(
"""element => {
const style = getComputedStyle(element)
Expand Down Expand Up @@ -148,7 +155,6 @@ def check_profile_requests(observed: list[dict[str, Any]]) -> None:
验证账号恢复后的认证、时区、语言与初始化请求头。

:param observed: 实际发出的 API 请求记录
:return: None
"""
profile_requests = [request for request in observed if request['path'] == '/system/user/profile']
assert profile_requests, '个人资料页未发送真实 API 请求'
Expand All @@ -165,7 +171,7 @@ async def run_smoke(framework: str, base_url: str, output: Path) -> None:
:param framework: vue2、vue3 或 react
:param base_url: 本次测试的开发服务器或静态文件服务器
:param output: 浏览器报告目录
:return: None
:raises BaseException: 执行中断,清理后向调用方传播原异常
"""
logs: list[str] = []
errors: list[str] = []
Expand All @@ -174,9 +180,7 @@ async def run_smoke(framework: str, base_url: str, output: Path) -> None:

async with async_playwright() as playwright:
executable = os.environ.get('RUOYI_SMOKE_BROWSER_EXECUTABLE')
browser = await playwright.chromium.launch(
headless=True, **({'executable_path': executable} if executable else {})
)
browser = await playwright.chromium.launch(headless=True, executable_path=executable or None)
context = await browser.new_context(viewport={'width': 390, 'height': 844}, timezone_id='UTC')
await context.tracing.start(screenshots=True, snapshots=True, sources=True)
await context.route('http://localhost:9099/**', api)
Expand All @@ -198,7 +202,7 @@ async def run_smoke(framework: str, base_url: str, output: Path) -> None:
await login_button.click()
await expect(page).to_have_url(re.compile(r'/pages/index'), timeout=30000)
await page.goto(f'{base_url}/#/pages/mine/info/index')
await expect(page.get_by_text(USER['nickName'], exact=True)).to_be_visible(timeout=30000)
await expect(page.get_by_text(NICKNAME, exact=True)).to_be_visible(timeout=30000)
await expect(page.get_by_text('Nickname', exact=True)).to_be_visible(timeout=15000)
created_at = await page.evaluate(
"""({locale, timeZone, createTime}) => new Intl.DateTimeFormat(locale, {
Expand Down Expand Up @@ -234,7 +238,8 @@ def main() -> None:
"""
验证现有开发服务器或临时 H5 静态服务,结束后关闭自身创建的资源。

:return: None
:raises TimeoutError: H5 服务未能在截止时间前就绪
:raises SystemExit: 缺少预先构建的 H5 产物
"""
parser = argparse.ArgumentParser()
parser.add_argument('--framework', choices=('vue2', 'vue3', 'react'), required=True)
Expand Down
7 changes: 6 additions & 1 deletion .github/tests/test_ci_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def load_script(name: str) -> ModuleType:
:return: 已执行模块顶层定义的脚本模块
"""
spec = importlib.util.spec_from_file_location(name, ROOT / '.github/scripts' / f'{name}.py')
assert spec is not None and spec.loader is not None, name
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
Expand All @@ -29,7 +30,11 @@ def load_script(name: str) -> ModuleType:

@pytest.fixture
def configuration() -> dict[str, Any]:
"""提供前端、nginx 和后端框架一致的 Compose 配置。"""
"""
提供前端、nginx 和后端框架一致的 Compose 配置。

:return: 前端、nginx 和后端框架一致的 Compose 配置
"""
frontend = ROOT / 'ruoyi-fastapi-frontend/vue2/web'
return {
'services': {
Expand Down
8 changes: 6 additions & 2 deletions .github/tests/test_ci_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

SCRIPT = Path(__file__).resolve().parents[1] / 'scripts' / 'ci_plan.py'
SPEC = importlib.util.spec_from_file_location('ci_plan', SCRIPT)
assert SPEC is not None and SPEC.loader is not None, SCRIPT
ci = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(ci)
FRONTEND_PROJECT_COUNT = 6
Expand Down Expand Up @@ -160,14 +161,17 @@ def test_full_run_preserves_python_database_and_framework_combinations() -> None
plan = ci.build_plan([], full=True)
assert all(plan['required'].values())
assert len(plan['e2e_matrix']['include']) == FULL_E2E_COMBINATION_COUNT
assert {row['python'] for row in plan['e2e_matrix']['include']} == {'3.10', '3.11', '3.12', '3.13', '3.14'}
assert {row['python'] for row in plan['e2e_matrix']['include']} == {'3.11', '3.12', '3.13', '3.14', '3.15'}


@pytest.mark.parametrize('result', ['failure', 'cancelled', 'skipped', None])
def test_gate_rejects_unsuccessful_required_job(result: str | None) -> None:
"""必跑任务失败、取消、跳过或缺失均不能通过门禁。"""
plan = ci.build_plan(['README.md'])
needs = {'plan': {'result': 'success'}, **{name: {'result': 'skipped'} for name in ci.CATEGORIES}}
needs: dict[str, dict[str, str | None]] = {
'plan': {'result': 'success'},
**{name: {'result': 'skipped'} for name in ci.CATEGORIES},
}
needs['quality']['result'] = result
assert ci.check_results(plan, needs)

Expand Down
22 changes: 21 additions & 1 deletion .github/tests/test_ci_python_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@


def load_module(name: str, path: Path) -> ModuleType:
"""按路径加载 CI 与 E2E 入口,以验证跨工程的版本契约。"""
"""
按路径加载 CI 与 E2E 入口,以验证跨工程的版本契约。

:param name: 要读取的本地模块的完整名称
:param path: 要读取或处理的路径
:return: 提供被测功能的模块
"""
spec = importlib.util.spec_from_file_location(name, path)
assert spec is not None and spec.loader is not None, path
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
Expand All @@ -31,6 +38,19 @@ def test_backend_and_native_cover_full_e2e_python_versions(workflow: str, job: s
assert config['jobs'][job]['strategy']['matrix']['python'] == list(ci.PYTHON_VERSIONS)


@pytest.mark.parametrize('workflow,job', [('ci-backend.yml', 'unit-contract'), ('ci-quality.yml', 'type-check')])
def test_type_checks_run_on_every_supported_python(workflow: str, job: str) -> None:
"""后端、浏览器测试和 CI 脚本的类型检查应在每个受支持版本运行。"""
config = yaml.safe_load((ROOT / '.github/workflows' / workflow).read_text(encoding='utf-8'))
matrix_job = config['jobs'][job]
assert matrix_job['strategy']['matrix']['python'] == list(ci.PYTHON_VERSIONS)
(setup,) = (step for step in matrix_job['steps'] if step.get('uses', '').startswith('actions/setup-python@'))
assert setup['with']['python-version'] == '${{ matrix.python }}'
(check,) = (step for step in matrix_job['steps'] if 'scripts/check_types.py' in step.get('run', ''))
assert 'if' not in check
assert '--python-version ${{ matrix.python }}' in check['run']


def test_release_covers_full_matrix_and_preserves_pr_baseline() -> None:
"""插件发布的完整矩阵跟随 E2E,PR 仍使用单版本基线。"""
config = yaml.safe_load((ROOT / '.github/workflows/ci-integration.yml').read_text(encoding='utf-8'))
Expand Down
17 changes: 17 additions & 0 deletions .github/ty.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[environment]
python-platform = "all"
python-version = "3.11"

[rules]
blanket-ignore-comment = "error"
disjoint-cast = "error"
dynamic-function-decorator-return = "error"
mismatched-enum-name = "error"
mismatched-namedtuple-name = "error"
mismatched-sentinel-name = "error"
missing-type-argument = "error"
unsound-return = "error"
unsound-yield = "error"

[terminal]
error-on-warning = true
7 changes: 6 additions & 1 deletion .github/workflows/ci-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python: ['3.10', '3.11', '3.12', '3.13', '3.14']
python: ['3.11', '3.12', '3.13', '3.14', '3.15']
defaults:
run:
working-directory: ruoyi-fastapi-backend
Expand All @@ -31,6 +31,7 @@ jobs:
cache-dependency-path: |
ruoyi-fastapi-backend/requirements*.txt
ruoyi-fastapi-backend/plugins/ai/plugin.yaml
ruoyi-fastapi-test/requirements.txt
- name: Install MySQL, PostgreSQL and test dependencies
run: python -m pip install -r requirements.txt -r requirements-pg.txt -r requirements-test.txt
- name: Compile and validate gettext catalogs
Expand Down Expand Up @@ -64,6 +65,10 @@ jobs:
run: python ../.github/scripts/install_ai_test_dependencies.py
- name: Check dependency consistency
run: python -m pip check
- name: Type-check backend, plugins and tests
run: |
python -m pip install -c ../ruoyi-fastapi-test/requirements.txt playwright
python scripts/check_types.py --python-version ${{ matrix.python }} .
- name: Run backend unit and contract tests
run: python -m pytest tests -q -m 'not browser and not native and not integration' --strict-markers --durations=20 --junitxml=target/ci/backend.xml
- name: Verify tests were executed
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
- name: Install the Mobile smoke browser
if: matrix.project.target == 'mobile'
run: |
python -m pip install playwright==1.64.0
python -m pip install playwright==1.65.2
python -m playwright install --with-deps chromium
- name: Verify Mobile H5 login and profile
if: matrix.project.target == 'mobile'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python: ${{ fromJSON(inputs.full && '["3.10","3.11","3.12","3.13","3.14"]' || '["3.12"]') }}
python: ${{ fromJSON(inputs.full && '["3.11","3.12","3.13","3.14","3.15"]' || '["3.12"]') }}
defaults:
run:
working-directory: ruoyi-fastapi-backend
Expand Down Expand Up @@ -221,7 +221,7 @@ jobs:
with:
path: ${{ steps.pnpm-store.outputs.path }}
key: ${{ runner.os }}-network-${{ matrix.framework }}-${{ hashFiles(format('ruoyi-fastapi-frontend/{0}/web/pnpm-lock.yaml', matrix.framework)) }}
- run: python -m pip install -r requirements.txt -r requirements-test.txt playwright==1.64.0
- run: python -m pip install -r requirements.txt -r requirements-test.txt playwright==1.65.2
- run: python scripts/compile_i18n.py
- run: python -m playwright install --with-deps chromium
- name: Install Web dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python: ['3.10', '3.11', '3.12', '3.13', '3.14']
python: ['3.11', '3.12', '3.13', '3.14', '3.15']
defaults:
run:
working-directory: ruoyi-fastapi-backend
Expand All @@ -54,7 +54,7 @@ jobs:
python-version: ${{ matrix.python }}
cache: pip
cache-dependency-path: ruoyi-fastapi-backend/requirements*.txt
- run: python -m pip install -r requirements.txt -r requirements-test.txt 'maturin>=1.15,<2'
- run: python -m pip install -r requirements.txt -r requirements-test.txt 'maturin>=1.16.0,<2'
- run: python scripts/compile_i18n.py
- run: rustup toolchain install 1.99.0 --profile minimal
- run: rustup default 1.99.0
Expand Down
26 changes: 24 additions & 2 deletions .github/workflows/ci-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@ permissions:
contents: read

jobs:
type-check:
name: Browser and CI types on Python ${{ matrix.python }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python: ['3.11', '3.12', '3.13', '3.14', '3.15']
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python }}
cache: pip
cache-dependency-path: |
.github/requirements.txt
ruoyi-fastapi-test/requirements.txt
- run: python -m pip install -r .github/requirements.txt -r ruoyi-fastapi-test/requirements.txt
- run: python ruoyi-fastapi-backend/scripts/check_types.py --python-version ${{ matrix.python }} ruoyi-fastapi-test .github

checks:
name: Code and CI contracts
runs-on: ubuntu-latest
Expand All @@ -17,12 +36,15 @@ jobs:
with:
python-version: '3.12'
cache: pip
cache-dependency-path: .github/requirements.txt
- run: python -m pip install -r .github/requirements.txt
cache-dependency-path: |
.github/requirements.txt
ruoyi-fastapi-test/requirements.txt
- run: python -m pip install -r .github/requirements.txt -r ruoyi-fastapi-test/requirements.txt
- name: Python lint and format
run: |
ruff check ruoyi-fastapi-backend ruoyi-fastapi-test .github/scripts .github/tests
ruff format --check ruoyi-fastapi-backend ruoyi-fastapi-test .github/scripts .github/tests
python ruoyi-fastapi-backend/scripts/check_docstrings.py ruoyi-fastapi-backend ruoyi-fastapi-test .github/scripts .github/tests
- name: Test CI routing, failure gates and deployment contracts
run: python -m pytest .github/tests -q --junitxml=target/ci/quality.xml
- name: Validate every Compose framework selection
Expand Down
Loading
Loading