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+ echo '$packages | jq -R'
37+ echo $packages | jq -R
38+ echo '$packages | jq -R | jq -s'
39+ echo $packages | jq -R | jq -s
40+ echo '$packages | jq -R | jq -s -c'
41+ echo $packages | jq -R | jq -s -c
42+ project=$(echo $packages | jq -R | jq -s -c)
43+ echo "project=$project" >> $GITHUB_OUTPUT
44+ printf "GitHub output:\nproject=$project\n\n"
45+ - name : Exclude package tests with missing target
46+ id : exclude
47+ run : |
48+ packages_without_unit_tests=$(comm -23 <(echo $packages) <(echo $packages_with_unit_tests))
49+ packages_without_int_tests=$(comm -23 <(echo $packages) <(echo $packages_with_int_tests))
50+ printf "Packages without unit tests:\n$packages_without_unit_tests\n\n"
51+ printf "Packages without integration tests:\n$packages_without_int_tests\n\n"
52+ exclude_unit_tests=$(echo $packages_without_unit_tests | sed '/^$/d' | jq -R | jq -s 'map({ "project": ., "target": "unit-test" })')
53+ exclude_int_tests=$(echo $packages_without_int_tests | sed '/^$/d' | jq -R | jq -s 'map({ "project": ., "target": "int-test" })')
54+ exclude=$(echo "$exclude_unit_tests\n$exclude_int_tests" | jq -s -c add)
55+ echo "exclude=$exclude" >> $GITHUB_OUTPUT
56+ printf "GitHub output:\nexclude=$exclude\n\n"
57+ outputs :
58+ project : ${{ steps.project.outputs.project }}
59+ exclude : ${{ steps.exclude.outputs.exclude }}
60+
1261 coverage :
62+ needs : [list-packages]
1363 strategy :
1464 fail-fast : false
1565 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
66+ project : ${{ fromJson(needs.list-packages.outputs.project) }}
67+ target : [unit-test, int-test]
68+ exclude : ${{ fromJson(needs.list-packages.outputs.exclude) }}
69+ name : Collect code coverage
2770 runs-on : ubuntu-latest
2871 steps :
2972 - name : Checkout the repository
@@ -35,13 +78,13 @@ jobs:
3578 cache : npm
3679 - name : Install dependencies
3780 run : npm ci
38- - name : Execute all tests and generate coverage reports
39- run : npx nx run ${{ matrix.lib }}:${{ matrix.scope }}-test --coverage.enabled
81+ - name : Execute tests with coverage
82+ run : npx nx run ${{ matrix.project }}:${{ matrix.target }} --coverage.enabled
4083 - name : Upload coverage reports to Codecov
4184 uses : codecov/codecov-action@v4
4285 with :
43- directory : coverage/${{ matrix.lib }}/${{ matrix.scope }}-tests /
86+ directory : coverage/${{ matrix.project }}/${{ matrix.target }}s /
4487 files : ./lcov.info
45- flags : ${{ matrix.lib }}-${{ matrix.scope }}
88+ flags : ${{ matrix.project }}-${{ matrix.target }}
4689 token : ${{ secrets.CODECOV_TOKEN }}
4790 fail_ci_if_error : true
0 commit comments