Skip to content

Commit e15d6d4

Browse files
committed
ci: fix codecov workflow - projects and targets inferred from nx graph
1 parent d6ba73c commit e15d6d4

1 file changed

Lines changed: 61 additions & 18 deletions

File tree

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,72 @@
11
name: Code Coverage
22

3-
on:
4-
push:
5-
branches: [main]
3+
# TODO: revert
4+
on: push
5+
# on:
6+
# push:
7+
# branches: [main]
68

79
env:
810
NX_NON_NATIVE_HASHER: true
911
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
1012

1113
jobs:
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: list-packages
29+
run: |
30+
array2json () {
31+
echo "$1" | sed 's/ /\n/g' | sed '/^$/d' | jq -R | jq -s -c
32+
}
33+
34+
packages=$(npx nx show projects --projects="packages/*" | sort)
35+
printf "All packages:\n$packages\n\n"
36+
37+
packages_with_unit_tests=$(npx nx show projects --with-target=unit-test --projects="packages/*" | sort)
38+
packages_with_int_tests=$(npx nx show projects --with-target=int-test --projects="packages/*" | sort)
39+
printf "Packages with unit tests:\n$packages_with_unit_tests\n\n"
40+
printf "Packages with integration tests:\n$packages_with_int_tests\n\n"
41+
42+
project=$(array2json $packages)
43+
echo "project=$project" >> $GITHUB_OUTPUT
44+
printf "GitHub output:\nproject=$project\n\n"
45+
46+
packages_without_unit_tests=$(comm -23 <(echo $packages) <(echo $packages_with_unit_tests))
47+
packages_without_int_tests=$(comm -23 <(echo $packages) <(echo $packages_with_int_tests))
48+
printf "Packages without unit tests:\n$packages_without_unit_tests\n\n"
49+
printf "Packages without integration tests:\n$packages_without_int_tests\n\n"
50+
51+
exclude_unit_tests=$(array2json $packages_without_unit_tests | jq 'map({ "project": ., "target": "unit-test" })')
52+
exclude_int_tests=$(array2json $packages_without_int_tests | jq 'map({ "project": ., "target": "int-test" })')
53+
exclude=$(echo "$exclude_unit_tests\n$exclude_int_tests" | jq -s -c add)
54+
55+
echo "exclude=$exclude" >> $GITHUB_OUTPUT
56+
printf "GitHub output:\nexclude=$exclude\n\n"
57+
outputs:
58+
project: ${{ steps.list-packages.outputs.project }}
59+
exclude: ${{ steps.list-packages.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

Comments
 (0)