diff --git a/.gitlab/ci/frontend.gitlab-ci.yml b/.gitlab/ci/frontend.gitlab-ci.yml index 1538352a88128a701aa71e42273751cfd4af75a0..860ca04813a55975e57de61034b741b3e4e163a8 100644 --- a/.gitlab/ci/frontend.gitlab-ci.yml +++ b/.gitlab/ci/frontend.gitlab-ci.yml @@ -335,3 +335,22 @@ webpack-dev-server: expire_in: 31d paths: - 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 diff --git a/.gitlab/ci/rules.gitlab-ci.yml b/.gitlab/ci/rules.gitlab-ci.yml index 383aca0043b7b958d907be08e8cfe36361427795..c0ea616c2d1e2092559788901ffb78ea5e458d22 100644 --- a/.gitlab/ci/rules.gitlab-ci.yml +++ b/.gitlab/ci/rules.gitlab-ci.yml @@ -335,6 +335,12 @@ changes: *frontend-dependency-patterns 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 # ################ diff --git a/danger/bundle_size/Dangerfile b/danger/bundle_size/Dangerfile new file mode 100644 index 0000000000000000000000000000000000000000..e2621360c7ff6ce383255a4761e41ed18403f616 --- /dev/null +++ b/danger/bundle_size/Dangerfile @@ -0,0 +1,38 @@ +# 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