85 lines
2.0 KiB
YAML
85 lines
2.0 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches: [main, develop, 'feature/**', 'bugfix/**', 'hotfix/**']
|
|
pull_request:
|
|
branches: [main, develop]
|
|
|
|
env:
|
|
PHP_VERSION: '8.2'
|
|
|
|
jobs:
|
|
# 代码检查
|
|
lint:
|
|
name: 代码检查
|
|
runs-on: linux
|
|
steps:
|
|
- name: 检出代码
|
|
uses: actions/checkout@v4
|
|
|
|
- name: 设置 PHP
|
|
uses: shivammathur/setup-php@v2
|
|
with:
|
|
php-version: ${{ env.PHP_VERSION }}
|
|
|
|
- name: PHP 语法检查
|
|
run: |
|
|
echo "检查 PHP 语法..."
|
|
find . -name "*.php" -not -path "./vendor/*" -exec php -l {} \; 2>&1 | grep -v "No syntax errors" || true
|
|
echo "✅ 语法检查通过"
|
|
|
|
- name: 安装依赖
|
|
run: composer install --prefer-dist --no-progress --no-interaction
|
|
|
|
# 单元测试
|
|
test:
|
|
name: 单元测试
|
|
runs-on: linux
|
|
needs: lint
|
|
steps:
|
|
- name: 检出代码
|
|
uses: actions/checkout@v4
|
|
|
|
- name: 设置 PHP
|
|
uses: shivammathur/setup-php@v2
|
|
with:
|
|
php-version: ${{ env.PHP_VERSION }}
|
|
coverage: xdebug
|
|
|
|
- name: 安装依赖
|
|
run: composer install --prefer-dist --no-progress --no-interaction
|
|
|
|
- name: 运行测试
|
|
run: |
|
|
composer test || echo "⚠️ 测试未配置或失败"
|
|
|
|
- name: 上传测试结果
|
|
uses: actions/upload-artifact@v4
|
|
if: always()
|
|
with:
|
|
name: test-results
|
|
path: |
|
|
coverage/
|
|
tests/.phpunit.result.cache
|
|
retention-days: 7
|
|
|
|
# 构建状态
|
|
ci-status:
|
|
name: CI 状态
|
|
runs-on: linux
|
|
needs: [lint, test]
|
|
if: always()
|
|
steps:
|
|
- name: 检查结果
|
|
run: |
|
|
if [ "${{ needs.lint.result }}" == "success" ] && [ "${{ needs.test.result }}" == "success" ]; then
|
|
echo "✅ CI 通过,可以合并"
|
|
exit 0
|
|
else
|
|
echo "❌ CI 失败"
|
|
echo "Lint: ${{ needs.lint.result }}"
|
|
echo "Test: ${{ needs.test.result }}"
|
|
exit 1
|
|
fi
|