Skip to content

build: Add codecov bundle analysis for npm packages #11276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ jobs:
${{needs.job_get_metadata.outputs.is_develop == 'false' && env.NX_CACHE_RESTORE_KEYS || 'nx-never-restore'}}

- name: Build packages
# Set the CODECOV_TOKEN for Bundle Analysis
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: yarn build
outputs:
# this needs to be passed on, because the `needs` context only looks at direct ancestors (so steps which depend on
Expand Down
2 changes: 1 addition & 1 deletion dev-packages/e2e-tests/Dockerfile.publish-packages
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This Dockerfile exists for the purpose of using a specific node/npm version (ie. the same we use in CI) to run npm publish with
ARG NODE_VERSION=18.17.1
ARG NODE_VERSION=18.18.0
FROM node:${NODE_VERSION}

WORKDIR /sentry-javascript/dev-packages/e2e-tests
Expand Down
2 changes: 1 addition & 1 deletion dev-packages/e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"yaml": "2.2.2"
},
"volta": {
"node": "18.17.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the bump?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codecov plugins require min Node version of 18.18.0.

"node": "18.18.0",
"yarn": "1.22.19"
}
}
4 changes: 4 additions & 0 deletions dev-packages/rollup-utils/npmHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import deepMerge from 'deepmerge';

import {
makeCleanupPlugin,
makeCodeCovPlugin,
makeDebugBuildStatementReplacePlugin,
makeExtractPolyfillsPlugin,
makeNodeResolvePlugin,
Expand Down Expand Up @@ -43,6 +44,8 @@ export function makeBaseNPMConfig(options = {}) {
excludeIframe: undefined,
});

const codecovPlugin = makeCodeCovPlugin();

const defaultBaseConfig = {
input: entrypoints,

Expand Down Expand Up @@ -103,6 +106,7 @@ export function makeBaseNPMConfig(options = {}) {
debugBuildStatementReplacePlugin,
rrwebBuildPlugin,
cleanupPlugin,
codecovPlugin,
],

// don't include imported modules from outside the package in the final output
Expand Down
19 changes: 19 additions & 0 deletions dev-packages/rollup-utils/plugins/npmPlugins.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* Sucrase plugin docs: https://github.com/rollup/plugins/tree/master/packages/sucrase
*/

import * as fs from 'fs';
import * as path from 'path';

import { codecovRollupPlugin } from '@codecov/rollup-plugin';
import json from '@rollup/plugin-json';
import replace from '@rollup/plugin-replace';
import sucrase from '@rollup/plugin-sucrase';
Expand Down Expand Up @@ -138,4 +142,19 @@ export function makeRrwebBuildPlugin({ excludeShadowDom, excludeIframe } = {}) {
});
}

/**
* Plugin that uploads bundle analysis to codecov.
*
* @param type The type of bundle being uploaded.
* @param prefix The prefix for the codecov bundle name. Defaults to 'npm'.
*/
export function makeCodeCovPlugin() {
const packageJson = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), './package.json'), { encoding: 'utf8' }));
return codecovRollupPlugin({
enableBundleAnalysis: process.env.CODECOV_TOKEN !== undefined,
bundleName: packageJson.name,
uploadToken: process.env.CODECOV_TOKEN,
});
}

export { makeExtractPolyfillsPlugin } from './extractPolyfillsPlugin.mjs';
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"yalc:publish": "lerna run yalc:publish"
},
"volta": {
"node": "18.17.0",
"node": "18.18.0",
"yarn": "1.22.19"
},
"workspaces": [
Expand Down Expand Up @@ -86,6 +86,7 @@
],
"devDependencies": {
"@biomejs/biome": "^1.4.0",
"@codecov/rollup-plugin": "0.0.1-beta.5",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-esm-shim": "^0.1.5",
"@rollup/plugin-json": "^6.1.0",
Expand Down
48 changes: 40 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2316,6 +2316,23 @@
exec-sh "^0.3.2"
minimist "^1.2.0"

"@codecov/bundler-plugin-core@^0.0.1-beta.5":
version "0.0.1-beta.5"
resolved "https://registry.yarnpkg.com/@codecov/bundler-plugin-core/-/bundler-plugin-core-0.0.1-beta.5.tgz#f516c080abe4c99fb5cfdc7d39513b277fac2bae"
integrity sha512-eltwv1aRJdwonlTD47jQ2GYdKZfMv3jCviDui32JOu12ZAiI3WdJCtjWF9zxpmnHEZ30pn0WbeZir+sXSFLJHw==
dependencies:
chalk "4.1.2"
semver "^7.5.4"
unplugin "^1.6.0"
zod "^3.22.4"

"@codecov/[email protected]":
version "0.0.1-beta.5"
resolved "https://registry.yarnpkg.com/@codecov/rollup-plugin/-/rollup-plugin-0.0.1-beta.5.tgz#cca4c68989efbcf4e2dbe3db5e9a5bf5b7501fe2"
integrity sha512-3x6vmt59Hgfpr8jroB7LYa2XX+kFds8HaWsUTBX08sJ2bCw+BzlW1Mnc+IdxBdMtjo1jkYEceRvfwQ0X2LK4ZQ==
dependencies:
"@codecov/bundler-plugin-core" "^0.0.1-beta.5"

"@colors/[email protected]":
version "1.5.0"
resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.5.0.tgz#bb504579c1cae923e6576a4f5da43d25f97bdbd9"
Expand Down Expand Up @@ -11337,6 +11354,14 @@ [email protected]:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

[email protected], chalk@^4.0.0, chalk@^4.0.2, chalk@^4.1.0, chalk@^4.1.1, chalk@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
dependencies:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

chalk@^1.0.0, chalk@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
Expand All @@ -11348,14 +11373,6 @@ chalk@^1.0.0, chalk@^1.1.3:
strip-ansi "^3.0.0"
supports-color "^2.0.0"

chalk@^4.0.0, chalk@^4.0.2, chalk@^4.1.0, chalk@^4.1.1, chalk@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
dependencies:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

chalk@^5.0.0, chalk@^5.2.0, chalk@^5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.3.0.tgz#67c20a7ebef70e7f3970a01f90fa210cb6860385"
Expand Down Expand Up @@ -29331,6 +29348,16 @@ [email protected]:
webpack-sources "^3.2.3"
webpack-virtual-modules "^0.5.0"

unplugin@^1.6.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/unplugin/-/unplugin-1.10.0.tgz#9cb8140f61e3fbcf27c7c38d305e9d62d5dbbf0b"
integrity sha512-CuZtvvO8ua2Wl+9q2jEaqH6m3DoQ38N7pvBYQbbaeNlWGvK2l6GHiKi29aIHDPoSxdUzQ7Unevf1/ugil5X6Pg==
dependencies:
acorn "^8.11.3"
chokidar "^3.6.0"
webpack-sources "^3.2.3"
webpack-virtual-modules "^0.6.1"

unset-value@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/unset-value/-/unset-value-1.0.0.tgz#8376873f7d2335179ffb1e6fc3a8ed0dfc8ab559"
Expand Down Expand Up @@ -30112,6 +30139,11 @@ webpack-virtual-modules@^0.5.0:
resolved "https://registry.yarnpkg.com/webpack-virtual-modules/-/webpack-virtual-modules-0.5.0.tgz#362f14738a56dae107937ab98ea7062e8bdd3b6c"
integrity sha512-kyDivFZ7ZM0BVOUteVbDFhlRt7Ah/CSPwJdi8hBpkK7QLumUqdLtVfm/PX/hkcnrvr0i77fO5+TjZ94Pe+C9iw==

webpack-virtual-modules@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/webpack-virtual-modules/-/webpack-virtual-modules-0.6.1.tgz#ac6fdb9c5adb8caecd82ec241c9631b7a3681b6f"
integrity sha512-poXpCylU7ExuvZK8z+On3kX+S8o/2dQ/SVYueKA0D4WEMXROXgY8Ez50/bQEUmvoSMMrWcrJqCHuhAbsiwg7Dg==

[email protected]:
version "5.76.1"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.76.1.tgz#7773de017e988bccb0f13c7d75ec245f377d295c"
Expand Down