mirror of
https://github.com/rustfs/console.git
synced 2026-08-30 17:14:47 +08:00
221 lines
7.9 KiB
YAML
221 lines
7.9 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@v6
|
|
|
|
- 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@v6
|
|
with:
|
|
version: 10.19.0
|
|
- name: 📦 Setup Node.js
|
|
uses: actions/setup-node@v6
|
|
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@v6
|
|
|
|
- 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@v6
|
|
with:
|
|
version: 10.19.0
|
|
- name: 📦 Setup Node.js ${{ matrix.node-version }}
|
|
uses: actions/setup-node@v6
|
|
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@v6
|
|
|
|
- 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@v6
|
|
with:
|
|
version: 10.19.0
|
|
- name: 📦 Setup Node.js
|
|
uses: actions/setup-node@v6
|
|
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
|