|
| 1 | +name: Compatibility Matrix Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, develop ] |
| 8 | + schedule: |
| 9 | + # 每日 UTC 00:00 运行完整矩阵 |
| 10 | + - cron: '0 0 * * *' |
| 11 | + |
| 12 | +jobs: |
| 13 | + # 核心组合测试(每次 PR 运行) |
| 14 | + core-compatibility: |
| 15 | + name: Core - Node ${{ matrix.node }} / Driver ${{ matrix.driver }} / ${{ matrix.os }} |
| 16 | + runs-on: ${{ matrix.os }} |
| 17 | + |
| 18 | + strategy: |
| 19 | + matrix: |
| 20 | + # 核心 LTS 版本 |
| 21 | + node: ['18.x', '20.x'] |
| 22 | + # 当前使用的驱动版本 |
| 23 | + driver: ['6.17.0'] |
| 24 | + os: [ubuntu-latest, windows-latest] |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout code |
| 28 | + uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: Setup Node.js ${{ matrix.node }} |
| 31 | + uses: actions/setup-node@v4 |
| 32 | + with: |
| 33 | + node-version: ${{ matrix.node }} |
| 34 | + cache: 'npm' |
| 35 | + |
| 36 | + - name: Install dependencies |
| 37 | + run: npm ci |
| 38 | + |
| 39 | + - name: Run compatibility tests |
| 40 | + run: npm run test:compatibility |
| 41 | + |
| 42 | + - name: Upload results |
| 43 | + if: always() |
| 44 | + uses: actions/upload-artifact@v4 |
| 45 | + with: |
| 46 | + name: core-results-node${{ matrix.node }}-${{ matrix.os }} |
| 47 | + path: reports/monSQLize/compatibility-*.json |
| 48 | + |
| 49 | + # 完整矩阵测试(仅在 main 分支和定时任务) |
| 50 | + full-matrix: |
| 51 | + name: Full - Node ${{ matrix.node }} / Driver ${{ matrix.driver }} |
| 52 | + runs-on: ubuntu-latest |
| 53 | + if: github.ref == 'refs/heads/main' || github.event_name == 'schedule' |
| 54 | + |
| 55 | + strategy: |
| 56 | + fail-fast: false |
| 57 | + matrix: |
| 58 | + # 所有支持的 Node.js 版本 |
| 59 | + node: ['14.x', '16.x', '18.x', '20.x', '22.x'] |
| 60 | + # 多个 MongoDB Driver 版本 |
| 61 | + driver: ['4.17.2', '5.9.2', '6.17.0'] |
| 62 | + exclude: |
| 63 | + # Node.js 14 不支持最新的某些依赖 |
| 64 | + - node: '14.x' |
| 65 | + driver: '6.17.0' |
| 66 | + |
| 67 | + steps: |
| 68 | + - name: Checkout code |
| 69 | + uses: actions/checkout@v4 |
| 70 | + |
| 71 | + - name: Setup Node.js ${{ matrix.node }} |
| 72 | + uses: actions/setup-node@v4 |
| 73 | + with: |
| 74 | + node-version: ${{ matrix.node }} |
| 75 | + cache: 'npm' |
| 76 | + |
| 77 | + - name: Install dependencies (default driver) |
| 78 | + run: npm ci |
| 79 | + |
| 80 | + - name: Install specific MongoDB Driver version |
| 81 | + run: | |
| 82 | + npm uninstall mongodb |
| 83 | + npm install mongodb@${{ matrix.driver }} --save-exact |
| 84 | + |
| 85 | + - name: Run compatibility tests |
| 86 | + run: npm run test:compatibility |
| 87 | + continue-on-error: true |
| 88 | + |
| 89 | + - name: Upload results |
| 90 | + if: always() |
| 91 | + uses: actions/upload-artifact@v4 |
| 92 | + with: |
| 93 | + name: full-results-node${{ matrix.node }}-driver${{ matrix.driver }} |
| 94 | + path: reports/monSQLize/compatibility-*.json |
| 95 | + |
| 96 | + # Server 版本测试(Memory Server 模式) |
| 97 | + server-compatibility: |
| 98 | + name: Server Compatibility (Memory Server) |
| 99 | + runs-on: ubuntu-latest |
| 100 | + if: github.ref == 'refs/heads/main' || github.event_name == 'schedule' |
| 101 | + |
| 102 | + steps: |
| 103 | + - name: Checkout code |
| 104 | + uses: actions/checkout@v4 |
| 105 | + |
| 106 | + - name: Setup Node.js |
| 107 | + uses: actions/setup-node@v4 |
| 108 | + with: |
| 109 | + node-version: '20.x' |
| 110 | + cache: 'npm' |
| 111 | + |
| 112 | + - name: Install dependencies |
| 113 | + run: npm ci |
| 114 | + |
| 115 | + - name: Run Server compatibility tests |
| 116 | + run: npm run test:compatibility:server |
| 117 | + continue-on-error: true |
| 118 | + |
| 119 | + - name: Upload results |
| 120 | + if: always() |
| 121 | + uses: actions/upload-artifact@v4 |
| 122 | + with: |
| 123 | + name: server-results |
| 124 | + path: reports/monSQLize/server-compatibility-*.json |
| 125 | + |
| 126 | + # 生成兼容性报告 |
| 127 | + generate-report: |
| 128 | + name: Generate Compatibility Report |
| 129 | + runs-on: ubuntu-latest |
| 130 | + needs: [core-compatibility, full-matrix, server-compatibility] |
| 131 | + if: always() |
| 132 | + |
| 133 | + steps: |
| 134 | + - name: Checkout code |
| 135 | + uses: actions/checkout@v4 |
| 136 | + |
| 137 | + - name: Setup Node.js |
| 138 | + uses: actions/setup-node@v4 |
| 139 | + with: |
| 140 | + node-version: '20.x' |
| 141 | + |
| 142 | + - name: Download all results |
| 143 | + uses: actions/download-artifact@v4 |
| 144 | + with: |
| 145 | + path: test-results |
| 146 | + |
| 147 | + - name: Install dependencies |
| 148 | + run: npm ci |
| 149 | + |
| 150 | + - name: Generate combined report |
| 151 | + run: | |
| 152 | + node scripts/generate-compatibility-report.js test-results |
| 153 | + |
| 154 | + - name: Upload report |
| 155 | + uses: actions/upload-artifact@v4 |
| 156 | + with: |
| 157 | + name: compatibility-report |
| 158 | + path: reports/monSQLize/compatibility-report-*.md |
| 159 | + |
| 160 | + - name: Comment PR with report |
| 161 | + if: github.event_name == 'pull_request' |
| 162 | + uses: actions/github-script@v7 |
| 163 | + with: |
| 164 | + script: | |
| 165 | + const fs = require('fs'); |
| 166 | + const reportPath = 'reports/monSQLize/compatibility-report-latest.md'; |
| 167 | + if (fs.existsSync(reportPath)) { |
| 168 | + const report = fs.readFileSync(reportPath, 'utf8'); |
| 169 | + github.rest.issues.createComment({ |
| 170 | + issue_number: context.issue.number, |
| 171 | + owner: context.repo.owner, |
| 172 | + repo: context.repo.repo, |
| 173 | + body: report |
| 174 | + }); |
| 175 | + } |
| 176 | +
|
0 commit comments