11name : Code Coverage
22
3- on :
4- push :
5- branches : [main]
3+ # TODO: revert
4+ on : push
5+ # on:
6+ # push:
7+ # branches: [main]
68
79env :
810 NX_NON_NATIVE_HASHER : true
911 NX_CLOUD_ACCESS_TOKEN : ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
1012
1113jobs :
14+ list-packages :
15+ name : List packages
16+ runs-on : ubuntu-latest
17+ steps :
18+ - name : Checkout the repository
19+ uses : actions/checkout@v4
20+ - name : Set up Node.js
21+ uses : actions/setup-node@v4
22+ with :
23+ node-version-file : .nvmrc
24+ cache : npm
25+ - name : Install dependencies
26+ run : npm ci
27+ - name : List packages using Nx CLI
28+ id : project
29+ run : |
30+ packages=$(npx nx show projects --projects="packages/*" | sort)
31+ packages_with_unit_tests=$(npx nx show projects --with-target=unit-test --projects="packages/*" | sort)
32+ packages_with_int_tests=$(npx nx show projects --with-target=int-test --projects="packages/*" | sort)
33+ project=$(echo $packages | jq -R | jq -s -c)
34+ echo "project=$project" >> $GITHUB_OUTPUT
35+ - name : Exclude package tests with missing target
36+ id : exclude
37+ run : |
38+ packages_without_unit_tests=$(comm -23 <(echo $packages) <(echo $packages_with_unit_tests))
39+ packages_without_int_tests=$(comm -23 <(echo $packages) <(echo $packages_with_int_tests))
40+ exclude_unit_tests=$(echo $packages_without_unit_tests | sed '/^$/d' | jq -R | jq -s 'map({ "project": ., "target": "unit-test" })')
41+ exclude_int_tests=$(echo $packages_without_int_tests | sed '/^$/d' | jq -R | jq -s 'map({ "project": ., "target": "int-test" })')
42+ exclude=$(echo "$exclude_unit_tests\n$exclude_int_tests" | jq -s -c add)
43+ echo "exclude=$exclude" >> $GITHUB_OUTPUT
44+ outputs :
45+ project : ${{ steps.project.outputs.project }}
46+ exclude : ${{ steps.exclude.outputs.exclude }}
47+
1248 coverage :
49+ needs : [list-packages]
1350 strategy :
1451 fail-fast : false
1552 matrix :
16- lib :
17- - cli
18- - core
19- - models
20- - utils
21- - plugin-eslint
22- - plugin-coverage
23- - plugin-js-packages
24- - plugin-lighthouse
25- scope : [unit, int]
26- name : Update code coverage
53+ project : ${{ fromJson(needs.list-packages.outputs.project) }}
54+ target : [unit-test, int-test]
55+ exclude : ${{ fromJson(needs.list-packages.outputs.exclude) }}
56+ name : Collect code coverage
2757 runs-on : ubuntu-latest
2858 steps :
2959 - name : Checkout the repository
@@ -35,13 +65,13 @@ jobs:
3565 cache : npm
3666 - name : Install dependencies
3767 run : npm ci
38- - name : Execute all tests and generate coverage reports
39- run : npx nx run ${{ matrix.lib }}:${{ matrix.scope }}-test --coverage.enabled
68+ - name : Execute tests with coverage
69+ run : npx nx run ${{ matrix.project }}:${{ matrix.target }} --coverage.enabled
4070 - name : Upload coverage reports to Codecov
4171 uses : codecov/codecov-action@v4
4272 with :
43- directory : coverage/${{ matrix.lib }}/${{ matrix.scope }}-tests /
73+ directory : coverage/${{ matrix.project }}/${{ matrix.target }}s /
4474 files : ./lcov.info
45- flags : ${{ matrix.lib }}-${{ matrix.scope }}
75+ flags : ${{ matrix.project }}-${{ matrix.target }}
4676 token : ${{ secrets.CODECOV_TOKEN }}
4777 fail_ci_if_error : true
0 commit comments