allure-report-publisher 0.0.2 → 0.1.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.
- checksums.yaml +4 -4
- data/README.md +22 -8
- data/lib/allure_report_publisher.rb +2 -5
- data/lib/allure_report_publisher/commands/upload.rb +90 -0
- data/lib/allure_report_publisher/lib/helpers/helpers.rb +2 -2
- data/lib/allure_report_publisher/lib/providers/_provider.rb +174 -0
- data/lib/allure_report_publisher/lib/providers/github.rb +142 -0
- data/lib/allure_report_publisher/lib/providers/gitlab.rb +132 -0
- data/lib/allure_report_publisher/lib/report_generator.rb +10 -13
- data/lib/allure_report_publisher/lib/uploaders/_uploader.rb +127 -41
- data/lib/allure_report_publisher/lib/uploaders/gcs.rb +104 -0
- data/lib/allure_report_publisher/lib/uploaders/s3.rb +107 -0
- data/lib/allure_report_publisher/version.rb +1 -1
- metadata +58 -9
- data/lib/allure_report_publisher/commands/base.rb +0 -13
- data/lib/allure_report_publisher/commands/upload_s3.rb +0 -43
- data/lib/allure_report_publisher/lib/ci/_base.rb +0 -63
- data/lib/allure_report_publisher/lib/ci/github_actions.rb +0 -50
- data/lib/allure_report_publisher/lib/uploaders/s3_uploader.rb +0 -94
@@ -0,0 +1,107 @@
|
|
1
|
+
require "aws-sdk-s3"
|
2
|
+
|
3
|
+
module Publisher
|
4
|
+
module Uploaders
|
5
|
+
# Report upload to AWS S3 bucket
|
6
|
+
#
|
7
|
+
class S3 < Uploader
|
8
|
+
private
|
9
|
+
|
10
|
+
# S3 client
|
11
|
+
#
|
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
|
21
|
+
end
|
22
|
+
|
23
|
+
# Report url
|
24
|
+
#
|
25
|
+
# @return [String]
|
26
|
+
def report_url
|
27
|
+
@report_url ||= url(full_prefix)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Latest report url
|
31
|
+
#
|
32
|
+
# @return [String]
|
33
|
+
def latest_report_url
|
34
|
+
@latest_report_url ||= url(prefix)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Add allure history
|
38
|
+
#
|
39
|
+
# @return [void]
|
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
|
+
)
|
47
|
+
end
|
48
|
+
rescue Aws::S3::Errors::NoSuchKey
|
49
|
+
raise(HistoryNotFoundError, "Allure history from previous runs not found!")
|
50
|
+
end
|
51
|
+
|
52
|
+
# Upload allure history
|
53
|
+
#
|
54
|
+
# @return [void]
|
55
|
+
def upload_history
|
56
|
+
upload_to_s3(report_files.select { |file| file.fnmatch?("*/history/*") }, prefix)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Upload allure report
|
60
|
+
#
|
61
|
+
# @return [void]
|
62
|
+
def upload_report
|
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)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Upload files to s3
|
74
|
+
#
|
75
|
+
# @param [Array<Pathname>] files
|
76
|
+
# @param [String] key_prefix
|
77
|
+
# @return [Array<Hash>]
|
78
|
+
def upload_to_s3(files, key_prefix)
|
79
|
+
args = files.map do |file|
|
80
|
+
{
|
81
|
+
body: File.new(file),
|
82
|
+
bucket: bucket_name,
|
83
|
+
key: key(key_prefix, file.relative_path_from(report_path))
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
Parallel.each(args, in_threads: 8) { |obj| client.put_object(obj) }
|
88
|
+
end
|
89
|
+
|
90
|
+
# Fabricate key for s3 object
|
91
|
+
#
|
92
|
+
# @param [String] *args
|
93
|
+
# @return [String]
|
94
|
+
def key(*args)
|
95
|
+
args.compact.join("/")
|
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
|
105
|
+
end
|
106
|
+
end
|
107
|
+
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
|
+
version: 0.1.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-
|
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
|
@@ -32,18 +32,66 @@ dependencies:
|
|
32
32
|
version: 1.95.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: dry-cli
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.6'
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0.8'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0.6'
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0.8'
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: gitlab
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '4.17'
|
60
|
+
type: :runtime
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
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'
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: octokit
|
35
83
|
requirement: !ruby/object:Gem::Requirement
|
36
84
|
requirements:
|
37
85
|
- - "~>"
|
38
86
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
87
|
+
version: '4.21'
|
40
88
|
type: :runtime
|
41
89
|
prerelease: false
|
42
90
|
version_requirements: !ruby/object:Gem::Requirement
|
43
91
|
requirements:
|
44
92
|
- - "~>"
|
45
93
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
94
|
+
version: '4.21'
|
47
95
|
- !ruby/object:Gem::Dependency
|
48
96
|
name: parallel
|
49
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,16 +159,17 @@ files:
|
|
111
159
|
- README.md
|
112
160
|
- bin/allure-report-publisher
|
113
161
|
- lib/allure_report_publisher.rb
|
114
|
-
- lib/allure_report_publisher/commands/
|
115
|
-
- lib/allure_report_publisher/commands/upload_s3.rb
|
162
|
+
- lib/allure_report_publisher/commands/upload.rb
|
116
163
|
- lib/allure_report_publisher/commands/version.rb
|
117
|
-
- lib/allure_report_publisher/lib/ci/_base.rb
|
118
|
-
- lib/allure_report_publisher/lib/ci/github_actions.rb
|
119
164
|
- lib/allure_report_publisher/lib/helpers/helpers.rb
|
120
165
|
- lib/allure_report_publisher/lib/helpers/spinner.rb
|
166
|
+
- lib/allure_report_publisher/lib/providers/_provider.rb
|
167
|
+
- lib/allure_report_publisher/lib/providers/github.rb
|
168
|
+
- lib/allure_report_publisher/lib/providers/gitlab.rb
|
121
169
|
- lib/allure_report_publisher/lib/report_generator.rb
|
122
170
|
- lib/allure_report_publisher/lib/uploaders/_uploader.rb
|
123
|
-
- lib/allure_report_publisher/lib/uploaders/
|
171
|
+
- lib/allure_report_publisher/lib/uploaders/gcs.rb
|
172
|
+
- lib/allure_report_publisher/lib/uploaders/s3.rb
|
124
173
|
- lib/allure_report_publisher/version.rb
|
125
174
|
homepage: https://github.com/andrcuns/allure-report-uploader
|
126
175
|
licenses:
|
@@ -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
|
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,63 +0,0 @@
|
|
1
|
-
module Publisher
|
2
|
-
# CI provider utilities
|
3
|
-
#
|
4
|
-
module CI
|
5
|
-
# Detect CI provider
|
6
|
-
#
|
7
|
-
# @return [Publisher::CI::Base]
|
8
|
-
def self.provider
|
9
|
-
return GithubActions if ENV["GITHUB_WORKFLOW"]
|
10
|
-
end
|
11
|
-
|
12
|
-
# Base class for CI executor info
|
13
|
-
#
|
14
|
-
class Base
|
15
|
-
EXECUTOR_JSON = "executor.json".freeze
|
16
|
-
|
17
|
-
def initialize(results_path, report_url)
|
18
|
-
@results_path = results_path
|
19
|
-
@report_url = report_url
|
20
|
-
end
|
21
|
-
|
22
|
-
# :nocov:
|
23
|
-
|
24
|
-
# Get ci run ID without creating instance of ci provider
|
25
|
-
#
|
26
|
-
# @return [String]
|
27
|
-
def self.run_id
|
28
|
-
raise("Not implemented!")
|
29
|
-
end
|
30
|
-
# :nocov:
|
31
|
-
|
32
|
-
# Write executor info file
|
33
|
-
#
|
34
|
-
# @return [void]
|
35
|
-
def write_executor_info
|
36
|
-
File.open("#{results_path}/#{EXECUTOR_JSON}", "w") do |file|
|
37
|
-
file.write(executor_info.to_json)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
attr_reader :results_path, :report_url
|
44
|
-
|
45
|
-
# :nocov:
|
46
|
-
|
47
|
-
# Get executor info
|
48
|
-
#
|
49
|
-
# @return [Hash]
|
50
|
-
def executor_info
|
51
|
-
raise("Not implemented!")
|
52
|
-
end
|
53
|
-
# :nocov:
|
54
|
-
|
55
|
-
# CI run id
|
56
|
-
#
|
57
|
-
# @return [String]
|
58
|
-
def run_id
|
59
|
-
self.class.run_id
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module Publisher
|
2
|
-
module CI
|
3
|
-
# Github actions executor info
|
4
|
-
#
|
5
|
-
class GithubActions < Base
|
6
|
-
# Run id
|
7
|
-
#
|
8
|
-
# @return [String]
|
9
|
-
def self.run_id
|
10
|
-
@run_id ||= ENV["GITHUB_RUN_ID"]
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
# Executor info
|
16
|
-
#
|
17
|
-
# @return [Hash]
|
18
|
-
def executor_info
|
19
|
-
{
|
20
|
-
name: "Github",
|
21
|
-
type: "github",
|
22
|
-
reportName: "AllureReport",
|
23
|
-
url: server_url,
|
24
|
-
reportUrl: report_url,
|
25
|
-
buildUrl: build_url,
|
26
|
-
buildOrder: run_id,
|
27
|
-
buildName: build_name
|
28
|
-
}
|
29
|
-
end
|
30
|
-
|
31
|
-
# Server url
|
32
|
-
#
|
33
|
-
# @return [String]
|
34
|
-
def server_url
|
35
|
-
@server_url ||= ENV["GITHUB_SERVER_URL"]
|
36
|
-
end
|
37
|
-
|
38
|
-
# Build url
|
39
|
-
#
|
40
|
-
# @return [String]
|
41
|
-
def build_url
|
42
|
-
@build_url ||= "#{server_url}/#{ENV['GITHUB_REPOSITORY']}/actions/runs/#{run_id}"
|
43
|
-
end
|
44
|
-
|
45
|
-
def build_name
|
46
|
-
@build_name ||= ENV["GITHUB_JOB"]
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
require "aws-sdk-s3"
|
2
|
-
|
3
|
-
module Publisher
|
4
|
-
module Uploaders
|
5
|
-
# Report upload to AWS S3 bucket
|
6
|
-
#
|
7
|
-
class S3 < Uploader
|
8
|
-
def execute
|
9
|
-
generate_report
|
10
|
-
upload_history_and_report
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
# S3 client
|
16
|
-
#
|
17
|
-
# @return [Aws::S3::Client]
|
18
|
-
def s3
|
19
|
-
@s3 ||= Aws::S3::Client.new(region: ENV["AWS_REGION"] || "us-east-1")
|
20
|
-
end
|
21
|
-
|
22
|
-
# Report url
|
23
|
-
#
|
24
|
-
# @return [String]
|
25
|
-
def report_url
|
26
|
-
@report_url ||= ["http://#{bucket}.s3.amazonaws.com", full_prefix, "index.html"].compact.join("/")
|
27
|
-
end
|
28
|
-
|
29
|
-
# Add allure history
|
30
|
-
#
|
31
|
-
# @return [void]
|
32
|
-
def add_history
|
33
|
-
super do
|
34
|
-
HISTORY.each do |file|
|
35
|
-
s3.get_object(
|
36
|
-
response_target: path(results_dir, "history", file),
|
37
|
-
key: key(prefix, "history", file),
|
38
|
-
bucket: bucket
|
39
|
-
)
|
40
|
-
end
|
41
|
-
rescue Aws::S3::Errors::NoSuchKey
|
42
|
-
raise("Allure history from previous runs not found!")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
# Upload report to s3
|
47
|
-
#
|
48
|
-
# @return [void]
|
49
|
-
def upload_history_and_report
|
50
|
-
log("Uploading report to s3")
|
51
|
-
Helpers::Spinner.spin("uploading report", done_message: "done. #{report_url}") do
|
52
|
-
upload_history
|
53
|
-
upload_report
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# Upload allure history
|
58
|
-
#
|
59
|
-
# @return [void]
|
60
|
-
def upload_history
|
61
|
-
upload_to_s3(report_files.select { |file| file.fnmatch?("*/history/*") }, prefix)
|
62
|
-
end
|
63
|
-
|
64
|
-
def upload_report
|
65
|
-
upload_to_s3(report_files)
|
66
|
-
end
|
67
|
-
|
68
|
-
# Upload files to s3
|
69
|
-
#
|
70
|
-
# @param [Array<Pathname>] files
|
71
|
-
# @param [String] key_prefix
|
72
|
-
# @return [Array<Hash>]
|
73
|
-
def upload_to_s3(files, key_prefix = full_prefix)
|
74
|
-
args = files.map do |file|
|
75
|
-
{
|
76
|
-
body: File.new(file),
|
77
|
-
bucket: bucket,
|
78
|
-
key: key(key_prefix, file.relative_path_from(report_dir))
|
79
|
-
}
|
80
|
-
end
|
81
|
-
|
82
|
-
Parallel.each(args, in_threads: 8) { |obj| s3.put_object(obj) }
|
83
|
-
end
|
84
|
-
|
85
|
-
# Fabricate key for s3 object
|
86
|
-
#
|
87
|
-
# @param [String] *args
|
88
|
-
# @return [String]
|
89
|
-
def key(*args)
|
90
|
-
args.compact.join("/")
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|