Commit 982d569b authored by Mike Greiling's avatar Mike Greiling

Merge branch 'leipert-danger-bundle-size' into 'master'

Danger: Add bundle size analysis

Closes #34098

See merge request gitlab-org/gitlab!30168
parents f6697c96 5132c997
...@@ -334,3 +334,22 @@ webpack-dev-server: ...@@ -334,3 +334,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
...@@ -78,9 +78,11 @@ ...@@ -78,9 +78,11 @@
.frontend-patterns: &frontend-patterns .frontend-patterns: &frontend-patterns
- "{package.json,yarn.lock}" - "{package.json,yarn.lock}"
- "{babel.config,jest.config}.js" - "babel.config.js"
- "jest.config.{base,integration,unit}.js"
- ".csscomb.json" - ".csscomb.json"
- "Dockerfile.assets" - "Dockerfile.assets"
- "config/**/*.js"
- "vendor/assets/**/*" - "vendor/assets/**/*"
- "{,ee/}{app/assets,app/helpers,app/presenters,app/views,locale,public,symbol}/**/*" - "{,ee/}{app/assets,app/helpers,app/presenters,app/views,locale,public,symbol}/**/*"
...@@ -93,7 +95,8 @@ ...@@ -93,7 +95,8 @@
.code-patterns: &code-patterns .code-patterns: &code-patterns
- "{package.json,yarn.lock}" - "{package.json,yarn.lock}"
- "{babel.config,jest.config}.js" - "babel.config.js"
- "jest.config.{base,integration,unit}.js"
- ".csscomb.json" - ".csscomb.json"
- "Dockerfile.assets" - "Dockerfile.assets"
- "vendor/assets/**/*" - "vendor/assets/**/*"
...@@ -113,7 +116,8 @@ ...@@ -113,7 +116,8 @@
.code-backstage-patterns: &code-backstage-patterns .code-backstage-patterns: &code-backstage-patterns
- "{package.json,yarn.lock}" - "{package.json,yarn.lock}"
- "{babel.config,jest.config}.js" - "babel.config.js"
- "jest.config.{base,integration,unit}.js"
- ".csscomb.json" - ".csscomb.json"
- "Dockerfile.assets" - "Dockerfile.assets"
- "vendor/assets/**/*" - "vendor/assets/**/*"
...@@ -135,7 +139,8 @@ ...@@ -135,7 +139,8 @@
.code-qa-patterns: &code-qa-patterns .code-qa-patterns: &code-qa-patterns
- "{package.json,yarn.lock}" - "{package.json,yarn.lock}"
- "{babel.config,jest.config}.js" - "babel.config.js"
- "jest.config.{base,integration,unit}.js"
- ".csscomb.json" - ".csscomb.json"
- "Dockerfile.assets" - "Dockerfile.assets"
- "vendor/assets/**/*" - "vendor/assets/**/*"
...@@ -154,7 +159,8 @@ ...@@ -154,7 +159,8 @@
.code-backstage-qa-patterns: &code-backstage-qa-patterns .code-backstage-qa-patterns: &code-backstage-qa-patterns
- "{package.json,yarn.lock}" - "{package.json,yarn.lock}"
- "{babel.config,jest.config}.js" - "babel.config.js"
- "jest.config.{base,integration,unit}.js"
- ".csscomb.json" - ".csscomb.json"
- "Dockerfile.assets" - "Dockerfile.assets"
- "vendor/assets/**/*" - "vendor/assets/**/*"
...@@ -335,6 +341,12 @@ ...@@ -335,6 +341,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
...@@ -63,9 +63,11 @@ export default { ...@@ -63,9 +63,11 @@ export default {
{ pipelineLink, projectLink }, { pipelineLink, projectLink },
false, false,
); );
} else if (pipelineLink && !projectLink) { }
if (pipelineLink && !projectLink) {
return sprintf(__('Dismissed on pipeline %{pipelineLink}'), { pipelineLink }, false); return sprintf(__('Dismissed on pipeline %{pipelineLink}'), { pipelineLink }, false);
} else if (!pipelineLink && projectLink) { }
if (!pipelineLink && projectLink) {
return sprintf(__('Dismissed at %{projectLink}'), { projectLink }, false); return sprintf(__('Dismissed at %{projectLink}'), { projectLink }, false);
} }
return __('Dismissed'); return __('Dismissed');
......
...@@ -5,7 +5,8 @@ export default { ...@@ -5,7 +5,8 @@ export default {
checkReportStatus(loading, error) { checkReportStatus(loading, error) {
if (loading) { if (loading) {
return LOADING; return LOADING;
} else if (error) { }
if (error) {
return ERROR; return ERROR;
} }
......
...@@ -24,13 +24,15 @@ export const enrichVulnerabilityWithFeedback = (vulnerability, feedback = []) => ...@@ -24,13 +24,15 @@ export const enrichVulnerabilityWithFeedback = (vulnerability, feedback = []) =>
isDismissed: true, isDismissed: true,
dismissalFeedback: fb, dismissalFeedback: fb,
}; };
} else if (fb.feedback_type === 'issue' && fb.issue_iid) { }
if (fb.feedback_type === 'issue' && fb.issue_iid) {
return { return {
...vuln, ...vuln,
hasIssue: true, hasIssue: true,
issue_feedback: fb, issue_feedback: fb,
}; };
} else if (fb.feedback_type === 'merge_request' && fb.merge_request_iid) { }
if (fb.feedback_type === 'merge_request' && fb.merge_request_iid) {
return { return {
...vuln, ...vuln,
hasMergeRequest: true, hasMergeRequest: true,
......
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