allure-report-publisher 0.0.6 → 0.3.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: be6f833714e1ff2ad413a9b5148cebd6454b23db763f567586b9e91222513524
4
- data.tar.gz: 6984e37c220f693288037522a86716079f3a235634c3ccbdd360056fd186f83c
3
+ metadata.gz: 0f5c4eb0b467125c36d80b35b99f7ec44ff1561a21bcc305d78a9afc4eaace1d
4
+ data.tar.gz: a525a10cae5378628ebf74d0a128ae9561db9f13b0ed023b992a404376b8ea1e
5
5
  SHA512:
6
- metadata.gz: d11ad18cdfb6c1955e521d8aae653b823f5defcfae4b095ae27f9bc9d1d0c89bca0336ab647c543b4c5d2cb92d2bffcd2c23343266b254aa1331984ac02abae9
7
- data.tar.gz: 023da790f7233de7da68520ea85e2e0388e6c840d3950ba004118a754f46d4c2c0c4570c76ca29add86cf97cc0dc40d859094df430627f4cf57316df89df6bf7
6
+ metadata.gz: c51b6b05861023942c761e80c0f777609dd0287f9f0724a4bc0246d7faa28a52ee05b394e85ddae66ea3441aa4a35372a88e2fe9b34c052776af3500570f19c1
7
+ data.tar.gz: bf3deb92f34c1899fc0c3bdce08cb6fa96652eac0493799b595894c3219baf200acf9a5f784a5ada92d24fe41ced54a9ac043678c82f850206a80d737e9a8909
data/README.md CHANGED
@@ -1,35 +1,33 @@
1
+ # allure-report-publisher
2
+
1
3
  [![Gem Version](https://img.shields.io/gem/v/allure-report-publisher?color=red)](https://rubygems.org/gems/allure-report-publisher)
4
+ [![Gem Pulls](https://img.shields.io/gem/dt/allure-report-publisher)](https://rubygems.org/gems/allure-report-publisher)
2
5
  [![Docker Image Version (latest semver)](https://img.shields.io/docker/v/andrcuns/allure-report-publisher?color=blue&label=docker&sort=semver)](https://hub.docker.com/r/andrcuns/allure-report-publisher)
6
+ [![Docker Pulls](https://img.shields.io/docker/pulls/andrcuns/allure-report-publisher)](https://hub.docker.com/r/andrcuns/allure-report-publisher)
3
7
  ![Workflow status](https://github.com/andrcuns/allure-report-publisher/workflows/Test/badge.svg)
4
- [![Test Report](https://img.shields.io/badge/report-allure-blue.svg)](http://allure-reports-andrcuns.s3.amazonaws.com/allure-report-publisher/refs/heads/main/index.html)
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)
5
9
  [![Maintainability](https://api.codeclimate.com/v1/badges/210eaa4f74588fb08313/maintainability)](https://codeclimate.com/github/andrcuns/allure-report-publisher/maintainability)
6
10
  [![Test Coverage](https://api.codeclimate.com/v1/badges/210eaa4f74588fb08313/test_coverage)](https://codeclimate.com/github/andrcuns/allure-report-publisher/test_coverage)
7
11
 
8
- # allure-report-publisher
9
-
10
12
  Upload your report to a file storage of your choice.
11
13
 
12
14
  ![Demo](demo.gif)
13
15
 
14
- ## Installation
16
+ # Installation
15
17
 
16
- ### Rubygems
18
+ ## Rubygems
17
19
 
18
20
  ```shell
19
21
  gem install allure-report-uploader
20
22
  ```
21
23
 
22
- ### Docker
24
+ ## Docker
23
25
 
24
26
  ```shell
25
27
  docker pull andrcuns/allure-report-publisher:latest
26
28
  ```
27
29
 
28
- ## Usage
29
-
30
- allure-report-publisher will automatically detect if used in CI environment and add relevant executor info and history
31
-
32
- - `Allure report link`: requires `GITHUB_AUTH_TOKEN` or `GITLAB_AUTH_TOKEN` in order to update pull request description with link to latest report
30
+ # Usage
33
31
 
34
32
  ```shell
35
33
  $ (allure-report-publisher|docker run --rm andrcuns/allure-report-publisher:latest) upload --help
@@ -43,44 +41,122 @@ Description:
43
41
  Generate and upload allure report
44
42
 
45
43
  Arguments:
46
- TYPE # REQUIRED Cloud storage type: (s3/gcs)
44
+ TYPE # REQUIRED Cloud storage type: (s3/gcs)
47
45
 
48
46
  Options:
49
- --results-glob=VALUE # Allure results files glob. Required: true
50
- --bucket=VALUE # Bucket name. Required: true
51
- --prefix=VALUE # Optional prefix for report path. Required: false
52
- --[no-]update-pr # Update pull request description with url to allure report, default: false
53
- --[no-]copy-latest # Keep copy of latest report at base prefix path, default: false
54
- --[no-]color # Toggle color output, default: false
55
- --help, -h # Print this help
47
+ --results-glob=VALUE # Allure results files glob. Required: true
48
+ --bucket=VALUE # Bucket name. Required: true
49
+ --prefix=VALUE # Optional prefix for report path. Required: false
50
+ --update-pr=VALUE # Add report url to PR via comment or description update. Required: false: (comment/description)
51
+ --[no-]copy-latest # Keep copy of latest report at base prefix path, default: false
52
+ --[no-]color # Toggle color output, default: false
53
+ --help, -h # Print this help
56
54
 
57
55
  Examples:
58
56
  allure-report-publisher upload s3 --results-glob='path/to/allure-result/**/*' --bucket=my-bucket
59
57
  allure-report-publisher upload gcs --results-glob='path/to/allure-result/**/*' --bucket=my-bucket --prefix=my-project/prs
60
58
  ```
61
59
 
62
- ### AWS S3
60
+ # Storage providers
61
+
62
+ Multiple cloud storage providers are supported
63
+
64
+ ## AWS S3
65
+
66
+ Requires environment variables `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` or credentials file `~/.aws/credentials`
67
+
68
+ ## Google Cloud Storage
69
+
70
+ Requires on of the following environment variables.
71
+
72
+ credentials.json file location:
73
+
74
+ - `STORAGE_CREDENTIALS`
75
+ - `STORAGE_KEYFILE`
76
+ - `GOOGLE_CLOUD_CREDENTIALS`
77
+ - `GOOGLE_CLOUD_KEYFILE`
78
+ - `GCLOUD_KEYFILE`
79
+
80
+ credentials.json contents:
81
+
82
+ - `GOOGLE_CLOUD_CREDENTIALS_JSON`
83
+ - `STORAGE_CREDENTIALS_JSON`
84
+ - `STORAGE_KEYFILE_JSON`
85
+ - `GOOGLE_CLOUD_CREDENTIALS_JSON`
86
+ - `GOOGLE_CLOUD_KEYFILE_JSON`
87
+ - `GCLOUD_KEYFILE_JSON`
88
+
89
+ # CI
90
+
91
+ `allure-report-publisher` will automatically detect if used in CI environment and add relevant executor info and history.
92
+
93
+ Following CI providers are supported:
94
+
95
+ - Github Actions
96
+ - Gitlab CI
97
+
98
+ ## Pull requests
99
+
100
+ It is possible to update pull requests with urls to published reports.
101
+
102
+ - `--update-pr=(comment|description)`: post report urls in pr description or as a comment
103
+
104
+ Example:
105
+
106
+ ---
107
+
108
+ `# Allure report`
109
+
110
+ `allure-report-publisher` generated test report for [1b756f48](https://github.com/andrcuns/allure-report-publisher/commit/HEAD)!
111
+
112
+ **rspec**: 📝 [test report](https://storage.googleapis.com/allure-test-reports/allure-report-publisher/refs/heads/main/index.html)
113
+
114
+ ---
115
+
116
+ ## Github Actions
117
+
118
+ Additional configuration is done via environment variables
119
+
120
+ Authentication for PR updates:
121
+
122
+ - `GITHUB_AUTH_TOKEN`: github auth token with api access
123
+
124
+ Following environment variables can override default CI values:
125
+
126
+ - `ALLURE_JOB_NAME`: overrides default `GITHUB_JOB` value which is used as name for report url section
127
+
128
+ ## Gitlab CI
129
+
130
+ Additional configuration is done via environment variables
131
+
132
+ Authentication for MR updates:
133
+
134
+ - `GITLAB_AUTH_TOKEN`: gitlab access token with api access
135
+
136
+ Following environment variables can override default CI values:
63
137
 
64
- - `AWS authentication`: requires environment variables `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` or credentials file `~/.aws/credentials`
138
+ - `ALLURE_JOB_NAME`: overrides default `CI_JOB_NAME` value which is used as name for report url section
65
139
 
66
- ### Google Cloud Storage
140
+ In case merge request triggers a downstream pipeline yet you want to update original merge request, overriding following environment variables might be useful:
67
141
 
68
- - `GCS authentication`: requires environment variable `GOOGLE_CLOUD_CREDENTIALS_JSON` with contents of credentials.json
142
+ - `ALLURE_PROJECT_PATH`: overrides default `CI_PROJECT_PATH` value
143
+ - `ALLURE_MERGE_REQUEST_IID`: overrides default `CI_MERGE_REQUEST_IID` value
144
+ - `ALLURE_COMMIT_SHA`: overrides default `CI_MERGE_REQUEST_SOURCE_BRANCH_SHA` or `CI_COMMIT_SHA` values
69
145
 
70
- ## Development
146
+ # Development
71
147
 
72
148
  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.
73
149
 
74
150
  To install this gem onto your local machine, run `bundle exec rake install`.
75
151
 
76
- ## Contributing
152
+ # Contributing
77
153
 
78
154
  Bug reports and pull requests are welcome on GitHub at <https://github.com/andrcuns/allure-report-publisher>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/andrcuns/allure-report-publisher/blob/main/CODE_OF_CONDUCT.md).
79
155
 
80
- ## License
156
+ # License
81
157
 
82
158
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
83
159
 
84
- ## Code of Conduct
160
+ # Code of Conduct
85
161
 
86
162
  Everyone interacting in the allure-report-publisher project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/andrcuns/allure-report-publisher/blob/main/CODE_OF_CONDUCT.md).
@@ -20,9 +20,9 @@ module Publisher
20
20
  option :prefix,
21
21
  desc: "Optional prefix for report path. Required: false"
22
22
  option :update_pr,
23
- type: :boolean,
24
- default: false,
25
- desc: "Update pull request description with url to allure report"
23
+ type: :string,
24
+ values: %w[comment description],
25
+ desc: "Add report url to PR via comment or description update. Required: false"
26
26
  option :copy_latest,
27
27
  type: :boolean,
28
28
  default: false,
@@ -52,7 +52,7 @@ module Publisher
52
52
  uploader.report_urls.each { |k, v| log("#{k}: #{v}", :green) }
53
53
  return unless args[:update_pr] && uploader.pr?
54
54
 
55
- log("Updating pull request description")
55
+ log("Adding reports urls")
56
56
  Spinner.spin("updating", exit_on_error: false) { uploader.add_url_to_pr }
57
57
  end
58
58
 
@@ -10,7 +10,7 @@ module Publisher
10
10
  # @param [Boolean] force_color
11
11
  # @return [Pastel]
12
12
  def self.pastel(force_color: nil)
13
- @pastel ||= Pastel.new(enabled: force_color)
13
+ @pastel ||= Pastel.new(enabled: force_color, eachline: "\n")
14
14
  end
15
15
 
16
16
  # Check allure cli is installed and executable
@@ -99,7 +99,7 @@ module Publisher
99
99
  # @param [String] error_message
100
100
  # @return [void]
101
101
  def spinner_error(error_message)
102
- colored_message = colorize(error_message, error_color)
102
+ colored_message = colorize("failed\n#{error_message}", error_color)
103
103
  return spinner.error(colored_message) if tty?
104
104
 
105
105
  spinner.stop
@@ -13,12 +13,11 @@ module Publisher
13
13
  # Base class for CI executor info
14
14
  #
15
15
  class Provider
16
- EXECUTOR_JSON = "executor.json".freeze
17
- DESCRIPTION_PATTERN = /<!-- allure -->[\s\S]+<!-- allurestop -->/.freeze
16
+ ALLURE_JOB_NAME = "ALLURE_JOB_NAME".freeze
18
17
 
19
- def initialize(results_path, report_url)
20
- @results_path = results_path
18
+ def initialize(report_url:, update_pr:)
21
19
  @report_url = report_url
20
+ @update_pr = update_pr
22
21
  end
23
22
 
24
23
  # :nocov:
@@ -29,27 +28,23 @@ module Publisher
29
28
  def self.run_id
30
29
  raise("Not implemented!")
31
30
  end
32
- # :nocov:
33
31
 
34
- # Write executor info file
32
+ # Get executor info
35
33
  #
36
- # @return [void]
37
- def write_executor_info
38
- File.open("#{results_path}/#{EXECUTOR_JSON}", "w") do |file|
39
- file.write(executor_info.to_json)
40
- end
34
+ # @return [Hash]
35
+ def executor_info
36
+ raise("Not implemented!")
41
37
  end
38
+ # :nocov:
42
39
 
43
40
  # Add report url to pull request description
44
41
  #
45
42
  # @return [void]
46
43
  def add_report_url
47
44
  raise("Not a pull request, skipped!") unless pr?
45
+ return add_comment if comment?
48
46
 
49
- reported = pr_description.match?(DESCRIPTION_PATTERN)
50
- return update_pr_description(pr_description.gsub(DESCRIPTION_PATTERN, description_template).strip) if reported
51
-
52
- update_pr_description("#{pr_description}\n\n#{description_template}".strip)
47
+ update_pr_description
53
48
  end
54
49
 
55
50
  # :nocov:
@@ -63,14 +58,7 @@ module Publisher
63
58
 
64
59
  private
65
60
 
66
- attr_reader :results_path, :report_url
67
-
68
- # Get executor info
69
- #
70
- # @return [Hash]
71
- def executor_info
72
- raise("Not implemented!")
73
- end
61
+ attr_reader :report_url, :update_pr
74
62
 
75
63
  # Current pull request description
76
64
  #
@@ -81,9 +69,29 @@ module Publisher
81
69
 
82
70
  # Update pull request description
83
71
  #
84
- # @param [String] _desc
85
72
  # @return [void]
86
- def update_pr_description(_desc)
73
+ def update_pr_description
74
+ raise("Not implemented!")
75
+ end
76
+
77
+ # Add comment with report url
78
+ #
79
+ # @return [void]
80
+ def add_comment
81
+ raise("Not implemented!")
82
+ end
83
+
84
+ # Build name
85
+ #
86
+ # @return [String]
87
+ def build_name
88
+ raise("Not implemented!")
89
+ end
90
+
91
+ # Commit SHA url
92
+ #
93
+ # @return [String]
94
+ def sha_url
87
95
  raise("Not implemented!")
88
96
  end
89
97
  # :nocov:
@@ -95,16 +103,18 @@ module Publisher
95
103
  self.class.run_id
96
104
  end
97
105
 
98
- # Allure report url pr description
106
+ # Add report url as comment
99
107
  #
100
- # @return [String]
101
- def description_template
102
- <<~DESC
103
- <!-- allure -->
104
- ---
105
- 📝 [Latest allure report](#{report_url})
106
- <!-- allurestop -->
107
- DESC
108
+ # @return [Boolean]
109
+ def comment?
110
+ update_pr == "comment"
111
+ end
112
+
113
+ # Report urls section creator
114
+ #
115
+ # @return [ReportUrls]
116
+ def report_urls
117
+ @report_urls ||= UrlSectionBuilder.new(report_url: report_url, build_name: build_name, sha_url: sha_url)
108
118
  end
109
119
  end
110
120
  end
@@ -5,6 +5,12 @@ module Publisher
5
5
  # Github implementation
6
6
  #
7
7
  class Github < Provider
8
+ # Set octokit to autopaginate
9
+ #
10
+ Octokit.configure do |config|
11
+ config.auto_paginate = true
12
+ end
13
+
8
14
  # Run id
9
15
  #
10
16
  # @return [String]
@@ -19,8 +25,6 @@ module Publisher
19
25
  ENV["GITHUB_EVENT_NAME"] == "pull_request"
20
26
  end
21
27
 
22
- private
23
-
24
28
  # Executor info
25
29
  #
26
30
  # @return [Hash]
@@ -37,6 +41,8 @@ module Publisher
37
41
  }
38
42
  end
39
43
 
44
+ private
45
+
40
46
  # Github api client
41
47
  #
42
48
  # @return [Octokit::Client]
@@ -48,26 +54,50 @@ module Publisher
48
54
  end
49
55
  end
50
56
 
51
- # Pull request description
57
+ # Update pull request description
52
58
  #
53
- # @return [String]
54
- def pr_description
55
- @pr_description ||= client.pull_request(repository, pr_id)[:body]
59
+ # @return [void]
60
+ def update_pr_description
61
+ client.update_pull_request(repository, pr_id, body: report_urls.updated_pr_description(pr_description))
56
62
  end
57
63
 
58
- # Update pull request description
64
+ # Add comment with report url
59
65
  #
60
- # @param [String] _desc
61
66
  # @return [void]
62
- def update_pr_description(desc)
63
- client.update_pull_request(repository, pr_id, body: desc)
67
+ def add_comment
68
+ return client.add_comment(repository, pr_id, report_urls.comment_body) unless comment
69
+
70
+ client.update_comment(repository, comment[:id], report_urls.comment_body(comment[:body]))
71
+ end
72
+
73
+ # Existing comment with allure urls
74
+ #
75
+ # @return [Sawyer::Resource]
76
+ def comment
77
+ @comment ||= client.issue_comments(repository, pr_id).detect do |comment|
78
+ UrlSectionBuilder.match?(comment[:body])
79
+ end
80
+ end
81
+
82
+ # Github event
83
+ #
84
+ # @return [Hash]
85
+ def github_event
86
+ @github_event ||= JSON.parse(File.read(ENV["GITHUB_EVENT_PATH"]), symbolize_names: true)
87
+ end
88
+
89
+ # Pull request description
90
+ #
91
+ # @return [String]
92
+ def pr_description
93
+ @pr_description ||= client.pull_request(repository, pr_id)[:body]
64
94
  end
65
95
 
66
96
  # Pull request id
67
97
  #
68
98
  # @return [Integer]
69
99
  def pr_id
70
- @pr_id ||= JSON.parse(File.read(ENV["GITHUB_EVENT_PATH"]))["number"]
100
+ @pr_id ||= github_event[:number]
71
101
  end
72
102
 
73
103
  # Server url
@@ -88,7 +118,7 @@ module Publisher
88
118
  #
89
119
  # @return [String]
90
120
  def build_name
91
- @build_name ||= ENV["GITHUB_JOB"]
121
+ @build_name ||= ENV[ALLURE_JOB_NAME] || ENV["GITHUB_JOB"]
92
122
  end
93
123
 
94
124
  # Github repository
@@ -97,6 +127,16 @@ module Publisher
97
127
  def repository
98
128
  @repository ||= ENV["GITHUB_REPOSITORY"]
99
129
  end
130
+
131
+ # Commit sha url
132
+ #
133
+ # @return [String]
134
+ def sha_url
135
+ sha = github_event.dig(:pull_request, :head, :sha)
136
+ short_sha = sha[0..7]
137
+
138
+ "[#{short_sha}](#{server_url}/#{repository}/pull/#{pr_id}/commits/#{sha})"
139
+ end
100
140
  end
101
141
  end
102
142
  end
@@ -16,7 +16,7 @@ module Publisher
16
16
  #
17
17
  # @return [Boolean]
18
18
  def pr?
19
- ENV["CI_PIPELINE_SOURCE"] == "merge_request_event"
19
+ (allure_project && allure_mr_iid) || ENV["CI_PIPELINE_SOURCE"] == "merge_request_event"
20
20
  end
21
21
 
22
22
  # Get executor info
@@ -35,6 +35,8 @@ module Publisher
35
35
  }
36
36
  end
37
37
 
38
+ private
39
+
38
40
  # Current pull request description
39
41
  #
40
42
  # @return [String]
@@ -44,10 +46,27 @@ module Publisher
44
46
 
45
47
  # Update pull request description
46
48
  #
47
- # @param [String] desc
48
49
  # @return [void]
49
- def update_pr_description(desc)
50
- client.update_merge_request(project, mr_iid, description: desc)
50
+ def update_pr_description
51
+ client.update_merge_request(project, mr_iid, description: report_urls.updated_pr_description(pr_description))
52
+ end
53
+
54
+ # Add comment with report url
55
+ #
56
+ # @return [void]
57
+ def add_comment
58
+ return client.create_merge_request_comment(project, mr_iid, report_urls.comment_body) unless comment
59
+
60
+ client.edit_merge_request_note(project, mr_iid, comment.id, report_urls.comment_body(comment.body))
61
+ end
62
+
63
+ # Existing comment with allure urls
64
+ #
65
+ # @return [Gitlab::ObjectifiedHash]
66
+ def comment
67
+ client.merge_request_comments(project, mr_iid).auto_paginate.detect do |comment|
68
+ UrlSectionBuilder.match?(comment.body)
69
+ end
51
70
  end
52
71
 
53
72
  # Get gitlab client
@@ -64,11 +83,39 @@ module Publisher
64
83
  end
65
84
  end
66
85
 
86
+ # Custom repository name
87
+ #
88
+ # @return [String]
89
+ def allure_project
90
+ @allure_project ||= ENV["ALLURE_PROJECT_PATH"]
91
+ end
92
+
93
+ # Custom mr iid name
94
+ #
95
+ # @return [String]
96
+ def allure_mr_iid
97
+ @allure_mr_iid ||= ENV["ALLURE_MERGE_REQUEST_IID"]
98
+ end
99
+
100
+ # Custom sha
101
+ #
102
+ # @return [String]
103
+ def allure_sha
104
+ @allure_sha ||= ENV["ALLURE_COMMIT_SHA"]
105
+ end
106
+
107
+ # Gitlab project path
108
+ #
109
+ # @return [String]
110
+ def project
111
+ @project ||= allure_project || ENV["CI_PROJECT_PATH"]
112
+ end
113
+
67
114
  # Merge request iid
68
115
  #
69
116
  # @return [Integer]
70
117
  def mr_iid
71
- @mr_iid ||= ENV["CI_MERGE_REQUEST_IID"]
118
+ @mr_iid ||= allure_mr_iid || ENV["CI_MERGE_REQUEST_IID"]
72
119
  end
73
120
 
74
121
  # Server url
@@ -89,14 +136,17 @@ module Publisher
89
136
  #
90
137
  # @return [String]
91
138
  def build_name
92
- @build_name ||= ENV["CI_JOB_NAME"]
139
+ @build_name ||= ENV[ALLURE_JOB_NAME] || ENV["CI_JOB_NAME"]
93
140
  end
94
141
 
95
- # Github repository
142
+ # Commit sha url
96
143
  #
97
144
  # @return [String]
98
- def project
99
- @project ||= ENV["CI_PROJECT_PATH"]
145
+ def sha_url
146
+ sha = allure_sha || ENV["CI_MERGE_REQUEST_SOURCE_BRANCH_SHA"] || ENV["CI_COMMIT_SHA"]
147
+ short_sha = sha[0..7]
148
+
149
+ "[#{short_sha}](#{server_url}/#{project}/-/merge_requests/#{mr_iid}/diffs?commit_id=#{sha})"
100
150
  end
101
151
  end
102
152
  end
@@ -0,0 +1,97 @@
1
+ module Publisher
2
+ module Providers
3
+ # Urls section builder
4
+ #
5
+ class UrlSectionBuilder
6
+ DESCRIPTION_PATTERN = /<!-- allure -->[\s\S]+<!-- allurestop -->/.freeze
7
+ JOBS_PATTERN = /<!-- jobs -->\n([\s\S]+)\n<!-- jobs -->/.freeze
8
+
9
+ def initialize(report_url:, build_name:, sha_url:)
10
+ @report_url = report_url
11
+ @build_name = build_name
12
+ @sha_url = sha_url
13
+ end
14
+
15
+ # Matches url section pattern
16
+ #
17
+ # @param [String] urls_block
18
+ # @return [Boolean]
19
+ def self.match?(urls_block)
20
+ urls_block.match?(DESCRIPTION_PATTERN)
21
+ end
22
+
23
+ # Get urls for PR update
24
+ #
25
+ # @param [String] pr
26
+ # @return [String]
27
+ def updated_pr_description(pr_description)
28
+ return "#{pr_description}\n\n#{body}" unless pr_description.match?(DESCRIPTION_PATTERN)
29
+
30
+ job_entries = jobs_section(pr_description)
31
+ pr_description.gsub(DESCRIPTION_PATTERN, body(job_entries))
32
+ end
33
+
34
+ # Allure report url comment
35
+ #
36
+ # @return [String]
37
+ def comment_body(pr_comment = nil)
38
+ return body.gsub("---\n", "") unless pr_comment
39
+
40
+ job_entries = jobs_section(pr_comment)
41
+ body(job_entries).gsub("---\n", "")
42
+ end
43
+
44
+ attr_reader :report_url, :build_name, :sha_url
45
+
46
+ private
47
+
48
+ # Allure report url pr description
49
+ #
50
+ # @return [String]
51
+ def body(job_entries = job_entry)
52
+ @body ||= <<~BODY.strip
53
+ <!-- allure -->
54
+ ---
55
+ #{heading}
56
+
57
+ <!-- jobs -->
58
+ #{job_entries}
59
+ <!-- jobs -->
60
+ <!-- allurestop -->
61
+ BODY
62
+ end
63
+
64
+ # Url section heading
65
+ #
66
+ # @return [String]
67
+ def heading
68
+ @heading ||= "# Allure report\n`allure-report-publisher` generated test report for #{sha_url}!"
69
+ end
70
+
71
+ # Return updated jobs section
72
+ #
73
+ # @param [String] urls
74
+ # @return [String]
75
+ def jobs_section(urls_block)
76
+ jobs = urls_block.match(JOBS_PATTERN)[1]
77
+ return jobs.gsub(job_entry_pattern, job_entry) if jobs.match?(job_entry_pattern)
78
+
79
+ "#{jobs}\n#{job_entry}"
80
+ end
81
+
82
+ # Single job report URL entry
83
+ #
84
+ # @return [String]
85
+ def job_entry
86
+ @job_entry ||= "**#{build_name}**: 📝 [test report](#{report_url})<br />"
87
+ end
88
+
89
+ # Job entry pattern
90
+ #
91
+ # @return [RegExp]
92
+ def job_entry_pattern
93
+ @job_entry_pattern ||= %r{^\*\*#{build_name}\*\*:.*\[test report\]\(.*\)<br />$}
94
+ end
95
+ end
96
+ end
97
+ end
@@ -10,10 +10,10 @@ module Publisher
10
10
  class ReportGenerator
11
11
  include Helpers
12
12
 
13
- def initialize(results_glob, results_dir, report_dir)
13
+ def initialize(results_glob, results_path, report_path)
14
14
  @results_glob = results_glob
15
- @results_dir = results_dir
16
- @report_dir = report_dir
15
+ @results_path = results_path
16
+ @report_path = report_path
17
17
  end
18
18
 
19
19
  # Generate allure report
@@ -26,7 +26,7 @@ module Publisher
26
26
 
27
27
  private
28
28
 
29
- attr_reader :results_glob, :results_dir, :report_dir
29
+ attr_reader :results_glob, :results_path, :report_path
30
30
 
31
31
  # Copy all results files to results directory
32
32
  #
@@ -35,7 +35,7 @@ module Publisher
35
35
  results = Dir.glob(results_glob)
36
36
  raise(NoAllureResultsError, "Missing allure results") if results.empty?
37
37
 
38
- FileUtils.cp(results, results_dir)
38
+ FileUtils.cp(results, results_path)
39
39
  end
40
40
 
41
41
  # Generate allure report
@@ -43,7 +43,7 @@ module Publisher
43
43
  # @return [void]
44
44
  def generate_report
45
45
  out, _err, status = Open3.capture3(
46
- "allure generate --clean --output #{report_dir} #{results_dir}"
46
+ "allure generate --clean --output #{report_path} #{results_path}"
47
47
  )
48
48
  raise(AllureError, out) unless status.success?
49
49
  end
@@ -7,6 +7,7 @@ module Publisher
7
7
  class Uploader
8
8
  include Helpers
9
9
 
10
+ EXECUTOR_JSON = "executor.json".freeze
10
11
  HISTORY = [
11
12
  "categories-trend.json",
12
13
  "duration-trend.json",
@@ -15,7 +16,7 @@ module Publisher
15
16
  "retry-trend.json"
16
17
  ].freeze
17
18
 
18
- def initialize(results_glob:, bucket:, update_pr: false, prefix: nil, copy_latest: false)
19
+ def initialize(results_glob:, bucket:, update_pr: nil, prefix: nil, copy_latest: false)
19
20
  @results_glob = results_glob
20
21
  @bucket_name = bucket
21
22
  @prefix = prefix
@@ -39,7 +40,7 @@ module Publisher
39
40
  add_history
40
41
  add_executor_info
41
42
 
42
- ReportGenerator.new(results_glob, results_dir, report_dir).generate
43
+ ReportGenerator.new(results_glob, results_path, report_path).generate
43
44
  end
44
45
 
45
46
  # Upload report to storage provider
@@ -147,7 +148,9 @@ module Publisher
147
148
  def add_executor_info
148
149
  return unless ci_provider
149
150
 
150
- ci_provider.write_executor_info
151
+ File.open("#{results_path}/#{EXECUTOR_JSON}", "w") do |file|
152
+ file.write(ci_provider.executor_info.to_json)
153
+ end
151
154
  end
152
155
 
153
156
  # Run upload commands
@@ -172,14 +175,14 @@ module Publisher
172
175
  def ci_provider
173
176
  return @ci_provider if defined?(@ci_provider)
174
177
 
175
- @ci_provider = Providers.provider&.new(results_dir, report_url)
178
+ @ci_provider = Providers.provider&.new(report_url: report_url, update_pr: update_pr)
176
179
  end
177
180
 
178
181
  # Fetch allure report history
179
182
  #
180
183
  # @return [void]
181
184
  def create_history_dir
182
- FileUtils.mkdir_p(path(results_dir, "history"))
185
+ FileUtils.mkdir_p(path(results_path, "history"))
183
186
  end
184
187
 
185
188
  # Report path prefix
@@ -196,15 +199,15 @@ module Publisher
196
199
  # Aggregated results directory
197
200
  #
198
201
  # @return [String]
199
- def results_dir
200
- @results_dir ||= Dir.mktmpdir("allure-results")
202
+ def results_path
203
+ @results_path ||= Dir.mktmpdir("allure-results")
201
204
  end
202
205
 
203
206
  # Allure report directory
204
207
  #
205
208
  # @return [String]
206
- def report_dir
207
- @report_dir ||= Dir.mktmpdir("allure-report")
209
+ def report_path
210
+ @report_path ||= Dir.mktmpdir("allure-report")
208
211
  end
209
212
 
210
213
  # Report files
@@ -212,7 +215,7 @@ module Publisher
212
215
  # @return [Array<Pathname>]
213
216
  def report_files
214
217
  @report_files ||= Pathname
215
- .glob("#{report_dir}/**/*")
218
+ .glob("#{report_path}/**/*")
216
219
  .reject(&:directory?)
217
220
  end
218
221
  end
@@ -43,7 +43,7 @@ module Publisher
43
43
  file = bucket.file(key(prefix, "history", file_name))
44
44
  raise(HistoryNotFoundError, "Allure history from previous runs not found!") unless file
45
45
 
46
- file.download(path(results_dir, "history", file_name))
46
+ file.download(path(results_path, "history", file_name))
47
47
  end
48
48
  end
49
49
 
@@ -77,7 +77,7 @@ module Publisher
77
77
  args = files.map do |file|
78
78
  {
79
79
  file: file.to_s,
80
- path: key(key_prefix, file.relative_path_from(report_dir))
80
+ path: key(key_prefix, file.relative_path_from(report_path))
81
81
  }
82
82
  end
83
83
 
@@ -40,7 +40,7 @@ module Publisher
40
40
  def download_history
41
41
  HISTORY.each do |file|
42
42
  client.get_object(
43
- response_target: path(results_dir, "history", file),
43
+ response_target: path(results_path, "history", file),
44
44
  key: key(prefix, "history", file),
45
45
  bucket: bucket_name
46
46
  )
@@ -80,7 +80,7 @@ module Publisher
80
80
  {
81
81
  body: File.new(file),
82
82
  bucket: bucket_name,
83
- key: key(key_prefix, file.relative_path_from(report_dir))
83
+ key: key(key_prefix, file.relative_path_from(report_path))
84
84
  }
85
85
  end
86
86
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Publisher
4
- VERSION = "0.0.6"
4
+ VERSION = "0.3.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: 0.0.6
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrejs Cunskis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-09 00:00:00.000000000 Z
11
+ date: 2021-05-24 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.95.0
22
+ version: 1.96.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,21 +29,27 @@ dependencies:
29
29
  version: 1.93.1
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 1.95.0
32
+ version: 1.96.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: dry-cli
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0.6'
40
+ - - "<"
38
41
  - !ruby/object:Gem::Version
39
- version: 0.6.0
42
+ version: '0.8'
40
43
  type: :runtime
41
44
  prerelease: false
42
45
  version_requirements: !ruby/object:Gem::Requirement
43
46
  requirements:
44
- - - "~>"
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0.6'
50
+ - - "<"
45
51
  - !ruby/object:Gem::Version
46
- version: 0.6.0
52
+ version: '0.8'
47
53
  - !ruby/object:Gem::Dependency
48
54
  name: gitlab
49
55
  requirement: !ruby/object:Gem::Requirement
@@ -160,6 +166,7 @@ files:
160
166
  - lib/allure_report_publisher/lib/providers/_provider.rb
161
167
  - lib/allure_report_publisher/lib/providers/github.rb
162
168
  - lib/allure_report_publisher/lib/providers/gitlab.rb
169
+ - lib/allure_report_publisher/lib/providers/url_section_builder.rb
163
170
  - lib/allure_report_publisher/lib/report_generator.rb
164
171
  - lib/allure_report_publisher/lib/uploaders/_uploader.rb
165
172
  - lib/allure_report_publisher/lib/uploaders/gcs.rb