allure-report-publisher 0.0.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,104 @@
1
+ require "google/cloud/storage"
2
+
3
+ module Publisher
4
+ module Uploaders
5
+ # Google cloud storage uploader implementation
6
+ #
7
+ class GCS < Uploader
8
+ private
9
+
10
+ # GCS client
11
+ #
12
+ # @return [Google::Cloud::Storage::Project]
13
+ def client
14
+ @client ||= Google::Cloud::Storage.new
15
+ end
16
+
17
+ # GCS bucket
18
+ #
19
+ # @return [Google::Cloud::Storage::Bucket]
20
+ def bucket
21
+ @bucket ||= client.bucket(bucket_name, skip_lookup: true)
22
+ end
23
+
24
+ # Report url
25
+ #
26
+ # @return [String]
27
+ def report_url
28
+ @report_url ||= url(full_prefix)
29
+ end
30
+
31
+ # Latest report url
32
+ #
33
+ # @return [String]
34
+ def latest_report_url
35
+ @latest_report_url ||= url(prefix)
36
+ end
37
+
38
+ # Download allure history
39
+ #
40
+ # @return [void]
41
+ def download_history
42
+ HISTORY.each do |file_name|
43
+ file = bucket.file(key(prefix, "history", file_name))
44
+ raise(HistoryNotFoundError, "Allure history from previous runs not found!") unless file
45
+
46
+ file.download(path(results_path, "history", file_name))
47
+ end
48
+ end
49
+
50
+ # Upload allure history
51
+ #
52
+ # @return [void]
53
+ def upload_history
54
+ upload_to_gcs(report_files.select { |file| file.fnmatch?("*/history/*") }, prefix)
55
+ end
56
+
57
+ # Upload allure report
58
+ #
59
+ # @return [void]
60
+ def upload_report
61
+ upload_to_gcs(report_files, full_prefix)
62
+ end
63
+
64
+ # Upload copy of latest run
65
+ #
66
+ # @return [void]
67
+ def upload_latest_copy
68
+ upload_to_gcs(report_files, prefix)
69
+ end
70
+
71
+ # Upload files to s3
72
+ #
73
+ # @param [Array<Pathname>] files
74
+ # @param [String] key_prefix
75
+ # @return [Array<Hash>]
76
+ def upload_to_gcs(files, key_prefix)
77
+ args = files.map do |file|
78
+ {
79
+ file: file.to_s,
80
+ path: key(key_prefix, file.relative_path_from(report_path))
81
+ }
82
+ end
83
+
84
+ Parallel.each(args, in_threads: 8) { |obj| bucket.create_file(obj[:file], obj[:path]) }
85
+ end
86
+
87
+ # Fabricate key for s3 object
88
+ #
89
+ # @param [String] *args
90
+ # @return [String]
91
+ def key(*args)
92
+ args.compact.join("/")
93
+ end
94
+
95
+ # Report url
96
+ #
97
+ # @param [String] path_prefix
98
+ # @return [String]
99
+ def url(path_prefix)
100
+ ["https://storage.googleapis.com", bucket_name, path_prefix, "index.html"].compact.join("/")
101
+ end
102
+ end
103
+ end
104
+ end
@@ -10,8 +10,8 @@ module Publisher
10
10
  # S3 client
11
11
  #
12
12
  # @return [Aws::S3::Client]
13
- def s3
14
- @s3 ||= Aws::S3::Client.new(region: ENV["AWS_REGION"] || "us-east-1")
13
+ def client
14
+ @client ||= Aws::S3::Client.new(region: ENV["AWS_REGION"] || "us-east-1")
15
15
  rescue Aws::Sigv4::Errors::MissingCredentialsError
16
16
  raise(<<~MSG.strip)
17
17
  missing aws credentials, provide credentials with one of the following options:
@@ -20,14 +20,6 @@ module Publisher
20
20
  MSG
21
21
  end
22
22
 
23
- # Validate if client is properly configured
24
- # and raise error if it is not
25
- #
26
- # @return [void]
27
- def check_client_configured
28
- s3
29
- end
30
-
31
23
  # Report url
32
24
  #
33
25
  # @return [String]
@@ -45,18 +37,16 @@ module Publisher
45
37
  # Add allure history
46
38
  #
47
39
  # @return [void]
48
- def add_history
49
- super do
50
- HISTORY.each do |file|
51
- s3.get_object(
52
- response_target: path(results_dir, "history", file),
53
- key: key(prefix, "history", file),
54
- bucket: bucket
55
- )
56
- end
57
- rescue Aws::S3::Errors::NoSuchKey
58
- raise("Allure history from previous runs not found!")
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
+ )
59
47
  end
48
+ rescue Aws::S3::Errors::NoSuchKey
49
+ raise(HistoryNotFoundError, "Allure history from previous runs not found!")
60
50
  end
61
51
 
62
52
  # Upload allure history
@@ -89,12 +79,12 @@ module Publisher
89
79
  args = files.map do |file|
90
80
  {
91
81
  body: File.new(file),
92
- bucket: bucket,
93
- 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))
94
84
  }
95
85
  end
96
86
 
97
- Parallel.each(args, in_threads: 8) { |obj| s3.put_object(obj) }
87
+ Parallel.each(args, in_threads: 8) { |obj| client.put_object(obj) }
98
88
  end
99
89
 
100
90
  # Fabricate key for s3 object
@@ -110,7 +100,7 @@ module Publisher
110
100
  # @param [String] path_prefix
111
101
  # @return [String]
112
102
  def url(path_prefix)
113
- ["http://#{bucket}.s3.amazonaws.com", path_prefix, "index.html"].compact.join("/")
103
+ ["http://#{bucket_name}.s3.amazonaws.com", path_prefix, "index.html"].compact.join("/")
114
104
  end
115
105
  end
116
106
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Publisher
4
- VERSION = "0.0.4"
4
+ VERSION = "0.2.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.4
4
+ version: 0.2.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-05 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,18 @@ 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
169
+ - lib/allure_report_publisher/lib/providers/url_section_builder.rb
150
170
  - lib/allure_report_publisher/lib/report_generator.rb
151
171
  - lib/allure_report_publisher/lib/uploaders/_uploader.rb
152
- - lib/allure_report_publisher/lib/uploaders/s3_uploader.rb
172
+ - lib/allure_report_publisher/lib/uploaders/gcs.rb
173
+ - lib/allure_report_publisher/lib/uploaders/s3.rb
153
174
  - lib/allure_report_publisher/version.rb
154
175
  homepage: https://github.com/andrcuns/allure-report-uploader
155
176
  licenses:
@@ -1,21 +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, default: false"
9
- option :update_pr,
10
- type: :boolean,
11
- default: false,
12
- desc: "Update pull request description with url to allure report"
13
- option :copy_latest,
14
- type: :boolean,
15
- default: false,
16
- desc: "Keep copy of latest report at base prefix path"
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,41 +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 :results_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
- "--results-glob='path/to/allure-result/**/*' --bucket=my-bucket",
17
- "--results-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
25
- .new(**args.slice(:results_glob, :bucket, :prefix, :copy_latest, :update_pr))
26
- .execute
27
- end
28
-
29
- private
30
-
31
- # Validate required args
32
- #
33
- # @param [Hash] args
34
- # @return [void]
35
- def validate_args(args)
36
- error("Missing argument --results-glob!") unless args[:results_glob]
37
- error("Missing argument --bucket!") unless args[:bucket]
38
- end
39
- end
40
- end
41
- end