|
| 1 | +name: Pull request validation |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | + paths-ignore: |
| 9 | + - .github |
| 10 | + - .vscode |
| 11 | + |
| 12 | + push: |
| 13 | + branches: |
| 14 | + - feat-github-workflow # Keeping the branch here so we can try out something later quickly |
| 15 | + |
| 16 | + workflow_dispatch: {} |
| 17 | + |
| 18 | +defaults: |
| 19 | + run: |
| 20 | + shell: bash |
| 21 | + |
| 22 | +env: |
| 23 | + CI_PULL_REQUEST: 1 # Skip nightly tests |
| 24 | + NODE_ENV: test # Add instrumentation code |
| 25 | + node-version: 18.18 # Need to bump jest@29 to resolve something in https://github.com/facebook/react-native/issues/35701 |
| 26 | + skip-secure-feed: false |
| 27 | + |
| 28 | +jobs: |
| 29 | + build: |
| 30 | + name: Build |
| 31 | + runs-on: ubuntu-latest |
| 32 | + |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v4 |
| 35 | + |
| 36 | + - if: "env.skip-secure-feed != 'true'" |
| 37 | + name: Enable secure feed |
| 38 | + run: npx https://aka.ms/EnableSecureFeed |
| 39 | + |
| 40 | + - name: Use Node.js ${{ env.node-version }} |
| 41 | + uses: actions/setup-node@v4 |
| 42 | + with: |
| 43 | + node-version: ${{ env.node-version }} |
| 44 | + cache: npm |
| 45 | + |
| 46 | + - run: npm clean-install |
| 47 | + |
| 48 | + - run: npm run bootstrap |
| 49 | + |
| 50 | + - run: npm run build --if-present |
| 51 | + |
| 52 | + - name: Pack Docker artifact |
| 53 | + run: | |
| 54 | + zip docker.zip -r@ <<EOF |
| 55 | + ./__tests__/ |
| 56 | + ./babel-jest-config.js |
| 57 | + ./babel-passthru-transformer.js |
| 58 | + ./babel.config.json |
| 59 | + ./docker-compose-wsl2.yml |
| 60 | + ./jest.config.js |
| 61 | + ./package.json |
| 62 | + ./package-lock.json |
| 63 | + ./packages/bundle/dist/ |
| 64 | + ./packages/test/harness/ |
| 65 | + ./packages/test/page-object/dist/ |
| 66 | + ./serve-test.json |
| 67 | + ./testharness.dockerfile |
| 68 | + ./testharness2.dockerfile |
| 69 | + EOF |
| 70 | +
|
| 71 | + - run: ls -l docker.zip |
| 72 | + |
| 73 | + - name: Upload Docker artifact |
| 74 | + uses: actions/upload-artifact@v3 |
| 75 | + with: |
| 76 | + name: docker |
| 77 | + path: docker.zip |
| 78 | + retention-days: 1 |
| 79 | + |
| 80 | + static-code-analysis: |
| 81 | + name: Static code analysis |
| 82 | + runs-on: ubuntu-latest |
| 83 | + |
| 84 | + steps: |
| 85 | + - uses: actions/checkout@v4 |
| 86 | + |
| 87 | + - if: "env.skip-secure-feed != 'true'" |
| 88 | + name: Enable secure feed |
| 89 | + run: npx https://aka.ms/EnableSecureFeed |
| 90 | + |
| 91 | + - name: Use Node.js ${{ env.node-version }} |
| 92 | + uses: actions/setup-node@v4 |
| 93 | + with: |
| 94 | + node-version: ${{ env.node-version }} |
| 95 | + cache: npm |
| 96 | + |
| 97 | + - run: npm clean-install |
| 98 | + |
| 99 | + - run: npm run bootstrap |
| 100 | + |
| 101 | + - run: npm run build --if-present |
| 102 | + |
| 103 | + - run: npm run precommit --if-present |
| 104 | + |
| 105 | + unit-test: |
| 106 | + name: Unit test |
| 107 | + runs-on: ubuntu-latest |
| 108 | + |
| 109 | + steps: |
| 110 | + - uses: actions/checkout@v4 |
| 111 | + |
| 112 | + - if: "env.skip-secure-feed != 'true'" |
| 113 | + name: Enable secure feed |
| 114 | + run: npx https://aka.ms/EnableSecureFeed |
| 115 | + |
| 116 | + - name: Use Node.js ${{ env.node-version }} |
| 117 | + uses: actions/setup-node@v4 |
| 118 | + with: |
| 119 | + node-version: ${{ env.node-version }} |
| 120 | + cache: npm |
| 121 | + |
| 122 | + - run: npm clean-install |
| 123 | + |
| 124 | + - run: npm run bootstrap |
| 125 | + |
| 126 | + - run: npm run build --if-present |
| 127 | + |
| 128 | + - name: Run jest --testPathPattern packages/ |
| 129 | + run: | |
| 130 | + ./node_modules/.bin/jest \ |
| 131 | + --ci \ |
| 132 | + --coverage true \ |
| 133 | + --forceExit \ |
| 134 | + --logHeapUsage \ |
| 135 | + --runInBand \ |
| 136 | + --testPathPattern=/packages/\ |
| 137 | + timeout-minutes: 10 |
| 138 | + |
| 139 | + - if: always() |
| 140 | + name: Append ID to test result |
| 141 | + run: | |
| 142 | + ls -laR . |
| 143 | +
|
| 144 | + mv jest.json jest-unit.json |
| 145 | + mv lcov.info lcov-unit.info |
| 146 | + mv nunit3.xml nunit3-unit.xml |
| 147 | + mv result.trx result-unit.trx |
| 148 | + working-directory: ./coverage |
| 149 | + |
| 150 | + - if: always() |
| 151 | + name: Upload test results |
| 152 | + uses: actions/upload-artifact@v3 |
| 153 | + with: |
| 154 | + name: test-result |
| 155 | + path: | |
| 156 | + ./coverage/jest-*.json |
| 157 | + ./coverage/lcov-*.info |
| 158 | + ./coverage/nunit3-*.xml |
| 159 | + ./coverage/result-*.trx |
| 160 | +
|
| 161 | + html-test: |
| 162 | + name: HTML test (${{ format('{0}/{1}', matrix.shard-index, matrix.shard-count) }}) |
| 163 | + needs: |
| 164 | + - build |
| 165 | + runs-on: ubuntu-latest |
| 166 | + strategy: |
| 167 | + fail-fast: false |
| 168 | + matrix: |
| 169 | + shard-index: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] |
| 170 | + shard-count: [20] |
| 171 | + |
| 172 | + steps: |
| 173 | + - if: "env.skip-secure-feed != 'true'" |
| 174 | + name: Enable secure feed |
| 175 | + run: npx https://aka.ms/EnableSecureFeed |
| 176 | + |
| 177 | + - name: Use Node.js ${{ env.node-version }} |
| 178 | + uses: actions/setup-node@v4 |
| 179 | + with: |
| 180 | + node-version: ${{ env.node-version }} |
| 181 | + |
| 182 | + - name: Download Docker artifact |
| 183 | + uses: actions/download-artifact@v3 |
| 184 | + with: |
| 185 | + name: docker |
| 186 | + |
| 187 | + - run: unzip docker.zip |
| 188 | + |
| 189 | + - run: rm docker.zip |
| 190 | + |
| 191 | + - run: npm clean-install |
| 192 | + |
| 193 | + - name: Run docker-compose build |
| 194 | + run: docker-compose -f docker-compose-wsl2.yml build --build-arg REGISTRY=mcr.microsoft.com/mirror/docker/library |
| 195 | + |
| 196 | + - name: Run docker-compose up |
| 197 | + run: docker-compose -f docker-compose-wsl2.yml up --detach --scale chrome=2 |
| 198 | + |
| 199 | + - name: Wait for Docker to be ready |
| 200 | + run: | |
| 201 | + set +e # Disable per-command fail, we will handle cURL fail. |
| 202 | +
|
| 203 | + while true |
| 204 | + do |
| 205 | + curl http://localhost:4444/wd/hub/status > /tmp/wd-status.json |
| 206 | +
|
| 207 | + [[ $? -eq 0 ]] && cat /tmp/wd-status.json | jq -r 'if (.value.ready != true) then halt_error(1) else empty end' |
| 208 | + [[ $? -eq 0 ]] && break |
| 209 | +
|
| 210 | + sleep 1 |
| 211 | + done |
| 212 | +
|
| 213 | + - name: Run jest --shard=${{ format('{0}/{1}', matrix.shard-index, matrix.shard-count) }} |
| 214 | + run: | |
| 215 | + ./node_modules/.bin/jest \ |
| 216 | + --ci \ |
| 217 | + --coverage true \ |
| 218 | + --forceExit \ |
| 219 | + --logHeapUsage \ |
| 220 | + --runInBand \ |
| 221 | + --shard=${{ format('{0}/{1}', matrix.shard-index, matrix.shard-count) }} |
| 222 | + timeout-minutes: 10 |
| 223 | + |
| 224 | + - if: always() |
| 225 | + name: Print Docker logs |
| 226 | + run: docker-compose -f docker-compose-wsl2.yml logs |
| 227 | + |
| 228 | + - if: always() |
| 229 | + name: Append ID to test result |
| 230 | + run: | |
| 231 | + ls -laR . |
| 232 | +
|
| 233 | + mv jest.json jest-${{ matrix.shard-index }}.json |
| 234 | + mv lcov.info lcov-${{ matrix.shard-index }}.info |
| 235 | + mv nunit3.xml nunit3-${{ matrix.shard-index }}.xml |
| 236 | + mv result.trx result-${{ matrix.shard-index }}.trx |
| 237 | + working-directory: ./coverage |
| 238 | + |
| 239 | + - if: always() |
| 240 | + name: Upload test results |
| 241 | + uses: actions/upload-artifact@v3 |
| 242 | + with: |
| 243 | + name: test-result |
| 244 | + path: | |
| 245 | + ./coverage/jest-*.json |
| 246 | + ./coverage/lcov-*.info |
| 247 | + ./coverage/nunit3-*.xml |
| 248 | + ./coverage/result-*.trx |
| 249 | +
|
| 250 | + - if: failure() |
| 251 | + name: Upload test snapshot diffs |
| 252 | + uses: actions/upload-artifact@v3 |
| 253 | + with: |
| 254 | + name: test-snapshot-diff |
| 255 | + path: ./__tests__/__image_snapshots__/*/__diff_output__/* |
| 256 | + |
| 257 | + merge-test-result: |
| 258 | + if: always() |
| 259 | + name: Merge test result |
| 260 | + needs: |
| 261 | + - html-test |
| 262 | + - unit-test |
| 263 | + runs-on: ubuntu-latest |
| 264 | + |
| 265 | + steps: |
| 266 | + - name: Download test results |
| 267 | + uses: actions/download-artifact@v3 |
| 268 | + with: |
| 269 | + name: test-result |
| 270 | + |
| 271 | + - name: Install lcov |
| 272 | + run: sudo apt install -y lcov |
| 273 | + |
| 274 | + - name: Merge lcov-*.info |
| 275 | + run: | |
| 276 | + lcov \ |
| 277 | + --rc lcov_branch_coverage=1 \ |
| 278 | + --add-tracefile lcov-1.info \ |
| 279 | + --add-tracefile lcov-2.info \ |
| 280 | + --add-tracefile lcov-3.info \ |
| 281 | + --add-tracefile lcov-4.info \ |
| 282 | + --add-tracefile lcov-5.info \ |
| 283 | + --add-tracefile lcov-6.info \ |
| 284 | + --add-tracefile lcov-7.info \ |
| 285 | + --add-tracefile lcov-8.info \ |
| 286 | + --add-tracefile lcov-9.info \ |
| 287 | + --add-tracefile lcov-10.info \ |
| 288 | + --add-tracefile lcov-11.info \ |
| 289 | + --add-tracefile lcov-12.info \ |
| 290 | + --add-tracefile lcov-13.info \ |
| 291 | + --add-tracefile lcov-14.info \ |
| 292 | + --add-tracefile lcov-15.info \ |
| 293 | + --add-tracefile lcov-16.info \ |
| 294 | + --add-tracefile lcov-17.info \ |
| 295 | + --add-tracefile lcov-18.info \ |
| 296 | + --add-tracefile lcov-19.info \ |
| 297 | + --add-tracefile lcov-20.info \ |
| 298 | + --add-tracefile lcov-unit.info \ |
| 299 | + --output-file lcov.info |
| 300 | +
|
| 301 | + - if: always() |
| 302 | + name: Print coverage list |
| 303 | + run: lcov --rc lcov_branch_coverage=1 --list lcov.info |
| 304 | + |
| 305 | + - if: always() |
| 306 | + name: Print coverage summary |
| 307 | + run: | |
| 308 | + echo \`\`\` >> $GITHUB_STEP_SUMMARY |
| 309 | + lcov --rc lcov_branch_coverage=1 --summary lcov.info | tee --append $GITHUB_STEP_SUMMARY |
| 310 | + echo \`\`\` >> $GITHUB_STEP_SUMMARY |
0 commit comments