Skip to content

Commit 4d5b682

Browse files
authored
Adding dedicated codecov upload job (#3817)
1 parent f032486 commit 4d5b682

1 file changed

Lines changed: 60 additions & 40 deletions

File tree

.circleci/config.yml

Lines changed: 60 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,7 @@ commands:
106106
type: string
107107
test_type:
108108
type: string
109-
coverage:
110-
type: boolean
111-
default: false
112109
steps:
113-
- when:
114-
condition: << parameters.coverage >>
115-
steps: []
116110
- setup_nx_cache
117111
- run:
118112
name: Run << parameters.test_type >> tests for << parameters.package >>
@@ -121,21 +115,6 @@ commands:
121115
JEST_MAX_WORKERS: '1'
122116
command: yarn test:<< parameters.test_type >> --projects=<< parameters.package >>
123117
no_output_timeout: 30m
124-
- when:
125-
condition: << parameters.coverage >>
126-
steps:
127-
- run:
128-
name: Calculate package directory
129-
command: |
130-
PACKAGE_DIR=$(echo "<< parameters.package >>" | rev | cut -d'/' -f1 | rev)
131-
echo "export PACKAGE_DIR=${PACKAGE_DIR}" >> $BASH_ENV
132-
- codecov/upload:
133-
files: packages/${PACKAGE_DIR}/coverage/lcov.info
134-
disable_search: true
135-
- codecov/upload:
136-
files: packages/${PACKAGE_DIR}/reports/*junit.xml
137-
report_type: test_results
138-
disable_search: true
139118
- save_nx_cache
140119

141120
# ====================
@@ -157,21 +136,6 @@ jobs:
157136
- run:
158137
name: Build packages
159138
command: yarn build
160-
- run:
161-
name: Upload bundle analysis
162-
command: |
163-
yarn dlx @codecov/bundle-analyzer packages/requester-utils/dist \
164-
--bundle-name=requester-utils \
165-
--upload-token=$CODECOV_TOKEN
166-
yarn dlx @codecov/bundle-analyzer packages/core/dist \
167-
--bundle-name=core \
168-
--upload-token=$CODECOV_TOKEN
169-
yarn dlx @codecov/bundle-analyzer packages/rest/dist \
170-
--bundle-name=rest \
171-
--upload-token=$CODECOV_TOKEN
172-
yarn dlx @codecov/bundle-analyzer packages/cli/dist \
173-
--bundle-name=cli \
174-
--upload-token=$CODECOV_TOKEN
175139
- save_nx_cache
176140
- persist_to_workspace:
177141
root: .
@@ -208,7 +172,6 @@ jobs:
208172
- run_package_tests:
209173
package: '@gitbeaker/requester-utils'
210174
test_type: 'unit'
211-
coverage: true
212175

213176
test-unit-core:
214177
executor: node-executor
@@ -217,7 +180,6 @@ jobs:
217180
- run_package_tests:
218181
package: '@gitbeaker/core'
219182
test_type: 'unit'
220-
coverage: true
221183

222184
test-unit-rest:
223185
executor: node-executor
@@ -226,7 +188,6 @@ jobs:
226188
- run_package_tests:
227189
package: '@gitbeaker/rest'
228190
test_type: 'unit'
229-
coverage: true
230191

231192
test-unit-cli:
232193
executor: node-executor
@@ -235,7 +196,6 @@ jobs:
235196
- run_package_tests:
236197
package: '@gitbeaker/cli'
237198
test_type: 'unit'
238-
coverage: true
239199

240200
# ====================
241201
# TYPE TESTS
@@ -443,6 +403,53 @@ jobs:
443403
echo "No gitlab-env.txt file found - no GitLab instance to clean up"
444404
fi
445405
406+
# ====================
407+
# CODECOV UPLOAD
408+
# ====================
409+
codecov-upload:
410+
executor: node-executor
411+
description: 'Upload coverage reports and bundle analysis to Codecov'
412+
steps:
413+
- restore_workspace
414+
- run:
415+
name: Upload coverage reports
416+
command: |
417+
# Upload coverage reports for each package that has coverage
418+
for coverage_file in packages/*/coverage/lcov.info; do
419+
if [ -f "$coverage_file" ]; then
420+
package=$(basename $(dirname $(dirname "$coverage_file")))
421+
echo "Uploading coverage for ${package}..."
422+
yarn dlx @codecov/cli upload-coverage \
423+
--file "$coverage_file" \
424+
--flags ${package}
425+
fi
426+
done
427+
- run:
428+
name: Upload test results
429+
command: |
430+
# Upload test results for each package that has test reports
431+
for reports_dir in packages/*/reports; do
432+
if [ -d "$reports_dir" ] && [ "$(ls -A "$reports_dir"/*.xml 2>/dev/null)" ]; then
433+
package=$(basename $(dirname "$reports_dir"))
434+
echo "Uploading test results for ${package}..."
435+
yarn dlx @codecov/cli upload-test-results \
436+
--dir "$reports_dir"
437+
fi
438+
done
439+
- run:
440+
name: Upload bundle analysis
441+
command: |
442+
# Upload bundle analysis for each package that has built dist
443+
for dist_dir in packages/*/dist; do
444+
if [ -d "$dist_dir" ]; then
445+
package=$(basename $(dirname "$dist_dir"))
446+
echo "Uploading bundle analysis for ${package}..."
447+
yarn dlx @codecov/bundle-analyzer "$dist_dir" \
448+
--bundle-name=${package} \
449+
--upload-token=$CODECOV_TOKEN
450+
fi
451+
done
452+
446453
# ====================
447454
# RELEASE JOBS
448455
# ====================
@@ -612,6 +619,19 @@ workflows:
612619
branches:
613620
ignore: [main, next]
614621

622+
# Codecov uploads (only on non-forked branches to avoid token access issues)
623+
- codecov-upload:
624+
requires:
625+
- build
626+
- test-unit-utils
627+
- test-unit-core
628+
- test-unit-rest
629+
- test-unit-cli
630+
filters:
631+
branches:
632+
# Exclude forked PR branches which start with 'pull/'
633+
ignore: /^pull\/.*/
634+
615635
# Releases
616636
- release-canary:
617637
requires:

0 commit comments

Comments
 (0)