Skip to content

ci: fix codecov workflow - projects and targets inferred from nx graph #487

ci: fix codecov workflow - projects and targets inferred from nx graph

ci: fix codecov workflow - projects and targets inferred from nx graph #487

Workflow file for this run

name: Code Coverage
# TODO: revert
on: push
# on:
# push:
# branches: [main]
env:
NX_NON_NATIVE_HASHER: true
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
jobs:
list-packages:
name: List packages
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: npm
- name: Install dependencies
run: npm ci
- name: List packages using Nx CLI
id: project
run: |
packages=$(npx nx show projects --projects="packages/*" | sort)
packages_with_unit_tests=$(npx nx show projects --with-target=unit-test --projects="packages/*" | sort)
packages_with_int_tests=$(npx nx show projects --with-target=int-test --projects="packages/*" | sort)
project=$(echo $packages | jq -R | jq -s -c)
echo "project=$project" >> $GITHUB_OUTPUT
- name: Exclude package tests with missing target
id: exclude
run: |
packages_without_unit_tests=$(comm -23 <(echo $packages) <(echo $packages_with_unit_tests))
packages_without_int_tests=$(comm -23 <(echo $packages) <(echo $packages_with_int_tests))
exclude_unit_tests=$(echo $packages_without_unit_tests | sed '/^$/d' | jq -R | jq -s 'map({ "project": ., "target": "unit-test" })')
exclude_int_tests=$(echo $packages_without_int_tests | sed '/^$/d' | jq -R | jq -s 'map({ "project": ., "target": "int-test" })')
exclude=$(echo "$exclude_unit_tests\n$exclude_int_tests" | jq -s -c add)
echo "exclude=$exclude" >> $GITHUB_OUTPUT
outputs:
project: ${{ steps.project.outputs.project }}
exclude: ${{ steps.exclude.outputs.exclude }}
coverage:
needs: [list-packages]
strategy:
fail-fast: false
matrix:
project: ${{ fromJson(needs.list-packages.outputs.project) }}
target: [unit-test, int-test]
exclude: ${{ fromJson(needs.list-packages.outputs.exclude) }}
name: Collect code coverage
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: npm
- name: Install dependencies
run: npm ci
- name: Execute tests with coverage
run: npx nx run ${{ matrix.project }}:${{ matrix.target }} --coverage.enabled
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
with:
directory: coverage/${{ matrix.project }}/${{ matrix.target }}s/
files: ./lcov.info
flags: ${{ matrix.project }}-${{ matrix.target }}
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true