allure-report-publisher 1.8.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28ab75e7680995e9117eb144cb3091561c5149f2fca4e93b89ed7dc06bbbf5fb
4
- data.tar.gz: ad1ef5249b916969807efb60619261ba3e24e2063d5914204fe17ded16abb928
3
+ metadata.gz: 1f7655105dbfd46700acb9b6045fdb563542697d88891f2ac1983d6d6d9a2cc3
4
+ data.tar.gz: d13ed56a3356b42060fa10ccc665765d2e3453cbd1090f483198b6c03a636555
5
5
  SHA512:
6
- metadata.gz: fada5ee179171b07a3387bd56abdff395413824d8819210c176e7b683fbd8caf3fab58d367c1ec33be89353324395ed6230ad3f763155f4d73a5b2ba95196f47
7
- data.tar.gz: bc06329051f0d2a8317202e9e91b8438225e905beab68ef3ea735547e1c4167b67fe05e3bcb19eca82d577b4ec2d67e54af2d403b09b5e8f43f560f5c1738698
6
+ metadata.gz: 7ff3f600d92b168111027c203e3b0d61b25aae3ba99cb01df372d0e0003ca6706fe3dfa5c07c2402f6d0e5f90eff19f95b790877a466d46e8627c90fc9177932
7
+ data.tar.gz: 7799a9144ceb663551f461a0e503ec9051f9be0588bbf60598d8cf7953b67fd3771ea5eec68ab0aff259d15c7a67422a65d5739278a8215af9a8992a939f70d6
data/README.md CHANGED
@@ -5,7 +5,6 @@
5
5
  ![Workflow status](https://github.com/andrcuns/allure-report-publisher/workflows/Test/badge.svg)
6
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/210eaa4f74588fb08313/maintainability)](https://codeclimate.com/github/andrcuns/allure-report-publisher/maintainability)
7
7
  [![Test Coverage](https://api.codeclimate.com/v1/badges/210eaa4f74588fb08313/test_coverage)](https://codeclimate.com/github/andrcuns/allure-report-publisher/test_coverage)
8
- [![Known Vulnerabilities](https://snyk.io/test/github/andrcuns/allure-report-publisher/badge.svg)](https://snyk.io/test/github/andrcuns/allure-report-publisher)
9
8
  [![Test Report](https://img.shields.io/badge/report-allure-blue.svg)](https://storage.googleapis.com/allure-test-reports/allure-report-publisher/refs/heads/main/index.html)
10
9
 
11
10
  Upload your report to a file storage of your choice.
@@ -47,9 +46,11 @@ Options:
47
46
  --bucket=VALUE # Bucket name. Required: true
48
47
  --prefix=VALUE # Optional prefix for report path. Required: false
49
48
  --update-pr=VALUE # Add report url to PR via comment or description update. Required: false: (comment/description/actions)
50
- --summary=VALUE # Additionally add summary table to PR comment or description. Required: false: (behaviors/suites/packages/total)
51
- --summary-table-type=VALUE # Summary table type. Required: false: (ascii/markdown), default: :ascii
49
+ --report-title=VALUE # Title for url section in PR comment/description. Required: false, default: "Allure Report"
50
+ --summary=VALUE # Additionally add summary table to PR comment or description. Required: false: (behaviors/suites/packages/total), default: "total"
51
+ --summary-table-type=VALUE # Summary table type. Required: false: (ascii/markdown), default: "ascii"
52
52
  --base-url=VALUE # Use custom base url instead of default cloud provider one. Required: false
53
+ --[no-]flaky-warning-status # Mark run with a '!' status in PR comment/description if report contains flaky tests, default: false
53
54
  --[no-]collapse-summary # Create summary as a collapsible section, default: false
54
55
  --[no-]copy-latest # Keep copy of latest report at base prefix path, default: false
55
56
  --[no-]color # Force color output
@@ -65,7 +66,7 @@ Examples:
65
66
 
66
67
  ## Environment variables
67
68
 
68
- All named options can be configured via environment variables. Environment variables are prefixed with `ALLURE_REPORT_` and uppercased.
69
+ All named options can be configured via environment variables. Environment variables are prefixed with `ALLURE_` and uppercased.
69
70
 
70
71
  Example: `--results-glob` can be configured via `ALLURE_REPORT_RESULTS_GLOB`
71
72
 
@@ -188,6 +189,10 @@ If reporter is executed with options `--update-pr=comment` and `--unresolved-dis
188
189
 
189
190
  - `ALLURE_FAILURE_ALERT_COMMENT`: comment added to create unresolved discussion note, default: `There are some test failures that need attention`
190
191
 
192
+ ### CI/CD catalog resource
193
+
194
+ [allure-report-publisher CI/CD catalog resource](https://gitlab.com/andrcuns/allure-report-publisher) can be used to easily integrate report publishing in to Gitlab CI pipelines.
195
+
191
196
  # Development
192
197
 
193
198
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -25,9 +25,14 @@ module Publisher
25
25
  type: :string,
26
26
  desc: "Add report url to PR via comment or description update. Required: false",
27
27
  values: %w[comment description actions]
28
+ option :report_title,
29
+ type: :string,
30
+ default: "Allure Report",
31
+ desc: "Title for url section in PR comment/description. Required: false"
28
32
  option :summary,
29
33
  type: :string,
30
34
  desc: "Additionally add summary table to PR comment or description. Required: false",
35
+ default: Publisher::Helpers::Summary::TOTAL,
31
36
  values: [
32
37
  Publisher::Helpers::Summary::BEHAVIORS,
33
38
  Publisher::Helpers::Summary::SUITES,
@@ -45,6 +50,10 @@ module Publisher
45
50
  option :base_url,
46
51
  type: :string,
47
52
  desc: "Use custom base url instead of default cloud provider one. Required: false"
53
+ option :flaky_warning_status,
54
+ type: :boolean,
55
+ default: false,
56
+ desc: "Mark run with a '!' status in PR comment/description if report contains flaky tests"
48
57
  option :collapse_summary,
49
58
  type: :boolean,
50
59
  default: false,
@@ -83,7 +92,7 @@ module Publisher
83
92
 
84
93
  generate_report
85
94
  upload_report
86
- return unless args[:update_pr] && uploader.pr?
95
+ return unless args[:update_pr] && Providers.info&.pr?
87
96
 
88
97
  add_report_urls
89
98
  rescue StandardError => e
@@ -99,17 +108,26 @@ module Publisher
99
108
  # @return [Publisher::Uploaders::Uploader]
100
109
  def uploader
101
110
  @uploader ||= uploaders(args[:type]).new(
102
- summary_type: args[:summary],
103
111
  result_paths: @result_paths,
112
+ **args.slice(:bucket, :prefix, :base_url, :copy_latest)
113
+ )
114
+ end
115
+
116
+ # CI provider instance
117
+ #
118
+ # @return [Publisher::Providers::Base]
119
+ def ci_provider
120
+ @ci_provider = Providers.provider&.new(
121
+ report_url: uploader.report_url,
122
+ report_path: uploader.report_path,
123
+ summary_type: args[:summary],
104
124
  **args.slice(
105
- :bucket,
106
- :prefix,
107
- :base_url,
108
- :copy_latest,
109
125
  :update_pr,
110
126
  :collapse_summary,
127
+ :flaky_warning_status,
111
128
  :summary_table_type,
112
- :unresolved_discussion_on_failure
129
+ :unresolved_discussion_on_failure,
130
+ :report_title
113
131
  )
114
132
  )
115
133
  end
@@ -173,7 +191,7 @@ module Publisher
173
191
  # @return [void]
174
192
  def add_report_urls
175
193
  log("Adding reports urls")
176
- Spinner.spin("updating", exit_on_error: false, debug: args[:debug]) { uploader.add_result_summary }
194
+ Spinner.spin("updating", exit_on_error: false, debug: args[:debug]) { ci_provider.add_result_summary }
177
195
  end
178
196
 
179
197
  # Handle error during upload command
@@ -121,7 +121,8 @@ module Publisher
121
121
  # @return [void]
122
122
  def spinner_error(error)
123
123
  message = ["failed", error.message]
124
- message << error.backtrace if debug
124
+ log_debug("Error: #{error.message}\n#{error.backtrace.join("\n")}")
125
+
125
126
  colored_message = colorize(message.compact.join("\n"), error_color)
126
127
  return spinner.error(colored_message) if tty?
127
128
 
@@ -9,18 +9,20 @@ module Publisher
9
9
  PACKAGES = "packages".freeze
10
10
  SUITES = "suites".freeze
11
11
  TOTAL = "total".freeze
12
- MARKDOWN = :markdown
13
- ASCII = :ascii
12
+ MARKDOWN = "markdown".freeze
13
+ ASCII = "ascii".freeze
14
14
 
15
15
  # Summary table generator
16
16
  #
17
17
  # @param [String] report_path
18
18
  # @param [String] summary_type
19
19
  # @param [String] markdown
20
- def initialize(report_path, summary_type, table_type = ASCII)
20
+ # @param [Boolean] flaky_warning_status
21
+ def initialize(report_path, summary_type, table_type = ASCII, flaky_warning_status: false)
21
22
  @report_path = report_path
22
23
  @summary_type = summary_type || TOTAL
23
24
  @table_type = table_type
25
+ @flaky_warning_status = flaky_warning_status
24
26
  end
25
27
 
26
28
  # Summary table
@@ -51,7 +53,7 @@ module Publisher
51
53
 
52
54
  private
53
55
 
54
- attr_reader :report_path, :summary_type, :table_type
56
+ attr_reader :report_path, :summary_type, :table_type, :flaky_warning_status
55
57
 
56
58
  # Expanded summary table
57
59
  #
@@ -102,7 +104,7 @@ module Publisher
102
104
  # @return [String]
103
105
  def status_icon(passed, failed, flaky)
104
106
  return "➖" if passed.zero? && failed.zero?
105
- return flaky.zero? ? "✅" : "❗" if failed.zero?
107
+ return !flaky_warning_status || flaky.zero? ? "✅" : "❗" if failed.zero?
106
108
 
107
109
  "❌"
108
110
  end
@@ -113,7 +115,7 @@ module Publisher
113
115
  def terminal_table
114
116
  Terminal::Table.new do |table|
115
117
  table.title = "#{summary_type} summary" unless markdown?
116
- table.style = { border: table_type }
118
+ table.style = { border: table_type.to_sym }
117
119
  table.headings = ["", "passed", "failed", "skipped", "flaky", "total", "result"]
118
120
  yield(table)
119
121
  end
@@ -14,6 +14,8 @@ module Publisher
14
14
  # @param [String] sha_url
15
15
  # @param [String] summary_type
16
16
  # @param [String] collapse_summary
17
+ # @param [Boolean] flaky_warning_status
18
+ # @param [String] report_title
17
19
  def initialize(**args)
18
20
  @report_url = args[:report_url]
19
21
  @report_path = args[:report_path]
@@ -22,6 +24,8 @@ module Publisher
22
24
  @summary_type = args[:summary_type]
23
25
  @summary_table_type = args[:summary_table_type]
24
26
  @collapse_summary = args[:collapse_summary]
27
+ @flaky_warning_status = args[:flaky_warning_status]
28
+ @report_title = args[:report_title]
25
29
  end
26
30
 
27
31
  # Matches url section pattern
@@ -64,7 +68,9 @@ module Publisher
64
68
  :sha_url,
65
69
  :summary_type,
66
70
  :summary_table_type,
67
- :collapse_summary
71
+ :collapse_summary,
72
+ :flaky_warning_status,
73
+ :report_title
68
74
 
69
75
  private
70
76
 
@@ -72,14 +78,21 @@ module Publisher
72
78
  #
73
79
  # @return [String]
74
80
  def heading
75
- @heading ||= "# Allure report\n`allure-report-publisher` generated test report!"
81
+ @heading ||= "# #{report_title}\n" \
82
+ "[`allure-report-publisher`](https://github.com/andrcuns/allure-report-publisher) " \
83
+ "generated test report!"
76
84
  end
77
85
 
78
86
  # Test run summary
79
87
  #
80
88
  # @return [Helpers::Summary]
81
89
  def summary
82
- @summary ||= Helpers::Summary.new(report_path, summary_type, summary_table_type)
90
+ @summary ||= Helpers::Summary.new(
91
+ report_path,
92
+ summary_type,
93
+ summary_table_type,
94
+ flaky_warning_status: flaky_warning_status
95
+ )
83
96
  end
84
97
 
85
98
  # Single job report URL entry
@@ -5,6 +5,8 @@ module Dry
5
5
  module Parser
6
6
  class InvalidEnvValue < StandardError; end
7
7
 
8
+ ENV_VAR_PREFIX = "ALLURE_".freeze
9
+
8
10
  class << self
9
11
  def call(command, arguments, prog_name)
10
12
  original_arguments = arguments.dup
@@ -45,7 +47,7 @@ module Dry
45
47
  end
46
48
 
47
49
  def option_from_env(option)
48
- name = "ALLURE_REPORT_#{option.name.to_s.upcase}"
50
+ name = "#{ENV_VAR_PREFIX}#{option.name.to_s.upcase}"
49
51
  value = ENV[name]
50
52
  return if value.nil? || value.empty?
51
53
  return if option.boolean? && !%w[true false].include?(value)
@@ -2,7 +2,7 @@ module Publisher
2
2
  # Namespace for providers executing tests
3
3
  #
4
4
  module Providers
5
- # Detect CI provider
5
+ # CI provider class
6
6
  #
7
7
  # @return [Publisher::Providers::Base]
8
8
  def self.provider
@@ -11,11 +11,18 @@ module Publisher
11
11
  Gitlab if ENV["GITLAB_CI"]
12
12
  end
13
13
 
14
+ # CI info class
15
+ #
16
+ # @return [Info::Base]
17
+ def self.info
18
+ return Info::Github.instance if ENV["GITHUB_WORKFLOW"]
19
+
20
+ Info::Gitlab.instance if ENV["GITLAB_CI"]
21
+ end
22
+
14
23
  # Base class for CI executor info
15
24
  #
16
25
  class Provider
17
- ALLURE_JOB_NAME = "ALLURE_JOB_NAME".freeze
18
-
19
26
  # CI provider base
20
27
  #
21
28
  # @param [Hash] args
@@ -23,9 +30,11 @@ module Publisher
23
30
  # @option args [String] :report_path
24
31
  # @option args [Boolean] :update_pr
25
32
  # @option args [String] :summary_type
33
+ # @option args [Symbol] :summary_table_type
26
34
  # @option args [Boolean] :collapse_summay
35
+ # @option args [Boolean] :flaky_warning_status
27
36
  # @option args [Boolean] :unresolved_discussion_on_failure
28
- # @option args [Symbol] :summary_table_type
37
+ # @option args [String] :report_title
29
38
  def initialize(**args)
30
39
  @report_url = args[:report_url]
31
40
  @report_path = args[:report_path]
@@ -33,45 +42,20 @@ module Publisher
33
42
  @summary_type = args[:summary_type]
34
43
  @summary_table_type = args[:summary_table_type]
35
44
  @collapse_summary = args[:collapse_summary]
45
+ @flaky_warning_status = args[:flaky_warning_status]
36
46
  @unresolved_discussion_on_failure = args[:unresolved_discussion_on_failure]
47
+ @report_title = args[:report_title]
37
48
  end
38
49
 
39
- # :nocov:
40
-
41
- # Get ci run ID without creating instance of ci provider
42
- #
43
- # @return [String]
44
- def self.run_id
45
- raise("Not implemented!")
46
- end
47
-
48
- # Get executor info
49
- #
50
- # @return [Hash]
51
- def executor_info
52
- raise("Not implemented!")
53
- end
54
- # :nocov:
55
-
56
50
  # Add report url to pull request description
57
51
  #
58
52
  # @return [void]
59
53
  def add_result_summary
60
- raise("Not a pull request, skipped!") unless pr?
61
54
  return add_comment if comment?
62
55
 
63
56
  update_pr_description
64
57
  end
65
58
 
66
- # :nocov:
67
-
68
- # Pull request run
69
- #
70
- # @return [Boolean]
71
- def pr?
72
- raise("Not implemented!")
73
- end
74
-
75
59
  private
76
60
 
77
61
  attr_reader :report_url,
@@ -80,7 +64,9 @@ module Publisher
80
64
  :summary_type,
81
65
  :collapse_summary,
82
66
  :summary_table_type,
83
- :unresolved_discussion_on_failure
67
+ :flaky_warning_status,
68
+ :unresolved_discussion_on_failure,
69
+ :report_title
84
70
 
85
71
  # Current pull request description
86
72
  #
@@ -102,29 +88,8 @@ module Publisher
102
88
  def add_comment
103
89
  raise("Not implemented!")
104
90
  end
105
-
106
- # Build name
107
- #
108
- # @return [String]
109
- def build_name
110
- raise("Not implemented!")
111
- end
112
-
113
- # Commit SHA url
114
- #
115
- # @return [String]
116
- def sha_url
117
- raise("Not implemented!")
118
- end
119
91
  # :nocov:
120
92
 
121
- # CI run id
122
- #
123
- # @return [String]
124
- def run_id
125
- self.class.run_id
126
- end
127
-
128
93
  # Add report url as comment
129
94
  #
130
95
  # @return [Boolean]
@@ -143,7 +108,9 @@ module Publisher
143
108
  sha_url: sha_url,
144
109
  summary_type: summary_type,
145
110
  summary_table_type: summary_table_type,
146
- collapse_summary: collapse_summary
111
+ collapse_summary: collapse_summary,
112
+ flaky_warning_status: flaky_warning_status,
113
+ report_title: report_title
147
114
  )
148
115
  end
149
116
  end
@@ -6,6 +6,7 @@ module Publisher
6
6
  #
7
7
  class Github < Provider
8
8
  include Helpers
9
+ extend Forwardable
9
10
 
10
11
  # Set octokit to autopaginate
11
12
  #
@@ -13,38 +14,13 @@ module Publisher
13
14
  config.auto_paginate = true
14
15
  end
15
16
 
16
- # Run id
17
- #
18
- # @return [String]
19
- def self.run_id
20
- @run_id ||= ENV["GITHUB_RUN_ID"]
21
- end
22
-
23
- # Pull request run
24
- #
25
- # @return [Boolean]
26
- def pr?
27
- ENV["GITHUB_EVENT_NAME"] == "pull_request"
28
- end
29
-
30
- # Executor info
31
- #
32
- # @return [Hash]
33
- def executor_info
34
- {
35
- name: "Github",
36
- type: "github",
37
- reportName: "AllureReport",
38
- url: server_url,
39
- reportUrl: report_url,
40
- buildUrl: build_url,
41
- buildOrder: run_id,
42
- buildName: build_name
43
- }
44
- end
45
-
46
17
  private
47
18
 
19
+ def_delegators :"Publisher::Providers::Info::Github.instance",
20
+ :repository,
21
+ :server_url,
22
+ :build_name
23
+
48
24
  # Github api client
49
25
  #
50
26
  # @return [Octokit::Client]
@@ -109,34 +85,6 @@ module Publisher
109
85
  @pr_id ||= github_event[:number]
110
86
  end
111
87
 
112
- # Server url
113
- #
114
- # @return [String]
115
- def server_url
116
- @server_url ||= ENV["GITHUB_SERVER_URL"]
117
- end
118
-
119
- # Build url
120
- #
121
- # @return [String]
122
- def build_url
123
- @build_url ||= "#{server_url}/#{repository}/actions/runs/#{run_id}"
124
- end
125
-
126
- # Job name
127
- #
128
- # @return [String]
129
- def build_name
130
- @build_name ||= ENV[ALLURE_JOB_NAME] || ENV["GITHUB_JOB"]
131
- end
132
-
133
- # Github repository
134
- #
135
- # @return [String]
136
- def repository
137
- @repository ||= ENV["GITHUB_REPOSITORY"]
138
- end
139
-
140
88
  # Commit sha url
141
89
  #
142
90
  # @return [String]
@@ -6,44 +6,83 @@ module Publisher
6
6
  #
7
7
  class Gitlab < Provider
8
8
  include Helpers
9
+ extend Forwardable
9
10
 
10
- # Get ci run ID without creating instance of ci provider
11
+ private
12
+
13
+ def_delegators :"Publisher::Providers::Info::Gitlab.instance",
14
+ :allure_project,
15
+ :allure_mr_iid,
16
+ :server_url,
17
+ :build_name
18
+
19
+ # Get gitlab client
20
+ #
21
+ # @return [Gitlab::Client]
22
+ def client
23
+ @client ||= begin
24
+ raise("Missing GITLAB_AUTH_TOKEN environment variable!") unless env("GITLAB_AUTH_TOKEN")
25
+
26
+ ::Gitlab::Client.new(
27
+ endpoint: "#{server_url}/api/v4",
28
+ private_token: env("GITLAB_AUTH_TOKEN")
29
+ )
30
+ end
31
+ end
32
+
33
+ # Current pull request description
11
34
  #
12
35
  # @return [String]
13
- def self.run_id
14
- @run_id ||= ENV["CI_PIPELINE_ID"]
36
+ def pr_description
37
+ @pr_description ||= client.merge_request(project, mr_iid).description
15
38
  end
16
39
 
17
- # Pull request run
40
+ # Comment with alert text
18
41
  #
19
- # @return [Boolean]
20
- def pr?
21
- (allure_project && allure_mr_iid) || ENV["CI_PIPELINE_SOURCE"] == "merge_request_event"
42
+ # @return [Gitlab::ObjectifiedHash]
43
+ def alert_comment
44
+ @alert_comment ||= discussion&.notes&.detect do |note|
45
+ note.body.include?(alert_comment_text)
46
+ end
22
47
  end
23
48
 
24
- # Get executor info
49
+ # Text for alert comment
25
50
  #
26
- # @return [Hash]
27
- def executor_info
28
- {
29
- name: "Gitlab",
30
- type: "gitlab",
31
- reportName: "AllureReport",
32
- url: server_url,
33
- reportUrl: report_url,
34
- buildUrl: build_url,
35
- buildOrder: run_id,
36
- buildName: build_name
37
- }
51
+ # @return [String]
52
+ def alert_comment_text
53
+ @alert_comment_text ||=
54
+ env("ALLURE_FAILURE_ALERT_COMMENT") || "There are some test failures that need attention"
38
55
  end
39
56
 
40
- private
57
+ # Custom sha
58
+ #
59
+ # @return [String]
60
+ def allure_sha
61
+ @allure_sha ||= env("ALLURE_COMMIT_SHA")
62
+ end
41
63
 
42
- # Current pull request description
64
+ # Gitlab project path
43
65
  #
44
66
  # @return [String]
45
- def pr_description
46
- @pr_description ||= client.merge_request(project, mr_iid).description
67
+ def project
68
+ @project ||= allure_project || env("CI_MERGE_REQUEST_PROJECT_PATH") || env("CI_PROJECT_PATH")
69
+ end
70
+
71
+ # Merge request iid
72
+ #
73
+ # @return [Integer]
74
+ def mr_iid
75
+ @mr_iid ||= allure_mr_iid || env("CI_MERGE_REQUEST_IID")
76
+ end
77
+
78
+ # Commit sha url
79
+ #
80
+ # @return [String]
81
+ def sha_url
82
+ sha = allure_sha || env("CI_MERGE_REQUEST_SOURCE_BRANCH_SHA") || env("CI_COMMIT_SHA")
83
+ short_sha = sha[0..7]
84
+
85
+ "[#{short_sha}](#{server_url}/#{project}/-/merge_requests/#{mr_iid}/diffs?commit_id=#{sha})"
47
86
  end
48
87
 
49
88
  # Update pull request description
@@ -58,25 +97,37 @@ module Publisher
58
97
  )
59
98
  end
60
99
 
61
- # rubocop:disable Metrics/PerceivedComplexity
62
100
  # Add comment with report url
63
101
  #
64
102
  # @return [void]
65
103
  def add_comment
104
+ create_or_update_comment
105
+ create_or_resolve_discussion
106
+ end
107
+
108
+ # Create or update comment with report url
109
+ #
110
+ # @return [void]
111
+ def create_or_update_comment
66
112
  if main_comment
67
113
  log_debug("Updating summary in comment with id #{discussion.id} in mr !#{mr_iid}")
68
114
 
69
- client.edit_merge_request_note(
115
+ return client.edit_merge_request_note(
70
116
  project,
71
117
  mr_iid,
72
118
  main_comment.id,
73
119
  url_section_builder.comment_body(main_comment.body)
74
120
  )
75
- else
76
- log_debug("Creating comment with summary for mr ! #{mr_iid}")
77
- client.create_merge_request_comment(project, mr_iid, url_section_builder.comment_body)
78
121
  end
79
122
 
123
+ log_debug("Creating comment with summary for mr ! #{mr_iid}")
124
+ client.create_merge_request_comment(project, mr_iid, url_section_builder.comment_body)
125
+ end
126
+
127
+ # Create or resolve comment discussion
128
+ #
129
+ # @return [void]
130
+ def create_or_resolve_discussion
80
131
  @discussion = nil
81
132
 
82
133
  if unresolved_discussion_on_failure && report_has_failures? && !alert_comment
@@ -93,8 +144,6 @@ module Publisher
93
144
  main_comment&.body&.include?("❌")
94
145
  end
95
146
 
96
- # rubocop:enable Metrics/PerceivedComplexity
97
-
98
147
  # Existing discussion that has comment with allure urls
99
148
  #
100
149
  # @return [Gitlab::ObjectifiedHash]
@@ -110,103 +159,6 @@ module Publisher
110
159
  def main_comment
111
160
  discussion&.notes&.detect { |note| Helpers::UrlSectionBuilder.match?(note.body) }
112
161
  end
113
-
114
- # Comment with alert text
115
- #
116
- # @return [Gitlab::ObjectifiedHash]
117
- def alert_comment
118
- @alert_comment ||= discussion&.notes&.detect do |note|
119
- note.body.include?(alert_comment_text)
120
- end
121
- end
122
-
123
- # Text for alert comment
124
- #
125
- # @return [String]
126
- def alert_comment_text
127
- @alert_comment_text ||=
128
- env("ALLURE_FAILURE_ALERT_COMMENT") || "There are some test failures that need attention"
129
- end
130
-
131
- # Get gitlab client
132
- #
133
- # @return [Gitlab::Client]
134
- def client
135
- @client ||= begin
136
- raise("Missing GITLAB_AUTH_TOKEN environment variable!") unless env("GITLAB_AUTH_TOKEN")
137
-
138
- ::Gitlab::Client.new(
139
- endpoint: "#{server_url}/api/v4",
140
- private_token: env("GITLAB_AUTH_TOKEN")
141
- )
142
- end
143
- end
144
-
145
- # Custom repository name
146
- #
147
- # @return [String]
148
- def allure_project
149
- @allure_project ||= env("ALLURE_PROJECT_PATH")
150
- end
151
-
152
- # Custom mr iid name
153
- #
154
- # @return [String]
155
- def allure_mr_iid
156
- @allure_mr_iid ||= env("ALLURE_MERGE_REQUEST_IID")
157
- end
158
-
159
- # Custom sha
160
- #
161
- # @return [String]
162
- def allure_sha
163
- @allure_sha ||= env("ALLURE_COMMIT_SHA")
164
- end
165
-
166
- # Gitlab project path
167
- #
168
- # @return [String]
169
- def project
170
- @project ||= allure_project || env("CI_MERGE_REQUEST_PROJECT_PATH") || env("CI_PROJECT_PATH")
171
- end
172
-
173
- # Merge request iid
174
- #
175
- # @return [Integer]
176
- def mr_iid
177
- @mr_iid ||= allure_mr_iid || env("CI_MERGE_REQUEST_IID")
178
- end
179
-
180
- # Server url
181
- #
182
- # @return [String]
183
- def server_url
184
- @server_url ||= env("CI_SERVER_URL")
185
- end
186
-
187
- # Build url
188
- #
189
- # @return [String]
190
- def build_url
191
- @build_url ||= env("CI_PIPELINE_URL")
192
- end
193
-
194
- # Job name
195
- #
196
- # @return [String]
197
- def build_name
198
- @build_name ||= env(ALLURE_JOB_NAME) || env("CI_JOB_NAME")
199
- end
200
-
201
- # Commit sha url
202
- #
203
- # @return [String]
204
- def sha_url
205
- sha = allure_sha || env("CI_MERGE_REQUEST_SOURCE_BRANCH_SHA") || env("CI_COMMIT_SHA")
206
- short_sha = sha[0..7]
207
-
208
- "[#{short_sha}](#{server_url}/#{project}/-/merge_requests/#{mr_iid}/diffs?commit_id=#{sha})"
209
- end
210
162
  end
211
163
  end
212
164
  end
@@ -0,0 +1,39 @@
1
+ require "singleton"
2
+
3
+ module Publisher
4
+ module Providers
5
+ module Info
6
+ # Base class for CI executor info
7
+ #
8
+ class Base
9
+ ALLURE_JOB_NAME = "ALLURE_JOB_NAME".freeze
10
+
11
+ # :nocov:
12
+
13
+ # CI Provider executor info
14
+ #
15
+ # @param [String] report_url
16
+ # @return [Hash]
17
+ def executor(_report_url)
18
+ raise("Not implemented!")
19
+ end
20
+
21
+ # Running on pull request/merge request
22
+ #
23
+ # @return [Boolean]
24
+ def pr?
25
+ raise("Not implemented!")
26
+ end
27
+
28
+ # Pipeline run id
29
+ #
30
+ # @return [Integer]
31
+ def run_id
32
+ raise("Not implemented!")
33
+ end
34
+
35
+ # :nocov:
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,70 @@
1
+ module Publisher
2
+ module Providers
3
+ module Info
4
+ # Github executor info
5
+ #
6
+ class Github < Base
7
+ include Singleton
8
+ include Helpers
9
+
10
+ # Executor info
11
+ #
12
+ # @return [Hash]
13
+ def executor(report_url)
14
+ {
15
+ name: "Github",
16
+ type: "github",
17
+ reportName: "AllureReport",
18
+ reportUrl: report_url,
19
+ url: server_url,
20
+ buildUrl: build_url,
21
+ buildOrder: run_id,
22
+ buildName: build_name
23
+ }
24
+ end
25
+
26
+ # Pull request run
27
+ #
28
+ # @return [Boolean]
29
+ def pr?
30
+ env("GITHUB_EVENT_NAME") == "pull_request"
31
+ end
32
+
33
+ # Run id
34
+ #
35
+ # @return [String]
36
+ def run_id
37
+ @run_id ||= env("GITHUB_RUN_ID")
38
+ end
39
+
40
+ # Server url
41
+ #
42
+ # @return [String]
43
+ def server_url
44
+ @server_url ||= env("GITHUB_SERVER_URL")
45
+ end
46
+
47
+ # Job name
48
+ #
49
+ # @return [String]
50
+ def build_name
51
+ @build_name ||= env(ALLURE_JOB_NAME) || env("GITHUB_JOB")
52
+ end
53
+
54
+ # Github repository
55
+ #
56
+ # @return [String]
57
+ def repository
58
+ @repository ||= env("GITHUB_REPOSITORY")
59
+ end
60
+
61
+ # Build url
62
+ #
63
+ # @return [String]
64
+ def build_url
65
+ @build_url ||= "#{server_url}/#{repository}/actions/runs/#{run_id}"
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,77 @@
1
+ module Publisher
2
+ module Providers
3
+ module Info
4
+ # Gitlab executor info
5
+ #
6
+ class Gitlab < Base
7
+ include Singleton
8
+ include Helpers
9
+
10
+ # Executor info
11
+ #
12
+ # @return [Hash]
13
+ def executor(report_url)
14
+ {
15
+ name: "Gitlab",
16
+ type: "gitlab",
17
+ reportName: "AllureReport",
18
+ reportUrl: report_url,
19
+ url: server_url,
20
+ buildUrl: build_url,
21
+ buildOrder: run_id,
22
+ buildName: build_name
23
+ }
24
+ end
25
+
26
+ # Pull request run
27
+ #
28
+ # @return [Boolean]
29
+ def pr?
30
+ !!(allure_project && allure_mr_iid) || ENV["CI_PIPELINE_SOURCE"] == "merge_request_event"
31
+ end
32
+
33
+ # Get ci run ID without creating instance of ci provider
34
+ #
35
+ # @return [String]
36
+ def run_id
37
+ @run_id ||= ENV["CI_PIPELINE_ID"]
38
+ end
39
+
40
+ # Server url
41
+ #
42
+ # @return [String]
43
+ def server_url
44
+ @server_url ||= env("CI_SERVER_URL")
45
+ end
46
+
47
+ # Build url
48
+ #
49
+ # @return [String]
50
+ def build_url
51
+ @build_url ||= env("CI_PIPELINE_URL")
52
+ end
53
+
54
+ # Custom repository name
55
+ #
56
+ # @return [String]
57
+ def allure_project
58
+ @allure_project ||= env("ALLURE_PROJECT_PATH")
59
+ end
60
+
61
+ # Custom mr iid name
62
+ #
63
+ # @return [String]
64
+ def allure_mr_iid
65
+ @allure_mr_iid ||= env("ALLURE_MERGE_REQUEST_IID")
66
+ end
67
+
68
+ # Job name
69
+ #
70
+ # @return [String]
71
+ def build_name
72
+ @build_name ||= env(ALLURE_JOB_NAME) || env("CI_JOB_NAME")
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -29,23 +29,13 @@ module Publisher
29
29
  # @option args [String] :bucket
30
30
  # @option args [String] :prefix
31
31
  # @option args [String] :base_url
32
- # @option args [Boolean] :update_pr
33
- # @option args [String] :summary_type
34
- # @option args [Symbol] :summary_table_type
35
- # @option args [Boolean] :collapse_summary
36
- # @option args [Boolean] :unresolved_discussion_on_failure
37
32
  # @option args [String] :copy_latest
38
33
  def initialize(**args)
39
34
  @result_paths = args[:result_paths]
40
35
  @bucket_name = args[:bucket]
41
36
  @prefix = args[:prefix]
42
37
  @base_url = args[:base_url]
43
- @update_pr = args[:update_pr]
44
- @summary_type = args[:summary_type]
45
- @summary_table_type = args[:summary_table_type]
46
- @copy_latest = (Providers.provider && args[:copy_latest]) # copy latest for ci only
47
- @collapse_summary = args[:collapse_summary]
48
- @unresolved_discussion_on_failure = args[:unresolved_discussion_on_failure]
38
+ @copy_latest = ci_info && args[:copy_latest] # copy latest for ci only
49
39
  end
50
40
 
51
41
  # Execute allure report generation and upload
@@ -54,7 +44,6 @@ module Publisher
54
44
  def execute
55
45
  generate_report
56
46
  upload
57
- add_result_summary
58
47
  end
59
48
 
60
49
  # Generate allure report
@@ -76,16 +65,6 @@ module Publisher
76
65
  upload_latest_copy if copy_latest
77
66
  end
78
67
 
79
- # Add allure report url to pull request description
80
- #
81
- # @return [void]
82
- def add_result_summary
83
- return unless update_pr && ci_provider
84
-
85
- log_debug("Adding test result summary")
86
- ci_provider.add_result_summary
87
- end
88
-
89
68
  # Uploaded report urls
90
69
  #
91
70
  # @return [Hash<String, String>] uploaded report urls
@@ -96,27 +75,35 @@ module Publisher
96
75
  urls
97
76
  end
98
77
 
99
- # Executed in PR pipeline
78
+ # :nocov:
79
+
80
+ # Report url
100
81
  #
101
- # @return [Boolean]
102
- def pr?
103
- ci_provider&.pr?
82
+ # @return [String]
83
+ def report_url
84
+ raise("Not Implemented!")
104
85
  end
105
86
 
87
+ # :nocov:
88
+
89
+ def_delegator :report_generator, :report_path
90
+
106
91
  private
107
92
 
108
93
  attr_reader :result_paths,
109
94
  :bucket_name,
110
95
  :prefix,
111
96
  :base_url,
112
- :update_pr,
113
- :copy_latest,
114
- :summary_type,
115
- :collapse_summary,
116
- :summary_table_type,
117
- :unresolved_discussion_on_failure
97
+ :copy_latest
118
98
 
119
- def_delegators :report_generator, :common_info_path, :report_path
99
+ def_delegator :report_generator, :common_info_path
100
+
101
+ # CI info
102
+ #
103
+ # @return [Providers::Info::Base]
104
+ def ci_info
105
+ Providers.info
106
+ end
120
107
 
121
108
  # :nocov:
122
109
 
@@ -127,13 +114,6 @@ module Publisher
127
114
  raise("Not Implemented!")
128
115
  end
129
116
 
130
- # Report url
131
- #
132
- # @return [String]
133
- def report_url
134
- raise("Not Implemented!")
135
- end
136
-
137
117
  # Latest report url
138
118
  #
139
119
  # @return [String]
@@ -168,6 +148,7 @@ module Publisher
168
148
  def upload_latest_copy
169
149
  raise("Not implemented!")
170
150
  end
151
+
171
152
  # :nocov:
172
153
 
173
154
  # Allure report generator
@@ -201,24 +182,7 @@ module Publisher
201
182
  #
202
183
  # @return [String]
203
184
  def run_id
204
- @run_id ||= Providers.provider&.run_id
205
- end
206
-
207
- # Get CI provider
208
- #
209
- # @return [Publisher::Providers::Base]
210
- def ci_provider
211
- return @ci_provider if defined?(@ci_provider)
212
-
213
- @ci_provider = Providers.provider&.new(
214
- report_url: report_url,
215
- report_path: report_path,
216
- update_pr: update_pr,
217
- summary_type: summary_type,
218
- summary_table_type: summary_table_type,
219
- collapse_summary: collapse_summary,
220
- unresolved_discussion_on_failure: unresolved_discussion_on_failure
221
- )
185
+ @run_id ||= ci_info&.run_id
222
186
  end
223
187
 
224
188
  # Add allure history
@@ -236,10 +200,10 @@ module Publisher
236
200
  #
237
201
  # @return [void]
238
202
  def add_executor_info
239
- return unless ci_provider
203
+ return unless ci_info
240
204
 
241
- json = ci_provider.executor_info.to_json
242
- log_debug("Saving ci executor info:\n#{JSON.pretty_generate(ci_provider.executor_info)}")
205
+ json = JSON.pretty_generate(ci_info.executor(report_url))
206
+ log_debug("Saving ci executor info:\n#{json}")
243
207
  # allure-report will fail to pick up reportUrl in history tab if executor.json is not present alongside results
244
208
  [common_info_path, *result_paths].each do |path|
245
209
  file = File.join(path, EXECUTOR_JSON)
@@ -5,6 +5,13 @@ module Publisher
5
5
  # Google cloud storage uploader implementation
6
6
  #
7
7
  class GCS < Uploader
8
+ # Report url
9
+ #
10
+ # @return [String]
11
+ def report_url
12
+ @report_url ||= url(full_prefix)
13
+ end
14
+
8
15
  private
9
16
 
10
17
  # GCS client
@@ -21,13 +28,6 @@ module Publisher
21
28
  @bucket ||= client.bucket(bucket_name, skip_lookup: true)
22
29
  end
23
30
 
24
- # Report url
25
- #
26
- # @return [String]
27
- def report_url
28
- @report_url ||= url(full_prefix)
29
- end
30
-
31
31
  # Latest report url
32
32
  #
33
33
  # @return [String]
@@ -6,6 +6,13 @@ module Publisher
6
6
  # Report upload to AWS S3 bucket
7
7
  #
8
8
  class S3 < Uploader
9
+ # Report url
10
+ #
11
+ # @return [String]
12
+ def report_url
13
+ @report_url ||= url(full_prefix)
14
+ end
15
+
9
16
  private
10
17
 
11
18
  # S3 client
@@ -29,13 +36,6 @@ module Publisher
29
36
  }.compact
30
37
  end
31
38
 
32
- # Report url
33
- #
34
- # @return [String]
35
- def report_url
36
- @report_url ||= url(full_prefix)
37
- end
38
-
39
39
  # Latest report url
40
40
  #
41
41
  # @return [String]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Publisher
4
- VERSION = "1.8.1"
4
+ VERSION = "3.0.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: allure-report-publisher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrejs Cunskis
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-02 00:00:00.000000000 Z
11
+ date: 2023-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-s3
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 1.93.1
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: 1.137.0
22
+ version: 1.142.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 1.93.1
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 1.137.0
32
+ version: 1.142.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: dry-cli
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -211,7 +211,7 @@ extensions: []
211
211
  extra_rdoc_files: []
212
212
  files:
213
213
  - README.md
214
- - bin/allure-report-publisher
214
+ - exe/allure-report-publisher
215
215
  - lib/allure_report_publisher.rb
216
216
  - lib/allure_report_publisher/commands/upload.rb
217
217
  - lib/allure_report_publisher/commands/version.rb
@@ -223,6 +223,9 @@ files:
223
223
  - lib/allure_report_publisher/lib/providers/_provider.rb
224
224
  - lib/allure_report_publisher/lib/providers/github.rb
225
225
  - lib/allure_report_publisher/lib/providers/gitlab.rb
226
+ - lib/allure_report_publisher/lib/providers/info/_base.rb
227
+ - lib/allure_report_publisher/lib/providers/info/github.rb
228
+ - lib/allure_report_publisher/lib/providers/info/gitlab.rb
226
229
  - lib/allure_report_publisher/lib/report_generator.rb
227
230
  - lib/allure_report_publisher/lib/uploaders/_uploader.rb
228
231
  - lib/allure_report_publisher/lib/uploaders/gcs.rb
File without changes