Skip to content

Commit 256c892

Browse files
committed
try uploading all bundles
1 parent 0ec4059 commit 256c892

File tree

6 files changed

+39
-7
lines changed

6 files changed

+39
-7
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ concurrency:
2323

2424
env:
2525
HEAD_COMMIT: ${{ github.event.inputs.commit || github.sha }}
26-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2726

2827
# WARNING: this disables cross os caching as ~ and
2928
# github.workspace evaluate to differents paths
@@ -275,6 +274,9 @@ jobs:
275274
${{needs.job_get_metadata.outputs.is_develop == 'false' && env.NX_CACHE_RESTORE_KEYS || 'nx-never-restore'}}
276275

277276
- name: Build packages
277+
# Set the CODECOV_TOKEN for Bundle Analysis
278+
env:
279+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
278280
# Under normal circumstances, using the git SHA as a cache key, there shouldn't ever be a cache hit on the built
279281
# packages, and so `yarn build` should always run. This `if` check is therefore only there for testing CI issues
280282
# where the built packages are beside the point. In that case, you can change `BUILD_CACHE_KEY` (at the top of

dev-packages/rollup-utils/bundleHelpers.mjs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
getEs5Polyfills,
1111
makeBrowserBuildPlugin,
1212
makeCleanupPlugin,
13+
makeCodeCovPlugin,
1314
makeCommonJSPlugin,
1415
makeIsDebugBuildPlugin,
1516
makeLicensePlugin,
@@ -152,7 +153,7 @@ export function makeBaseBundleConfig(options) {
152153
* @returns An array of versions of that config
153154
*/
154155
export function makeBundleConfigVariants(baseConfig, options = {}) {
155-
const { variants = BUNDLE_VARIANTS } = options;
156+
const { variants = BUNDLE_VARIANTS, bundleAnalysis = true } = options;
156157

157158
const includeDebuggingPlugin = makeIsDebugBuildPlugin(true);
158159
const stripDebuggingPlugin = makeIsDebugBuildPlugin(false);
@@ -183,7 +184,7 @@ export function makeBundleConfigVariants(baseConfig, options = {}) {
183184
},
184185
};
185186

186-
return variants.map(variant => {
187+
const bundles = variants.map(variant => {
187188
if (!BUNDLE_VARIANTS.includes(variant)) {
188189
throw new Error(`Unknown bundle variant requested: ${variant}`);
189190
}
@@ -193,4 +194,16 @@ export function makeBundleConfigVariants(baseConfig, options = {}) {
193194
customMerge: key => (key === 'plugins' ? mergePlugins : undefined),
194195
});
195196
});
197+
198+
if (bundleAnalysis) {
199+
bundles.forEach(bundle => {
200+
try {
201+
bundle.plugins.push(makeCodeCovPlugin(bundle.output.entryFileNames()));
202+
} catch (_) {
203+
// empty
204+
}
205+
});
206+
}
207+
208+
return bundles;
196209
}

dev-packages/rollup-utils/npmHelpers.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export function makeBaseNPMConfig(options = {}) {
2929
hasBundles = false,
3030
packageSpecificConfig = {},
3131
addPolyfills = true,
32-
bundleAnalysis,
32+
bundleAnalysis = true,
33+
bundleName,
3334
} = options;
3435

3536
const nodeResolvePlugin = makeNodeResolvePlugin();
@@ -113,8 +114,8 @@ export function makeBaseNPMConfig(options = {}) {
113114
defaultBaseConfig.plugins.push(extractPolyfillsPlugin);
114115
}
115116

116-
if (bundleAnalysis && bundleAnalysis.length) {
117-
defaultBaseConfig.plugins.push(makeCodeCovPlugin(bundleAnalysis));
117+
if (bundleAnalysis) {
118+
defaultBaseConfig.plugins.push(makeCodeCovPlugin(bundleName));
118119
}
119120

120121
return deepMerge(defaultBaseConfig, packageSpecificConfig, {

dev-packages/rollup-utils/plugins/npmPlugins.mjs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
* Sucrase plugin docs: https://github.com/rollup/plugins/tree/master/packages/sucrase
88
*/
99

10+
import * as fs from 'fs';
11+
import * as path from 'path';
12+
1013
import { codecovRollupPlugin } from '@codecov/rollup-plugin';
1114
import replace from '@rollup/plugin-replace';
1215
import sucrase from '@rollup/plugin-sucrase';
@@ -134,8 +137,18 @@ export function makeRrwebBuildPlugin({ excludeShadowDom, excludeIframe } = {}) {
134137

135138
/**
136139
* Plugin that uploads bundle analysis to codecov.
140+
*
141+
* @param type The type of bundle being uploaded.
142+
* @param prefix The prefix for the codecov bundle name. Defaults to 'npm'.
137143
*/
138-
export function makeCodeCovPlugin(bundleName) {
144+
export function makeCodeCovPlugin(suffix) {
145+
const packageJson = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), './package.json'), { encoding: 'utf8' }));
146+
147+
let bundleName = packageJson.name;
148+
if (suffix != undefined) {
149+
bundleName += `:${suffix}`;
150+
}
151+
139152
return codecovRollupPlugin({
140153
enableBundleAnalysis: process.env.GITHUB_ACTIONS === 'true' && process.env.CODECOV_TOKEN,
141154
bundleName,

packages/nextjs/rollup.npm.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default [
2323
),
2424
...makeNPMConfigVariants(
2525
makeBaseNPMConfig({
26+
bundleName: 'config',
2627
entrypoints: [
2728
'src/config/templates/apiWrapperTemplate.ts',
2829
'src/config/templates/middlewareWrapperTemplate.ts',
@@ -58,6 +59,7 @@ export default [
5859
),
5960
...makeNPMConfigVariants(
6061
makeBaseNPMConfig({
62+
bundleName: 'loaders',
6163
entrypoints: ['src/config/loaders/index.ts'],
6264

6365
packageSpecificConfig: {

packages/serverless/rollup.aws.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default [
2727
// launches (via the `NODE_OPTIONS="-r @sentry/serverless/dist/awslambda-auto"` variable). Note the inclusion in this
2828
// path of the legacy `dist` folder; for backwards compatibility, in the build script we'll copy the file there.
2929
makeBaseNPMConfig({
30+
bundleName: 'awslambda-auto',
3031
entrypoints: ['src/awslambda-auto.ts'],
3132
packageSpecificConfig: {
3233
// Normally `makeNPMConfigVariants` sets both of these values for us, but we don't actually want the ESM variant,

0 commit comments

Comments
 (0)