fix: remove local file #305
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
| 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: Detect package manager | |
| id: detect-package-manager | |
| run: | | |
| if [ -f "${{ github.workspace }}/pnpm-lock.yaml" ]; then | |
| echo "manager=pnpm" >> $GITHUB_OUTPUT | |
| echo "command=install --frozen-lockfile" >> $GITHUB_OUTPUT | |
| exit 0 | |
| elif [ -f "${{ github.workspace }}/yarn.lock" ]; then | |
| echo "manager=yarn" >> $GITHUB_OUTPUT | |
| echo "command=install" >> $GITHUB_OUTPUT | |
| exit 0 | |
| elif [ -f "${{ github.workspace }}/package-lock.json" ]; then | |
| echo "manager=npm" >> $GITHUB_OUTPUT | |
| echo "command=ci" >> $GITHUB_OUTPUT | |
| exit 0 | |
| else | |
| echo "Unable to determine package manager" | |
| exit 1 | |
| fi | |
| - name: Setup pnpm | |
| if: steps.detect-package-manager.outputs.manager == 'pnpm' | |
| uses: pnpm/action-setup@v4 | |
| - name: 📦 Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22" | |
| cache: ${{ steps.detect-package-manager.outputs.manager }} | |
| - name: 📥 Install dependencies | |
| run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} | |
| - name: 🔍 Run linter | |
| run: ${{ steps.detect-package-manager.outputs.manager }} run lint | |
| - name: 🔍 Type check | |
| run: ${{ steps.detect-package-manager.outputs.manager }} run type-check 2>/dev/null || pnpm exec tsc --noEmit | |
| # ============================================================================ | |
| # 单元测试 (有测试时运行) | |
| # ============================================================================ | |
| 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: Detect package manager | |
| id: detect-package-manager | |
| run: | | |
| if [ -f "${{ github.workspace }}/pnpm-lock.yaml" ]; then | |
| echo "manager=pnpm" >> $GITHUB_OUTPUT | |
| echo "command=install --frozen-lockfile" >> $GITHUB_OUTPUT | |
| exit 0 | |
| elif [ -f "${{ github.workspace }}/yarn.lock" ]; then | |
| echo "manager=yarn" >> $GITHUB_OUTPUT | |
| echo "command=install" >> $GITHUB_OUTPUT | |
| exit 0 | |
| elif [ -f "${{ github.workspace }}/package-lock.json" ]; then | |
| echo "manager=npm" >> $GITHUB_OUTPUT | |
| echo "command=ci" >> $GITHUB_OUTPUT | |
| exit 0 | |
| else | |
| echo "Unable to determine package manager" | |
| exit 1 | |
| fi | |
| - name: Setup pnpm | |
| if: steps.detect-package-manager.outputs.manager == 'pnpm' | |
| uses: pnpm/action-setup@v4 | |
| - name: 📦 Setup Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| cache: ${{ steps.detect-package-manager.outputs.manager }} | |
| - name: 📥 Install dependencies | |
| run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} | |
| - name: 🧪 Run unit tests | |
| run: ${{ steps.detect-package-manager.outputs.manager }} run test:run 2>/dev/null || echo "No test:run script, skipping" | |
| - 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 | |
| if-no-files-found: ignore | |
| # ============================================================================ | |
| # 构建测试 | |
| # ============================================================================ | |
| build-test: | |
| name: 🏗️ Build Test | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| needs: lint | |
| steps: | |
| - name: 📥 Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Detect package manager | |
| id: detect-package-manager | |
| run: | | |
| if [ -f "${{ github.workspace }}/pnpm-lock.yaml" ]; then | |
| echo "manager=pnpm" >> $GITHUB_OUTPUT | |
| echo "command=install --frozen-lockfile" >> $GITHUB_OUTPUT | |
| exit 0 | |
| elif [ -f "${{ github.workspace }}/yarn.lock" ]; then | |
| echo "manager=yarn" >> $GITHUB_OUTPUT | |
| echo "command=install" >> $GITHUB_OUTPUT | |
| exit 0 | |
| elif [ -f "${{ github.workspace }}/package-lock.json" ]; then | |
| echo "manager=npm" >> $GITHUB_OUTPUT | |
| echo "command=ci" >> $GITHUB_OUTPUT | |
| exit 0 | |
| else | |
| echo "Unable to determine package manager" | |
| exit 1 | |
| fi | |
| - name: Setup pnpm | |
| if: steps.detect-package-manager.outputs.manager == 'pnpm' | |
| uses: pnpm/action-setup@v4 | |
| - name: 📦 Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22" | |
| cache: ${{ steps.detect-package-manager.outputs.manager }} | |
| - name: 📥 Install dependencies | |
| run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} | |
| - name: 🏗️ Build project | |
| run: ${{ steps.detect-package-manager.outputs.manager }} run build | |
| - name: 📦 Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: build-output | |
| path: | | |
| .next/ | |
| dist/ | |
| retention-days: 7 | |
| if-no-files-found: ignore | |
| # ============================================================================ | |
| # 测试总结 | |
| # ============================================================================ | |
| test-summary: | |
| name: 📋 Test Summary | |
| runs-on: ubuntu-latest | |
| needs: [unit-tests, build-test] | |
| if: always() | |
| steps: | |
| - 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' || needs.unit-tests.result == 'skipped' && '⏭️ Skipped' || '❌ 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.build-test.result == 'success' | |
| run: | | |
| echo "🎉 Build and checks passed successfully!" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "Ready for deployment! 🚀" >> $GITHUB_STEP_SUMMARY |