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+ echo "All packages:\n$packages"
32+ packages_with_unit_tests=$(npx nx show projects --with-target=unit-test --projects="packages/*" | sort)
33+ packages_with_int_tests=$(npx nx show projects --with-target=int-test --projects="packages/*" | sort)
34+ echo "Packages with unit tests:\n$packages_with_unit_tests"
35+ echo "Packages with integration tests:\n$packages_with_int_tests"
36+ project=$(echo $packages | jq -R | jq -s -c)
37+ echo "project=$project" >> $GITHUB_OUTPUT
38+ echo "GitHub output:\nproject=$project"
39+ - name : Exclude package tests with missing target
40+ id : exclude
41+ run : |
42+ packages_without_unit_tests=$(comm -23 <(echo $packages) <(echo $packages_with_unit_tests))
43+ packages_without_int_tests=$(comm -23 <(echo $packages) <(echo $packages_with_int_tests))
44+ echo "Packages without unit tests:\n$packages_without_unit_tests"
45+ echo "Packages without integration tests:\n$packages_without_int_tests"
46+ exclude_unit_tests=$(echo $packages_without_unit_tests | sed '/^$/d' | jq -R | jq -s 'map({ "project": ., "target": "unit-test" })')
47+ exclude_int_tests=$(echo $packages_without_int_tests | sed '/^$/d' | jq -R | jq -s 'map({ "project": ., "target": "int-test" })')
48+ exclude=$(echo "$exclude_unit_tests\n$exclude_int_tests" | jq -s -c add)
49+ echo "exclude=$exclude" >> $GITHUB_OUTPUT
50+ echo "GitHub output:\nexclude=$exclude"
51+ outputs :
52+ project : ${{ steps.project.outputs.project }}
53+ exclude : ${{ steps.exclude.outputs.exclude }}
54+
1255 coverage :
56+ needs : [list-packages]
1357 strategy :
1458 fail-fast : false
1559 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
60+ project : ${{ fromJson(needs.list-packages.outputs.project) }}
61+ target : [unit-test, int-test]
62+ exclude : ${{ fromJson(needs.list-packages.outputs.exclude) }}
63+ name : Collect code coverage
2764 runs-on : ubuntu-latest
2865 steps :
2966 - name : Checkout the repository
@@ -35,13 +72,13 @@ jobs:
3572 cache : npm
3673 - name : Install dependencies
3774 run : npm ci
38- - name : Execute all tests and generate coverage reports
39- run : npx nx run ${{ matrix.lib }}:${{ matrix.scope }}-test --coverage.enabled
75+ - name : Execute tests with coverage
76+ run : npx nx run ${{ matrix.project }}:${{ matrix.target }} --coverage.enabled
4077 - name : Upload coverage reports to Codecov
4178 uses : codecov/codecov-action@v4
4279 with :
43- directory : coverage/${{ matrix.lib }}/${{ matrix.scope }}-tests /
80+ directory : coverage/${{ matrix.project }}/${{ matrix.target }}s /
4481 files : ./lcov.info
45- flags : ${{ matrix.lib }}-${{ matrix.scope }}
82+ flags : ${{ matrix.project }}-${{ matrix.target }}
4683 token : ${{ secrets.CODECOV_TOKEN }}
4784 fail_ci_if_error : true
0 commit comments