Refactor/merge packages #3
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # CI/CD 测试工作流 | |
| name: CI/CD Tests | |
| on: | |
| push: | |
| branches: [ main, develop, feature/** ] | |
| pull_request: | |
| branches: [ main, develop ] | |
| workflow_dispatch: | |
| jobs: | |
| # 单元测试 | |
| unit-tests: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| node-version: [16.x, 18.x, 20.x] | |
| 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: 'pnpm' | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v3 | |
| with: | |
| version: 8 | |
| - name: Install dependencies | |
| run: pnpm install | |
| - name: Run unit tests | |
| run: pnpm test:unit | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v4 | |
| with: | |
| file: ./coverage/lcov.info | |
| flags: unittests | |
| name: codecov-umbrella | |
| env: | |
| CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
| # 集成测试 | |
| integration-tests: | |
| runs-on: ubuntu-latest | |
| needs: unit-tests | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18.x' | |
| cache: 'pnpm' | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v3 | |
| with: | |
| version: 8 | |
| - name: Install dependencies | |
| run: pnpm install | |
| - name: Run integration tests | |
| run: pnpm test:integration | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v4 | |
| with: | |
| file: ./coverage/lcov.info | |
| flags: integration | |
| name: codecov-integration | |
| # E2E 测试 | |
| e2e-tests: | |
| runs-on: ubuntu-latest | |
| needs: integration-tests | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18.x' | |
| cache: 'pnpm' | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v3 | |
| with: | |
| version: 8 | |
| - name: Install dependencies | |
| run: pnpm install | |
| - name: Run E2E tests | |
| run: pnpm test:e2e | |
| - name: Upload test results | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: e2e-test-results | |
| path: | | |
| test-results/ | |
| reports/ | |
| # 跨平台测试 | |
| cross-platform-tests: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, windows-latest, macos-latest] | |
| node-version: [18.x] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| cache: 'pnpm' | |
| - name: Setup pnpm (Unix) | |
| if: runner.os != 'Windows' | |
| uses: pnpm/action-setup@v3 | |
| with: | |
| version: 8 | |
| - name: Setup pnpm (Windows) | |
| if: runner.os == 'Windows' | |
| run: npm install -g pnpm | |
| - name: Install dependencies | |
| run: pnpm install | |
| - name: Run platform-specific tests | |
| run: pnpm test:unit | |
| - name: Check build | |
| run: pnpm build | |
| # 代码质量检查 | |
| code-quality: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18.x' | |
| cache: 'pnpm' | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v3 | |
| with: | |
| version: 8 | |
| - name: Install dependencies | |
| run: pnpm install | |
| - name: Run linter | |
| run: pnpm lint | |
| - name: Run type checker | |
| run: pnpm type-check | |
| - name: Run formatter check | |
| run: pnpm format:check | |
| # 性能测试 | |
| performance-tests: | |
| runs-on: ubuntu-latest | |
| needs: unit-tests | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18.x' | |
| cache: 'pnpm' | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v3 | |
| with: | |
| version: 8 | |
| - name: Install dependencies | |
| run: pnpm install | |
| - name: Run performance tests | |
| run: pnpm test:performance | |
| - name: Upload performance results | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: performance-results | |
| path: performance-results/ | |
| # 安全扫描 | |
| security-scan: | |
| runs-on: ubuntu-latest | |
| needs: unit-tests | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Run security audit | |
| run: pnpm audit || true # 允许失败,但显示结果 | |
| - name: Run dependency check | |
| uses: dependency-check/Dependency-Check_Action@main | |
| with: | |
| project: 'blade-ai' | |
| path: '.' | |
| format: 'HTML' | |
| out: 'reports' | |
| args: > | |
| --failOnAnyVulnerability | |
| --nodeAuditSkipDevDependencies | |
| env: | |
| NODE_ENV: development | |
| - name: Upload security report | |
| uses: actions/upload-artifact@v4 | |
| if: failure() | |
| with: | |
| name: security-report | |
| path: reports/ | |
| # 测试报告生成 | |
| test-report: | |
| runs-on: ubuntu-latest | |
| needs: [unit-tests, integration-tests, e2e-tests] | |
| if: always() | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Download unit test results | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: unit-test-results | |
| path: test-results/unit | |
| - name: Download integration test results | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: integration-test-results | |
| path: test-results/integration | |
| - name: Download E2E test results | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: e2e-test-results | |
| path: test-results/e2e | |
| - name: Generate test report | |
| run: | | |
| echo "## Test Results Summary" > report.md | |
| echo "### Unit Tests" >> report.md | |
| echo "Status: ${{ needs.unit-tests.result }}" >> report.md | |
| echo "" >> report.md | |
| echo "### Integration Tests" >> report.md | |
| echo "Status: ${{ needs.integration-tests.result }}" >> report.md | |
| echo "" >> report.md | |
| echo "### E2E Tests" >> report.md | |
| echo "Status: ${{ needs.e2e-tests.result }}" >> report.md | |
| - name: Upload test report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-report | |
| path: report.md | |
| # 发布前检查 | |
| pre-release-check: | |
| runs-on: ubuntu-latest | |
| needs: [unit-tests, integration-tests, code-quality, security-scan] | |
| if: github.ref == 'refs/heads/main' | |
| steps: | |
| - name: Check all tests passed | |
| if: needs.unit-tests.result != 'success' || needs.integration-tests.result != 'success' || needs.code-quality.result != 'success' || needs.security-scan.result != 'success' | |
| run: | | |
| echo "Some checks failed. Cannot proceed with release." | |
| exit 1 | |
| - name: All checks passed | |
| run: echo "All checks passed. Ready for release." | |
| # 工作流配置 | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| env: | |
| CI: true | |
| NODE_ENV: test | |
| FORCE_COLOR: 1 |