Skip to content
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

ci(docs-infra): store JS bundles as CI artifacts to debug size check flakes #37703

Closed
wants to merge 2 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions .circleci/config.yml
Expand Up @@ -377,6 +377,10 @@ jobs:

test_aio:
executor: default-executor
parameters:
debugArtifactsDir:
type: string
default: aio/dist/size-debug-artifacts
steps:
- custom_attach_workspace
- init_environment
Expand All @@ -395,6 +399,15 @@ jobs:
- run: yarn --cwd aio test-a11y-score-localhost
# Check the bundle sizes.
- run: yarn --cwd aio payload-size
# When `payload-size` check fails, copy the files that were checked into `debugArtifactsDir`.
- run:
when: on_fail
Copy link
Member Author

Choose a reason for hiding this comment

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

You can see how this step works here: https://circleci.com/workflow-run/5837947b-493e-4310-a0ab-efeea4b1643c.
(For that run, I set when: on_success to have this step run even if previous steps succeeded.)

name: Prepare JS bundles to be stored as artifacts
command: node aio/scripts/prepare-size-debug-artifacts aio << parameters.debugArtifactsDir >>
# Store files in `debugArtifactsDir` (if any) as artifacts for debugging purposes.
- store_artifacts:
path: << parameters.debugArtifactsDir >>
destination: aio
# Run unit tests for Firebase redirects
- run: yarn --cwd aio redirects-test

Expand All @@ -410,6 +423,9 @@ jobs:

test_aio_local:
parameters:
debugArtifactsDir:
type: string
default: aio/dist/size-debug-artifacts
viewengine:
type: boolean
default: false
Expand All @@ -428,6 +444,15 @@ jobs:
- run: yarn --cwd aio test-pwa-score-localhost $CI_AIO_MIN_PWA_SCORE
# Check the bundle sizes.
- run: yarn --cwd aio payload-size aio-local<<# parameters.viewengine >>-viewengine<</ parameters.viewengine >>
# When `payload-size` check fails, copy the files that were checked into `debugArtifactsDir`.
- run:
when: on_fail
name: Prepare JS bundles to be stored as artifacts
command: node aio/scripts/prepare-size-debug-artifacts aio-local<<# parameters.viewengine >>-viewengine<</ parameters.viewengine >> << parameters.debugArtifactsDir >>
# Store files in `debugArtifactsDir` (if any) as artifacts for debugging purposes.
- store_artifacts:
path: << parameters.debugArtifactsDir >>
destination: aio

test_aio_tools:
executor: default-executor
Expand Down
24 changes: 24 additions & 0 deletions aio/scripts/prepare-size-debug-artifacts.js
@@ -0,0 +1,24 @@
#!/usr/bin/env node
const {cp, ls, mkdir, set} = require('shelljs');
const {join, resolve} = require('path');
set('-e');

// Read input arguments.
const [sizesTarget, artifactsRelativeDir] = process.argv.slice(2);

// Compute paths.
const projectDir = resolve(__dirname, '../..');
const sizesFilePath = join(projectDir, 'goldens/size-tracking/aio-payloads.json');
const distDir = join(projectDir, 'aio/dist');
const artifactsDir = resolve(projectDir, artifactsRelativeDir);

// Determine which files need to be copied.
const fileNamePrefixes = Object.keys(require(sizesFilePath)[sizesTarget].master.uncompressed);
const filesToCopyRe = new RegExp(`^(?:${fileNamePrefixes.join('|')})\\..+\\.js$`);
const filesToCopy = ls(distDir)
.filter(file => filesToCopyRe.test(file))
.map(file => join(distDir, file));

// Copy files to the specified directory.
mkdir('-p', artifactsDir);
cp(filesToCopy, artifactsDir);