summaryrefslogtreecommitdiff
path: root/danger/bundle_size/Dangerfile
blob: b824edb5dab42fa974b3f7daf650bc5fe2a342e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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",
  "--job #{ENV["CI_JOB_ID"]}",
  "--to-file #{analysis_result}",
  "--html ./bundle-size-review/comparison.html",
  "--markdown #{markdown_result}"
].join(" ")

# execute comparison
`#{comparison_cmd}`

comment = `cat #{markdown_result}`

unless comment.strip.empty?
  markdown(<<~MARKDOWN)
    #{comment}
  MARKDOWN
end