Skip to content

Commit 2300dc1

Browse files
authored
chore: improve test workflow and coverage reports (#2866)
1 parent 511e5fd commit 2300dc1

File tree

43 files changed

+319
-188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+319
-188
lines changed

.github/workflows/test-all-versions.pr.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

.github/workflows/test-all-versions.push.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

.github/workflows/unit-test.yml renamed to .github/workflows/test.yml

Lines changed: 93 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
name: Unit Tests
1+
name: Test Packages
22
on:
33
push:
44
branches: [main]
55
pull_request:
6+
branches: [main]
67

78
permissions:
89
contents: read
910

1011
jobs:
11-
build-and-cache:
12+
compile:
1213
strategy:
1314
fail-fast: false
1415
runs-on: ubuntu-latest
@@ -26,19 +27,33 @@ jobs:
2627
node-version: 18
2728
- name: Install
2829
run: npm ci
29-
- name: Build
30-
run: npm run compile
30+
# Note: when pushing to main we want to test only what changed in
31+
# last commit. Otherwise we want to test all changes from origin/main.
32+
# So we set the right values for base and head commits depending
33+
# on the type of event (PR or push)
34+
# ref: https://nx.dev/ci/features/affected#configure-affected-on-ci
35+
- name: Set base and head commits
36+
run: |
37+
if [ "${{github.event_name}}" == "push" ]; then
38+
echo "NX_BASE=origin/main~1" >> "$GITHUB_ENV"
39+
echo "NX_HEAD=origin/main" >> "$GITHUB_ENV"
40+
else
41+
echo "NX_BASE=origin/main" >> "$GITHUB_ENV"
42+
echo "NX_HEAD=HEAD" >> "$GITHUB_ENV"
43+
fi
44+
- name: Compile (Delta)
45+
run: npm run compile:ci:affected
3146
- name: Upload Build Artifacts
3247
uses: actions/upload-artifact@v4
3348
with:
34-
name: tests-build-cache-${{ github.run_number }}
49+
name: compile-cache-${{ github.run_number }}
3550
path: .nx
3651
include-hidden-files: true
3752
if-no-files-found: error
3853
retention-days: 1
3954

4055
unit-test:
41-
needs: build-and-cache
56+
needs: compile
4257
strategy:
4358
fail-fast: false
4459
matrix:
@@ -172,6 +187,7 @@ jobs:
172187
POSTGRES_USER: postgres
173188
POSTGRES_PASSWORD: postgres
174189
NPM_CONFIG_UNSAFE_PERM: true
190+
NODE_OPTIONS: --max-old-space-size=4096
175191
steps:
176192
- name: Checkout
177193
uses: actions/checkout@v5
@@ -185,56 +201,90 @@ jobs:
185201
- name: Download Build Artifacts
186202
uses: actions/download-artifact@v5
187203
with:
188-
name: tests-build-cache-${{ github.run_number }}
204+
name: compile-cache-${{ github.run_number }}
189205
path: .nx
190-
- name: Build
191-
run: npm run compile
192-
- name: Unit tests (Full)
193-
if: matrix.code-coverage
194-
run: npm run test
195-
- name: Unit tests (Delta)
196-
if: ${{ !matrix.code-coverage }}
197-
run: npm run test:ci:changed
198-
- name: Report Coverage
199-
if: ${{ matrix.code-coverage && !cancelled()}}
200-
uses: codecov/codecov-action@v5
201-
env:
202-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
206+
# Note: see comment in the compile job
207+
- name: Set base and head commits
208+
run: |
209+
if [ "${{github.event_name}}" == "push" ]; then
210+
echo "NX_BASE=origin/main~1" >> "$GITHUB_ENV"
211+
echo "NX_HEAD=origin/main" >> "$GITHUB_ENV"
212+
else
213+
echo "NX_BASE=origin/main" >> "$GITHUB_ENV"
214+
echo "NX_HEAD=HEAD" >> "$GITHUB_ENV"
215+
fi
216+
- name: Compile (Delta)
217+
run: npm run compile:ci:affected
218+
- name: Unit tests (Browser - Delta)
219+
if: ${{ matrix.node == '22' }}
220+
run: npm run test:browser:ci:affected
221+
- name: Unit tests (Nodejs - Delta)
222+
run: npm run test:ci:affected
223+
- name: Test All Versions (Delta)
224+
run: npm run test-all-versions:ci:affected
225+
- name: Upload Test Artifacts
226+
uses: actions/upload-artifact@v4
203227
with:
204-
verbose: true
228+
name: tests-coverage-cache-${{ github.run_number }}-${{ matrix.node }}
229+
include-hidden-files: true
230+
if-no-files-found: error
231+
retention-days: 1
232+
path: |
233+
!node_modules
234+
packages/*/.nyc_output/**
235+
LICENSE
205236
206-
browser-test:
207-
needs: build-and-cache
208-
strategy:
209-
fail-fast: false
210-
matrix:
211-
node: ["22"]
237+
test-coverage-report:
212238
runs-on: ubuntu-latest
213-
env:
214-
NPM_CONFIG_UNSAFE_PERM: true
215-
NODE_OPTIONS: --max-old-space-size=4096
239+
needs: unit-test
216240
steps:
217241
- name: Checkout
218242
uses: actions/checkout@v5
219243
with:
220244
fetch-depth: 0
221245
- uses: actions/setup-node@v4
222246
with:
223-
node-version: ${{ matrix.node }}
247+
node-version: 18
224248
- name: Install
225249
run: npm ci
226-
- name: Download Build Artifacts
250+
# NOTE: keep this in sync with the node versions from `unit-test` job
251+
- name: Download Test Artifacts (18)
227252
uses: actions/download-artifact@v5
228253
with:
229-
name: tests-build-cache-${{ github.run_number }}
230-
path: .nx
231-
- name: Build
232-
run: npm run compile
233-
- name: Unit tests
234-
run: npm run test:browser
235-
- name: Report Coverage
236-
uses: codecov/codecov-action@v5
237-
env:
238-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
254+
name: tests-coverage-cache-${{ github.run_number }}-18
255+
path: .
256+
- name: Download Test Artifacts (18.19.0)
257+
uses: actions/download-artifact@v5
239258
with:
240-
verbose: true
259+
name: tests-coverage-cache-${{ github.run_number }}-18.19.0
260+
path: .
261+
- name: Download Test Artifacts (20)
262+
uses: actions/download-artifact@v5
263+
with:
264+
name: tests-coverage-cache-${{ github.run_number }}-20
265+
path: .
266+
- name: Download Test Artifacts (20.6.0)
267+
uses: actions/download-artifact@v5
268+
with:
269+
name: tests-coverage-cache-${{ github.run_number }}-20.6.0
270+
path: .
271+
- name: Download Test Artifacts (22)
272+
uses: actions/download-artifact@v5
273+
with:
274+
name: tests-coverage-cache-${{ github.run_number }}-22
275+
path: .
276+
# Note: see comment in the compile job
277+
- name: Set base and head commits
278+
run: |
279+
if [ "${{github.event_name}}" == "push" ]; then
280+
echo "NX_BASE=origin/main~1" >> "$GITHUB_ENV"
281+
echo "NX_HEAD=origin/main" >> "$GITHUB_ENV"
282+
else
283+
echo "NX_BASE=origin/main" >> "$GITHUB_ENV"
284+
echo "NX_HEAD=HEAD" >> "$GITHUB_ENV"
285+
fi
286+
- name: Merge coverage (Delta)
287+
run: npm run test-merge-coverage:ci:affected
288+
- name: Report Coverage with Flags
289+
run: node ./scripts/codecov-upload-flags.mjs ${{ github.event.pull_request.head.sha }} ${{ github.event.pull_request.head.label }}
290+

codecov.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
codecov:
22
notify:
3-
require_ci_to_pass: no
3+
after_n_builds: 1
4+
require_ci_to_pass: no
45
comment:
5-
layout: "header, changes, diff, files"
6+
layout: "header, changes, diff, flags, files"
67
behavior: default
78
coverage:
89
status:
@@ -13,3 +14,11 @@ coverage:
1314
default:
1415
target: auto
1516
threshold: 1%
17+
# Codecov action does not read this file to do the split of coverage
18+
# by flag. So there is no reason to have explicit flag definition.
19+
# We use automatinc flag management.
20+
# ref: https://about.codecov.io/blog/introducing-improved-flag-management-with-automatic-flags/
21+
# note: Uploads are made per package(flag) in ./scripts/codecov-upload-flags.mjs
22+
flag_management:
23+
default_rules:
24+
carryforward: true

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@
1313
"clean": "nx run-many -t clean",
1414
"version:update": "nx run-many -t version:update",
1515
"compile": "nx run-many -t compile",
16+
"compile:ci:affected": "nx affected -t compile",
1617
"test": "nx run-many -t test",
18+
"test:ci:affected": "nx affected -t test",
1719
"test:browser": "nx run-many -t test:browser",
18-
"test:ci:changed": "nx affected -t test --base=origin/main --head=HEAD",
19-
"test-all-versions": "nx run-many -t test-all-versions",
20+
"test:browser:ci:affected": "nx affected -t test:browser",
21+
"test-all-versions": "nx run-many --parallel=false -t test-all-versions",
22+
"test-all-versions:ci:affected": "nx affected --parallel=false -t test-all-versions",
23+
"test-merge-coverage:ci:affected": "nx affected -t test-merge-coverage",
2024
"test-services:start": "docker compose -f ./test/docker-compose.yaml up -d --wait",
2125
"test-services:stop": "docker compose -f ./test/docker-compose.yaml down",
2226
"test:with-services-env": "cross-env NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=./test/test-services.env npm test",
27+
"test-all-versions:with-services-env": "cross-env NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=./test/test-services.env npm run test-all-versions",
2328
"changelog": "lerna-changelog",
2429
"lint": "nx run-many -t lint && npm run lint:deps && npm run lint:readme && npm run lint:markdown && npm run lint:semconv-deps && npm run lint:examples",
2530
"lint:fix": "nx run-many -t lint:fix && npm run lint:markdown:fix",

packages/instrumentation-amqplib/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@
3838
"lint:readme": "node ../../scripts/lint-readme.js",
3939
"prepublishOnly": "npm run compile",
4040
"tdd": "npm run test -- --watch-extensions ts --watch",
41-
"test": "nyc mocha --require '@opentelemetry/contrib-test-utils' 'test/**/*.test.ts'",
41+
"test": "nyc --no-clean mocha --require '@opentelemetry/contrib-test-utils' 'test/**/*.test.ts'",
4242
"test:with-services-env": "cross-env NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../test/test-services.env npm test",
4343
"test-all-versions": "tav",
4444
"test-all-versions:with-services-env": "cross-env NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../test/test-services.env npm run test-all-versions",
45+
"test-merge-coverage": "nyc merge .nyc_output coverage/coverage-final.json",
4546
"test-services:start": "cd ../.. && npm run test-services:start rabbitmq",
4647
"test-services:stop": "cd ../.. && npm run test-services:stop rabbitmq",
4748
"version:update": "node ../../scripts/version-update.js",

packages/instrumentation-aws-lambda/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@
1010
"directory": "packages/instrumentation-aws-lambda"
1111
},
1212
"scripts": {
13-
"test": "nyc mocha 'test/**/*.test.ts'",
14-
"tdd": "npm run test -- --watch-extensions ts --watch",
1513
"clean": "rimraf build/*",
14+
"compile": "tsc -p .",
15+
"compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/instrumentation-aws-lambda",
1616
"lint": "eslint . --ext=ts,js,mjs",
1717
"lint:fix": "eslint . --ext=ts,js,mjs --fix",
1818
"lint:readme": "node ../../scripts/lint-readme.js",
1919
"prepublishOnly": "npm run compile",
20-
"version:update": "node ../../scripts/version-update.js",
21-
"compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/instrumentation-aws-lambda",
22-
"compile": "tsc -p ."
20+
"tdd": "npm run test -- --watch-extensions ts --watch",
21+
"test": "nyc --no-clean mocha 'test/**/*.test.ts'",
22+
"test-merge-coverage": "nyc merge .nyc_output coverage/coverage-final.json",
23+
"version:update": "node ../../scripts/version-update.js"
2324
},
2425
"keywords": [
2526
"aws-lambda",

packages/instrumentation-bunyan/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
},
1212
"scripts": {
1313
"clean": "rimraf build/*",
14-
"compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/instrumentation-bunyan",
1514
"compile": "tsc -p .",
15+
"compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/instrumentation-bunyan",
1616
"lint": "eslint . --ext=ts,js,mjs",
1717
"lint:fix": "eslint . --ext=ts,js,mjs --fix",
1818
"prepublishOnly": "npm run compile",
1919
"tdd": "npm run test -- --watch-extensions ts --watch",
20-
"test": "nyc mocha 'test/**/*.test.ts'",
20+
"test": "nyc --no-clean mocha 'test/**/*.test.ts'",
2121
"test-all-versions": "tav",
22+
"test-merge-coverage": "nyc merge .nyc_output coverage/coverage-final.json",
2223
"version:update": "node ../../scripts/version-update.js"
2324
},
2425
"keywords": [

packages/instrumentation-cassandra-driver/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
"lint:fix": "eslint . --ext=ts,js,mjs --fix",
1818
"lint:readme": "node ../../scripts/lint-readme.js",
1919
"prepublishOnly": "npm run compile",
20+
"setup:dev": "nx run-many -t compile -p @opentelemetry/instrumentation-cassandra-driver",
2021
"tdd": "npm run test -- --watch-extensions ts --watch",
21-
"test": "nyc mocha 'test/**/*.test.ts'",
22+
"test": "nyc --no-clean mocha 'test/**/*.test.ts'",
2223
"test:with-services-env": "cross-env NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../test/test-services.env npm test",
2324
"//todo": "echo \"add test-all-versions\"",
25+
"test-merge-coverage": "nyc merge .nyc_output coverage/coverage-final.json",
2426
"test-services:start": "cd ../.. && npm run test-services:start cassandra",
2527
"test-services:stop": "cd ../.. && npm run test-services:stop cassandra",
2628
"version:update": "node ../../scripts/version-update.js"

packages/instrumentation-connect/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"lint:fix": "eslint . --ext=ts,js,mjs --fix",
1818
"lint:readme": "node ../../scripts/lint-readme.js",
1919
"prepublishOnly": "npm run compile",
20-
"test": "nyc mocha 'test/**/*.test.ts'",
20+
"test": "nyc --no-clean mocha 'test/**/*.test.ts'",
21+
"test-merge-coverage": "nyc merge .nyc_output coverage/coverage-final.json",
2122
"version:update": "node ../../scripts/version-update.js",
2223
"watch": "tsc -w"
2324
},

0 commit comments

Comments
 (0)