Skip to content

chore: Add CodeCov bundle analysis #10682

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

Closed
wants to merge 3 commits into from
Closed
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 @@ -274,6 +274,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 }}
# Under normal circumstances, using the git SHA as a cache key, there shouldn't ever be a cache hit on the built
# packages, and so `yarn build` should always run. This `if` check is therefore only there for testing CI issues
# where the built packages are beside the point. In that case, you can change `BUILD_CACHE_KEY` (at the top of
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 @@
"esbuild": "0.20.0"
},
"volta": {
"node": "18.17.1",
"node": "18.18.0",
"yarn": "1.22.19"
}
}
17 changes: 15 additions & 2 deletions dev-packages/rollup-utils/bundleHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getEs5Polyfills,
makeBrowserBuildPlugin,
makeCleanupPlugin,
makeCodeCovPlugin,
makeCommonJSPlugin,
makeIsDebugBuildPlugin,
makeLicensePlugin,
Expand Down Expand Up @@ -152,7 +153,7 @@ export function makeBaseBundleConfig(options) {
* @returns An array of versions of that config
*/
export function makeBundleConfigVariants(baseConfig, options = {}) {
const { variants = BUNDLE_VARIANTS } = options;
const { variants = BUNDLE_VARIANTS, bundleAnalysis = true } = options;

const includeDebuggingPlugin = makeIsDebugBuildPlugin(true);
const stripDebuggingPlugin = makeIsDebugBuildPlugin(false);
Expand Down Expand Up @@ -183,7 +184,7 @@ export function makeBundleConfigVariants(baseConfig, options = {}) {
},
};

return variants.map(variant => {
const bundles = variants.map(variant => {
if (!BUNDLE_VARIANTS.includes(variant)) {
throw new Error(`Unknown bundle variant requested: ${variant}`);
}
Expand All @@ -193,4 +194,16 @@ export function makeBundleConfigVariants(baseConfig, options = {}) {
customMerge: key => (key === 'plugins' ? mergePlugins : undefined),
});
});

if (bundleAnalysis) {
bundles.forEach(bundle => {
try {
bundle.plugins.push(makeCodeCovPlugin(bundle.output.entryFileNames()));
} catch (_) {
// empty
}
});
}

return bundles;
}
7 changes: 7 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 All @@ -28,6 +29,8 @@ export function makeBaseNPMConfig(options = {}) {
hasBundles = false,
packageSpecificConfig = {},
addPolyfills = true,
bundleAnalysis = true,
bundleName,
} = options;

const nodeResolvePlugin = makeNodeResolvePlugin();
Expand Down Expand Up @@ -111,6 +114,10 @@ export function makeBaseNPMConfig(options = {}) {
defaultBaseConfig.plugins.push(extractPolyfillsPlugin);
}

if (bundleAnalysis) {
defaultBaseConfig.plugins.push(makeCodeCovPlugin(bundleName));
}

return deepMerge(defaultBaseConfig, packageSpecificConfig, {
// Plugins have to be in the correct order or everything breaks, so when merging we have to manually re-order them
customMerge: key => (key === 'plugins' ? mergePlugins : undefined),
Expand Down
25 changes: 25 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 replace from '@rollup/plugin-replace';
import sucrase from '@rollup/plugin-sucrase';
import cleanup from 'rollup-plugin-cleanup';
Expand Down Expand Up @@ -131,4 +135,25 @@ 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(suffix) {
const packageJson = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), './package.json'), { encoding: 'utf8' }));

let bundleName = packageJson.name;
if (suffix != undefined) {
bundleName += `:${suffix}`;
}

return codecovRollupPlugin({
enableBundleAnalysis: process.env.GITHUB_ACTIONS === 'true' && process.env.CODECOV_TOKEN,
bundleName,
uploadToken: process.env.CODECOV_TOKEN,
});
}

export { makeExtractPolyfillsPlugin } from './extractPolyfillsPlugin.mjs';
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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 @@ -148,5 +148,8 @@
"proseWrap": "always",
"singleQuote": true,
"trailingComma": "all"
},
"dependencies": {
"@codecov/rollup-plugin": "^0.0.1-beta.0"
}
}
2 changes: 1 addition & 1 deletion packages/core/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils';

export default makeNPMConfigVariants(makeBaseNPMConfig());
export default makeNPMConfigVariants(makeBaseNPMConfig({ bundleAnalysis: 'npm:@sentry/core' }));
2 changes: 2 additions & 0 deletions packages/nextjs/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default [
),
...makeNPMConfigVariants(
makeBaseNPMConfig({
bundleName: 'config',
entrypoints: [
'src/config/templates/apiWrapperTemplate.ts',
'src/config/templates/middlewareWrapperTemplate.ts',
Expand Down Expand Up @@ -58,6 +59,7 @@ export default [
),
...makeNPMConfigVariants(
makeBaseNPMConfig({
bundleName: 'loaders',
entrypoints: ['src/config/loaders/index.ts'],

packageSpecificConfig: {
Expand Down
1 change: 1 addition & 0 deletions packages/serverless/rollup.aws.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default [
// launches (via the `NODE_OPTIONS="-r @sentry/serverless/dist/awslambda-auto"` variable). Note the inclusion in this
// path of the legacy `dist` folder; for backwards compatibility, in the build script we'll copy the file there.
makeBaseNPMConfig({
bundleName: 'awslambda-auto',
entrypoints: ['src/awslambda-auto.ts'],
packageSpecificConfig: {
// Normally `makeNPMConfigVariants` sets both of these values for us, but we don't actually want the ESM variant,
Expand Down
53 changes: 45 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2527,6 +2527,23 @@
exec-sh "^0.3.2"
minimist "^1.2.0"

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

"@codecov/rollup-plugin@^0.0.1-beta.0":
version "0.0.1-beta.0"
resolved "https://registry.yarnpkg.com/@codecov/rollup-plugin/-/rollup-plugin-0.0.1-beta.0.tgz#6d9dd52f751053171fb1576702646d1b912916fc"
integrity sha512-W0a/k8KG7FC534F/C9QrsSgH9Q07xHgvMAFm6PoUMJBdvYR8FS0NhdtUuyQTuo/zYBIone8UCYWDxnQbvmjAbQ==
dependencies:
"@codecov/bundler-plugin-core" "^0.0.1-beta.0"

"@colors/[email protected]":
version "1.5.0"
resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.5.0.tgz#bb504579c1cae923e6576a4f5da43d25f97bdbd9"
Expand Down Expand Up @@ -8086,6 +8103,11 @@ acorn@^8.10.0:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.10.0.tgz#8be5b3907a67221a81ab23c7889c4c5526b62ec5"
integrity sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==

acorn@^8.11.3:
version "8.11.3"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.11.3.tgz#71e0b14e13a4ec160724b38fb7b0f233b1b81d7a"
integrity sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==

acorn@^8.2.4, acorn@^8.4.1, acorn@^8.5.0, acorn@^8.7.0, acorn@^8.7.1:
version "8.8.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.0.tgz#88c0187620435c7f6015803f5539dae05a9dbea8"
Expand Down Expand Up @@ -11368,6 +11390,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 @@ -11379,14 +11409,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 @@ -31618,6 +31640,16 @@ [email protected]:
webpack-sources "^3.2.3"
webpack-virtual-modules "^0.5.0"

unplugin@^1.6.0:
version "1.7.1"
resolved "https://registry.yarnpkg.com/unplugin/-/unplugin-1.7.1.tgz#009571e3128640f4e327f33680d2db27afaf1e11"
integrity sha512-JqzORDAPxxs8ErLV4x+LL7bk5pk3YlcWqpSNsIkAZj972KzFZLClc/ekppahKkOczGkwIG6ElFgdOgOlK4tXZw==
dependencies:
acorn "^8.11.3"
chokidar "^3.5.3"
webpack-sources "^3.2.3"
webpack-virtual-modules "^0.6.1"

unquote@~1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/unquote/-/unquote-1.1.1.tgz#8fded7324ec6e88a0ff8b905e7c098cdc086d544"
Expand Down Expand Up @@ -32515,6 +32547,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 "4.44.1"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.44.1.tgz#17e69fff9f321b8f117d1fda714edfc0b939cc21"
Expand Down