Commit adcea4dd authored by Lukas Eipert's avatar Lukas Eipert

Danger: Add bundle size analysis

Adding a new danger job which analyses and compares the current MRs
bundle size to the bundle size of the commit on master it is trying to
merge into.

The tool itself is managed in:
https://gitlab.com/gitlab-org/frontend/playground/webpack-memory-metrics
parent cc194a6d
...@@ -335,3 +335,22 @@ webpack-dev-server: ...@@ -335,3 +335,22 @@ webpack-dev-server:
expire_in: 31d expire_in: 31d
paths: paths:
- webpack-dev-server.json - webpack-dev-server.json
bundle-size-review:
extends:
- .default-retry
- .frontend:rules:bundle-size-review
image: registry.gitlab.com/gitlab-org/gitlab-build-images:danger
stage: test
needs: ["gitlab:assets:compile pull-cache"]
script:
- mkdir -p bundle-size-review
- cp webpack-report/index.html bundle-size-review/bundle-report.html
- yarn global add https://gitlab.com/gitlab-org/frontend/playground/webpack-memory-metrics.git
- danger --dangerfile=danger/bundle_size/Dangerfile --fail-on-errors=true --verbose --danger_id=bundle-size-review
artifacts:
when: always
name: bundle-size-review
expire_in: 31d
paths:
- bundle-size-review
...@@ -335,6 +335,12 @@ ...@@ -335,6 +335,12 @@
changes: *frontend-dependency-patterns changes: *frontend-dependency-patterns
allow_failure: true allow_failure: true
.frontend:rules:bundle-size-review:
rules:
- if: '$DANGER_GITLAB_API_TOKEN && $CI_MERGE_REQUEST_IID && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
changes: *frontend-patterns
allow_failure: true
################ ################
# Memory rules # # Memory rules #
################ ################
......
# frozen_string_literal: true
analysis_result = "./bundle-size-review/analysis.json"
markdown_result = "./bundle-size-review/comparison.md"
# Executing the webpack-entry-point-analyser
# We would like to do that in the CI file directly,
# but unfortunately the head_commit SHA is not available
# as a CI variable due to our merge into master simulation
analyze_cmd = [
"webpack-entry-point-analyser",
"--from-file ./webpack-report/stats.json",
"--json #{analysis_result}",
" --sha #{gitlab&.head_commit}"
].join(" ")
# execute analysis
`#{analyze_cmd}`
# We are executing the comparison by comparing the start_sha
# to the current pipeline result. The start_sha is the commit
# from master that was merged into for the merged pipeline.
comparison_cmd = [
"webpack-compare-reports",
"--from-sha #{gitlab.mr_json["diff_refs"]["start_sha"]}",
"--to-file #{analysis_result}",
"--html ./bundle-size-review/comparison.html",
"--markdown #{markdown_result}"
].join(" ")
# execute comparison
`#{comparison_cmd}`
comment = `cat #{markdown_result}`
markdown(<<~MARKDOWN)
#{comment}
MARKDOWN
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment