Files
rustfs-console/.github/workflows/test.yml
T
overtrue 86367af9f4 ⬆️ chore: 升级 CI/CD 工作流 Node.js 版本至 22
- 将所有工作流文件中的 Node.js 版本从 18 升级到 22
- test.yml: 更新单元测试矩阵为 [20, 22]
- release.yml: 更新环境变量 NODE_VERSION 为 22
- quality.yml: 更新所有代码质量检查任务的 Node 版本
- dependencies.yml: 更新依赖管理任务的 Node 版本
2025-10-07 23:24:12 +08:00

374 lines
12 KiB
YAML

name: 🧪 Tests
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# ============================================================================
# 代码质量检查
# ============================================================================
lint:
name: 🔍 Code Quality
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
- name: 📦 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- name: 📥 Install dependencies
run: npm ci
- name: 🔍 Run linter
run: npm run lint
- name: 🔍 Type check
run: npm run type-check
# ============================================================================
# 单元测试
# ============================================================================
unit-tests:
name: 🧪 Unit Tests
runs-on: ubuntu-latest
timeout-minutes: 15
needs: lint
strategy:
matrix:
node-version: [20, 22]
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
- name: 📦 Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: 📥 Install dependencies
run: |
npm ci
npm install --save-dev vitest jsdom @vitest/ui c8
- name: 🧪 Run unit tests
run: npx vitest run tests/utils/config-helpers.test.ts --reporter=verbose
- name: 📊 Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: unit-test-results-node-${{ matrix.node-version }}
path: |
coverage/
test-results.xml
retention-days: 7
# ============================================================================
# 集成测试
# ============================================================================
integration-tests:
name: 🔗 Integration Tests
runs-on: ubuntu-latest
timeout-minutes: 20
needs: lint
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
- name: 📦 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- name: 📥 Install dependencies
run: |
npm ci
npm install --save-dev vitest jsdom @vitest/ui c8
- name: 🔗 Run integration tests
run: npx vitest run tests/utils/config-helpers.integration.test.ts --reporter=verbose
- name: 📊 Upload integration test results
uses: actions/upload-artifact@v4
if: always()
with:
name: integration-test-results
path: |
coverage/
test-results.xml
retention-days: 7
# ============================================================================
# 性能测试
# ============================================================================
performance-tests:
name: ⚡ Performance Tests
runs-on: ubuntu-latest
timeout-minutes: 25
needs: [unit-tests, integration-tests]
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
- name: 📦 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- name: 📥 Install dependencies
run: |
npm ci
npm install --save-dev vitest jsdom @vitest/ui c8
- name: ⚡ Run performance tests
run: npx vitest run tests/utils/config-helpers.performance.test.ts --reporter=verbose
- name: 📊 Upload performance test results
uses: actions/upload-artifact@v4
if: always()
with:
name: performance-test-results
path: |
coverage/
performance-report.json
retention-days: 7
# ============================================================================
# 代码覆盖率
# ============================================================================
coverage:
name: 📊 Code Coverage
runs-on: ubuntu-latest
timeout-minutes: 15
needs: lint
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
- name: 📦 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- name: 📥 Install dependencies
run: |
npm ci
npm install --save-dev vitest jsdom @vitest/ui c8
- name: 📊 Run tests with coverage
run: npx vitest run tests/utils/config-helpers*.test.ts --coverage --reporter=verbose
- name: 📤 Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/lcov.info
flags: config-helpers
name: config-helpers-coverage
fail_ci_if_error: false
- name: 📊 Coverage Summary
run: |
echo "## 📊 Coverage Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ -f coverage/coverage-summary.json ]; then
node -e "
const fs = require('fs');
const coverage = JSON.parse(fs.readFileSync('coverage/coverage-summary.json', 'utf8'));
const total = coverage.total;
console.log('| Metric | Percentage | Covered/Total |');
console.log('|--------|------------|---------------|');
console.log('| Lines | ' + total.lines.pct + '% | ' + total.lines.covered + '/' + total.lines.total + ' |');
console.log('| Functions | ' + total.functions.pct + '% | ' + total.functions.covered + '/' + total.functions.total + ' |');
console.log('| Branches | ' + total.branches.pct + '% | ' + total.branches.covered + '/' + total.branches.total + ' |');
console.log('| Statements | ' + total.statements.pct + '% | ' + total.statements.covered + '/' + total.statements.total + ' |');
" >> $GITHUB_STEP_SUMMARY
fi
- name: 📊 Upload coverage artifacts
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage/
retention-days: 30
# ============================================================================
# 浏览器兼容性测试
# ============================================================================
browser-tests:
name: 🌐 Browser Compatibility
runs-on: ubuntu-latest
timeout-minutes: 20
needs: [unit-tests, integration-tests]
strategy:
matrix:
browser: [chromium, firefox, webkit]
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
- name: 📦 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- name: 📥 Install dependencies
run: |
npm ci
npm install --save-dev vitest jsdom @vitest/ui c8 playwright
- name: 🎭 Install Playwright browsers
run: npx playwright install ${{ matrix.browser }}
- name: 🌐 Run browser tests
run: |
# 使用 Playwright 运行浏览器环境测试
npx vitest run tests/utils/config-helpers.test.ts --environment=happy-dom --reporter=verbose
env:
BROWSER: ${{ matrix.browser }}
- name: 📊 Upload browser test results
uses: actions/upload-artifact@v4
if: always()
with:
name: browser-test-results-${{ matrix.browser }}
path: |
test-results/
screenshots/
retention-days: 7
# ============================================================================
# 安全扫描
# ============================================================================
security:
name: 🔒 Security Scan
runs-on: ubuntu-latest
timeout-minutes: 10
needs: lint
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
- name: 📦 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- name: 📥 Install dependencies
run: npm ci
- name: 🔒 Run security audit
run: npm audit --audit-level=moderate
- name: 🔍 Run CodeQL Analysis
uses: github/codeql-action/init@v3
with:
languages: javascript
- name: 🔍 Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
# ============================================================================
# 构建测试
# ============================================================================
build-test:
name: 🏗️ Build Test
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [coverage, security]
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
- name: 📦 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- name: 📥 Install dependencies
run: npm ci
- name: 🏗️ Build project
run: npm run build
- name: 📦 Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-output
path: |
.output/
dist/
retention-days: 7
# ============================================================================
# 测试总结
# ============================================================================
test-summary:
name: 📋 Test Summary
runs-on: ubuntu-latest
needs: [unit-tests, integration-tests, performance-tests, coverage, browser-tests, build-test]
if: always()
steps:
- name: 📥 Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts/
- name: 📋 Generate test summary
run: |
echo "# 🧪 Test Results Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 📊 Test Status" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Test Type | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-----------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Unit Tests | ${{ needs.unit-tests.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Integration Tests | ${{ needs.integration-tests.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Performance Tests | ${{ needs.performance-tests.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Coverage | ${{ needs.coverage.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Browser Tests | ${{ needs.browser-tests.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Build Test | ${{ needs.build-test.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 📈 Metrics" >> $GITHUB_STEP_SUMMARY
echo "- **Commit**: \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
echo "- **Branch**: \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY
echo "- **Workflow**: [\#${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> $GITHUB_STEP_SUMMARY
- name: 🎉 Success notification
if: needs.unit-tests.result == 'success' && needs.integration-tests.result == 'success' && needs.coverage.result == 'success'
run: |
echo "🎉 All tests passed successfully!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "The config-helpers module is ready for deployment! 🚀" >> $GITHUB_STEP_SUMMARY