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+ printf "All packages:\n$packages\n\n"
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+ printf "Packages with unit tests:\n$packages_with_unit_tests\n\n"
35+ printf "Packages with integration tests:\n$packages_with_int_tests\n\n"
36+ array2json () {
37+ echo "$1" | sed 's/ /\n/g' | sed '/^$/d' | jq -R | jq -s -c
38+ }
39+ project=$(array2json $packages)
40+ echo "project=$project" >> $GITHUB_OUTPUT
41+ printf "GitHub output:\nproject=$project\n\n"
42+ - name : Exclude package tests with missing target
43+ id : exclude
44+ run : |
45+ packages_without_unit_tests=$(comm -23 <(echo $packages) <(echo $packages_with_unit_tests))
46+ packages_without_int_tests=$(comm -23 <(echo $packages) <(echo $packages_with_int_tests))
47+ printf "Packages without unit tests:\n$packages_without_unit_tests\n\n"
48+ printf "Packages without integration tests:\n$packages_without_int_tests\n\n"
49+ exclude_unit_tests=$(array2json $packages_without_unit_tests | jq 'map({ "project": ., "target": "unit-test" })')
50+ exclude_int_tests=$(array2json $packages_without_int_tests | jq 'map({ "project": ., "target": "int-test" })')
51+ exclude=$(echo "$exclude_unit_tests\n$exclude_int_tests" | jq -s -c add)
52+ echo "exclude=$exclude" >> $GITHUB_OUTPUT
53+ printf "GitHub output:\nexclude=$exclude\n\n"
54+ outputs :
55+ project : ${{ steps.project.outputs.project }}
56+ exclude : ${{ steps.exclude.outputs.exclude }}
57+
1258 coverage :
59+ needs : [list-packages]
1360 strategy :
1461 fail-fast : false
1562 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
63+ project : ${{ fromJson(needs.list-packages.outputs.project) }}
64+ target : [unit-test, int-test]
65+ exclude : ${{ fromJson(needs.list-packages.outputs.exclude) }}
66+ name : Collect code coverage
2767 runs-on : ubuntu-latest
2868 steps :
2969 - name : Checkout the repository
@@ -35,13 +75,13 @@ jobs:
3575 cache : npm
3676 - name : Install dependencies
3777 run : npm ci
38- - name : Execute all tests and generate coverage reports
39- run : npx nx run ${{ matrix.lib }}:${{ matrix.scope }}-test --coverage.enabled
78+ - name : Execute tests with coverage
79+ run : npx nx run ${{ matrix.project }}:${{ matrix.target }} --coverage.enabled
4080 - name : Upload coverage reports to Codecov
4181 uses : codecov/codecov-action@v4
4282 with :
43- directory : coverage/${{ matrix.lib }}/${{ matrix.scope }}-tests /
83+ directory : coverage/${{ matrix.project }}/${{ matrix.target }}s /
4484 files : ./lcov.info
45- flags : ${{ matrix.lib }}-${{ matrix.scope }}
85+ flags : ${{ matrix.project }}-${{ matrix.target }}
4686 token : ${{ secrets.CODECOV_TOKEN }}
4787 fail_ci_if_error : true
0 commit comments