allure-report-publisher 0.0.3 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,60 +7,46 @@ module Publisher
7
7
  class S3 < Uploader
8
8
  private
9
9
 
10
- # Validate if client is properly configured
11
- # and raise error if it is not
10
+ # S3 client
12
11
  #
13
- # @return [void]
14
- def check_client_configured
15
- s3
12
+ # @return [Aws::S3::Client]
13
+ def client
14
+ @client ||= Aws::S3::Client.new(region: ENV["AWS_REGION"] || "us-east-1")
15
+ rescue Aws::Sigv4::Errors::MissingCredentialsError
16
+ raise(<<~MSG.strip)
17
+ missing aws credentials, provide credentials with one of the following options:
18
+ - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables
19
+ - ~/.aws/credentials file
20
+ MSG
16
21
  end
17
22
 
18
23
  # Report url
19
24
  #
20
25
  # @return [String]
21
26
  def report_url
22
- @report_url ||= ["http://#{bucket}.s3.amazonaws.com", full_prefix, "index.html"].compact.join("/")
27
+ @report_url ||= url(full_prefix)
23
28
  end
24
29
 
25
- # Add allure history
30
+ # Latest report url
26
31
  #
27
- # @return [void]
28
- def add_history
29
- super do
30
- HISTORY.each do |file|
31
- s3.get_object(
32
- response_target: path(results_dir, "history", file),
33
- key: key(prefix, "history", file),
34
- bucket: bucket
35
- )
36
- end
37
- rescue Aws::S3::Errors::NoSuchKey
38
- raise("Allure history from previous runs not found!")
39
- end
32
+ # @return [String]
33
+ def latest_report_url
34
+ @latest_report_url ||= url(prefix)
40
35
  end
41
36
 
42
- # Upload report to s3
37
+ # Add allure history
43
38
  #
44
39
  # @return [void]
45
- def upload_history_and_report
46
- log("Uploading report to s3")
47
- Helpers::Spinner.spin("uploading report", done_message: "done. #{report_url}") do
48
- upload_history
49
- upload_report
40
+ def download_history
41
+ HISTORY.each do |file|
42
+ client.get_object(
43
+ response_target: path(results_path, "history", file),
44
+ key: key(prefix, "history", file),
45
+ bucket: bucket_name
46
+ )
50
47
  end
51
- end
52
-
53
- # S3 client
54
- #
55
- # @return [Aws::S3::Client]
56
- def s3
57
- @s3 ||= Aws::S3::Client.new(region: ENV["AWS_REGION"] || "us-east-1")
58
- rescue Aws::Sigv4::Errors::MissingCredentialsError
59
- raise(<<~MSG.strip)
60
- missing aws credentials, provide credentials with one of the following options:
61
- - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables
62
- - ~/.aws/credentials file
63
- MSG
48
+ rescue Aws::S3::Errors::NoSuchKey
49
+ raise(HistoryNotFoundError, "Allure history from previous runs not found!")
64
50
  end
65
51
 
66
52
  # Upload allure history
@@ -74,7 +60,14 @@ module Publisher
74
60
  #
75
61
  # @return [void]
76
62
  def upload_report
77
- upload_to_s3(report_files)
63
+ upload_to_s3(report_files, full_prefix)
64
+ end
65
+
66
+ # Upload copy of latest run
67
+ #
68
+ # @return [void]
69
+ def upload_latest_copy
70
+ upload_to_s3(report_files, prefix)
78
71
  end
79
72
 
80
73
  # Upload files to s3
@@ -82,16 +75,16 @@ module Publisher
82
75
  # @param [Array<Pathname>] files
83
76
  # @param [String] key_prefix
84
77
  # @return [Array<Hash>]
85
- def upload_to_s3(files, key_prefix = full_prefix)
78
+ def upload_to_s3(files, key_prefix)
86
79
  args = files.map do |file|
87
80
  {
88
81
  body: File.new(file),
89
- bucket: bucket,
90
- key: key(key_prefix, file.relative_path_from(report_dir))
82
+ bucket: bucket_name,
83
+ key: key(key_prefix, file.relative_path_from(report_path))
91
84
  }
92
85
  end
93
86
 
94
- Parallel.each(args, in_threads: 8) { |obj| s3.put_object(obj) }
87
+ Parallel.each(args, in_threads: 8) { |obj| client.put_object(obj) }
95
88
  end
96
89
 
97
90
  # Fabricate key for s3 object
@@ -101,6 +94,14 @@ module Publisher
101
94
  def key(*args)
102
95
  args.compact.join("/")
103
96
  end
97
+
98
+ # Report url
99
+ #
100
+ # @param [String] path_prefix
101
+ # @return [String]
102
+ def url(path_prefix)
103
+ ["http://#{bucket_name}.s3.amazonaws.com", path_prefix, "index.html"].compact.join("/")
104
+ end
104
105
  end
105
106
  end
106
107
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Publisher
4
- VERSION = "0.0.3"
4
+ VERSION = "0.1.1"
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.3
4
+ version: 0.1.1
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-03 00:00:00.000000000 Z
11
+ date: 2021-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-s3
@@ -34,16 +34,22 @@ dependencies:
34
34
  name: dry-cli
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 0.6.0
39
+ version: '0.6'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
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
@@ -58,6 +64,20 @@ dependencies:
58
64
  - - "~>"
59
65
  - !ruby/object:Gem::Version
60
66
  version: '4.17'
67
+ - !ruby/object:Gem::Dependency
68
+ name: google-cloud-storage
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '1.31'
74
+ type: :runtime
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '1.31'
61
81
  - !ruby/object:Gem::Dependency
62
82
  name: octokit
63
83
  requirement: !ruby/object:Gem::Requirement
@@ -139,17 +159,17 @@ files:
139
159
  - README.md
140
160
  - bin/allure-report-publisher
141
161
  - lib/allure_report_publisher.rb
142
- - lib/allure_report_publisher/commands/base.rb
143
- - lib/allure_report_publisher/commands/upload_s3.rb
162
+ - lib/allure_report_publisher/commands/upload.rb
144
163
  - lib/allure_report_publisher/commands/version.rb
145
164
  - lib/allure_report_publisher/lib/helpers/helpers.rb
146
165
  - lib/allure_report_publisher/lib/helpers/spinner.rb
147
- - lib/allure_report_publisher/lib/providers/_base.rb
166
+ - lib/allure_report_publisher/lib/providers/_provider.rb
148
167
  - lib/allure_report_publisher/lib/providers/github.rb
149
168
  - lib/allure_report_publisher/lib/providers/gitlab.rb
150
169
  - lib/allure_report_publisher/lib/report_generator.rb
151
170
  - lib/allure_report_publisher/lib/uploaders/_uploader.rb
152
- - lib/allure_report_publisher/lib/uploaders/s3_uploader.rb
171
+ - lib/allure_report_publisher/lib/uploaders/gcs.rb
172
+ - lib/allure_report_publisher/lib/uploaders/s3.rb
153
173
  - lib/allure_report_publisher/version.rb
154
174
  homepage: https://github.com/andrcuns/allure-report-uploader
155
175
  licenses:
@@ -1,17 +0,0 @@
1
- module Publisher
2
- module Commands
3
- # Common arguments and options definition
4
- #
5
- module CommonOptions
6
- def self.included(mod)
7
- mod.instance_eval do
8
- option :color, type: :boolean, desc: "Toggle color output"
9
- option :update_pr,
10
- type: :boolean,
11
- default: false,
12
- desc: "Update pull request description with url to allure report"
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,43 +0,0 @@
1
- module Publisher
2
- module Commands
3
- # Upload allure report
4
- #
5
- class UploadS3 < Dry::CLI::Command
6
- include CommonOptions
7
- include Helpers
8
-
9
- desc "Generate and upload allure report"
10
-
11
- option :result_files_glob, desc: "Allure results files glob. Required: true"
12
- option :bucket, desc: "Bucket name. Required: true"
13
- option :prefix, desc: "Optional prefix for report path. Required: false"
14
-
15
- example [
16
- "--result-files-glob='path/to/allure-result/**/*' --bucket=my-bucket",
17
- "--result-files-glob='path/to/allure-result/**/*' --bucket=my-bucket --project=my-project/prs"
18
- ]
19
-
20
- def call(**args)
21
- validate_args(args)
22
- Helpers.pastel(force_color: args[:color])
23
-
24
- Uploaders::S3.new(
25
- args[:result_files_glob],
26
- args[:bucket],
27
- args[:prefix]
28
- ).execute(update_pr: args[:update_pr])
29
- end
30
-
31
- private
32
-
33
- # Validate required args
34
- #
35
- # @param [Hash] args
36
- # @return [void]
37
- def validate_args(args)
38
- error("Missing argument --result-files-glob!") unless args[:result_files_glob]
39
- error("Missing argument --bucket!") unless args[:bucket]
40
- end
41
- end
42
- end
43
- end
@@ -1,111 +0,0 @@
1
- module Publisher
2
- # Namespace for providers executing tests
3
- #
4
- module Providers
5
- # Detect CI provider
6
- #
7
- # @return [Publisher::Providers::Base]
8
- def self.provider
9
- return Github if ENV["GITHUB_WORKFLOW"]
10
- return Gitlab if ENV["GITLAB_CI"]
11
- end
12
-
13
- # Base class for CI executor info
14
- #
15
- class Base
16
- EXECUTOR_JSON = "executor.json".freeze
17
- DESCRIPTION_PATTERN = /<!-- allure -->[\s\S]+<!-- allurestop -->/.freeze
18
-
19
- def initialize(results_path, report_url)
20
- @results_path = results_path
21
- @report_url = report_url
22
- end
23
-
24
- # :nocov:
25
-
26
- # Get ci run ID without creating instance of ci provider
27
- #
28
- # @return [String]
29
- def self.run_id
30
- raise("Not implemented!")
31
- end
32
- # :nocov:
33
-
34
- # Write executor info file
35
- #
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
41
- end
42
-
43
- # Add report url to pull request description
44
- #
45
- # @return [void]
46
- def add_report_url
47
- raise("Not a pull request, skipped!") unless pr?
48
-
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)
53
- end
54
-
55
- private
56
-
57
- attr_reader :results_path, :report_url
58
-
59
- # :nocov:
60
-
61
- # Get executor info
62
- #
63
- # @return [Hash]
64
- def executor_info
65
- raise("Not implemented!")
66
- end
67
-
68
- # Pull request run
69
- #
70
- # @return [Boolean]
71
- def pr?
72
- raise("Not implemented!")
73
- end
74
-
75
- # Current pull request description
76
- #
77
- # @return [String]
78
- def pr_description
79
- raise("Not implemented!")
80
- end
81
-
82
- # Update pull request description
83
- #
84
- # @param [String] _desc
85
- # @return [void]
86
- def update_pr_description(_desc)
87
- raise("Not implemented!")
88
- end
89
- # :nocov:
90
-
91
- # CI run id
92
- #
93
- # @return [String]
94
- def run_id
95
- self.class.run_id
96
- end
97
-
98
- # Allure report url pr description
99
- #
100
- # @return [String]
101
- def description_template
102
- <<~DESC
103
- <!-- allure -->
104
- ---
105
- 📝 [Latest allure report](#{report_url})
106
- <!-- allurestop -->
107
- DESC
108
- end
109
- end
110
- end
111
- end