Skip to content

Commit

Permalink
Add ability to set custom report name in final allure report (#633)
Browse files Browse the repository at this point in the history
* Allow to set custom report name

* Set custom test report name

* Correctly set report name with space

* Improve option description
  • Loading branch information
andrcuns authored Jan 24, 2024
1 parent 3a02ec8 commit 7db9f51
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ jobs:
--summary="behaviors" \
--summary-table-type="${{ matrix.table }}" \
--report-title="Test Report" \
--report-name="Test Report" \
--copy-latest \
--color \
--debug
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Options:
--prefix=VALUE # Optional prefix for report path. Required: false
--update-pr=VALUE # Add report url to PR via comment or description update. Required: false: (comment/description/actions)
--report-title=VALUE # Title for url section in PR comment/description. Required: false, default: "Allure Report"
--report-name=VALUE # Custom report name in final Allure report. Required: false
--summary=VALUE # Additionally add summary table to PR comment or description. Required: false: (behaviors/suites/packages/total), default: "total"
--summary-table-type=VALUE # Summary table type. Required: false: (ascii/markdown), default: "ascii"
--base-url=VALUE # Use custom base url instead of default cloud provider one. Required: false
Expand Down
5 changes: 4 additions & 1 deletion lib/allure_report_publisher/commands/upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class Upload < Dry::CLI::Command
type: :string,
default: "Allure Report",
desc: "Title for url section in PR comment/description. Required: false"
option :report_name,
type: :string,
desc: "Custom report name in final Allure report. Required: false"
option :summary,
type: :string,
desc: "Additionally add summary table to PR comment or description. Required: false",
Expand Down Expand Up @@ -109,7 +112,7 @@ def call(**args)
def uploader
@uploader ||= uploaders(args[:type]).new(
result_paths: @result_paths,
**args.slice(:bucket, :prefix, :base_url, :copy_latest)
**args.slice(:bucket, :prefix, :base_url, :copy_latest, :report_name)
)
end

Expand Down
11 changes: 8 additions & 3 deletions lib/allure_report_publisher/lib/report_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ class NoAllureResultsError < StandardError; end
class ReportGenerator
include Helpers

def initialize(result_paths)
def initialize(result_paths, report_name)
@result_paths = result_paths.join(" ")
@report_name = report_name
end

# Generate allure report
Expand Down Expand Up @@ -44,14 +45,18 @@ def report_path

# @return [String] result paths string
attr_reader :result_paths
# @return [String] custom report name
attr_reader :report_name

# Generate allure report
#
# @return [void]
def generate_report
log_debug("Generating allure report")
cmd = "allure generate --clean --output #{report_path} #{common_info_path} #{result_paths}"
out = execute_shell(cmd)
cmd = ["allure generate --clean"]
cmd << "--report-name '#{report_name}'" if report_name
cmd << "--output #{report_path} #{common_info_path} #{result_paths}"
out = execute_shell(cmd.join(" "))
log_debug("Generated allure report. #{out}".strip)

deduplicate_executors
Expand Down
7 changes: 5 additions & 2 deletions lib/allure_report_publisher/lib/uploaders/_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ class Uploader
# @option args [String] :prefix
# @option args [String] :base_url
# @option args [String] :copy_latest
# @option args [String] :report_name
def initialize(**args)
@result_paths = args[:result_paths]
@bucket_name = args[:bucket]
@prefix = args[:prefix]
@base_url = args[:base_url]
@copy_latest = ci_info && args[:copy_latest] # copy latest for ci only
@report_name = args[:report_name]
end

# Execute allure report generation and upload
Expand Down Expand Up @@ -94,7 +96,8 @@ def report_url
:bucket_name,
:prefix,
:base_url,
:copy_latest
:copy_latest,
:report_name

def_delegator :report_generator, :common_info_path

Expand Down Expand Up @@ -155,7 +158,7 @@ def upload_latest_copy
#
# @return [Publisher::ReportGenerator]
def report_generator
@report_generator ||= ReportGenerator.new(result_paths)
@report_generator ||= ReportGenerator.new(result_paths, report_name)
end

# Report path prefix
Expand Down
35 changes: 27 additions & 8 deletions spec/allure_report_publisher/lib/report_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
RSpec.describe Publisher::ReportGenerator, epic: "generator" do
include ActiveSupport::Testing::TimeHelpers

subject(:report_generator) { described_class.new(result_paths) }
subject(:report_generator) { described_class.new(result_paths, report_name) }

include_context "with mock helper"

Expand All @@ -15,6 +15,7 @@
let(:report_dir) { File.join(tmpdir, "allure-report-#{Time.now.to_i}") }
let(:status) { true }
let(:tmpdir) { "/tmp/dir" }
let(:report_name) { nil }

before do
allow(Dir).to receive(:mktmpdir).with("allure-results") { common_info_dir }
Expand All @@ -31,14 +32,32 @@
allow(File).to receive(:write).with("#{report_dir}/widgets/executors.json", deduped_executors)
end

it "generates allure report" do
freeze_time do
report_generator.generate
context "without custom report name" do
it "generates allure report" do
freeze_time do
report_generator.generate

expect(Open3).to have_received(:capture3).with(
"allure generate --clean --output #{report_dir} #{common_info_dir} #{result_paths.join(' ')}"
)
expect(File).to have_received(:write).with("#{report_dir}/widgets/executors.json", deduped_executors)
end
end
end

context "with custom report name" do
let(:report_name) { "custom_report_name" }

it "generates allure report with custom name" do
freeze_time do
report_generator.generate

expect(Open3).to have_received(:capture3).with(
"allure generate --clean --output #{report_dir} #{common_info_dir} #{result_paths.join(' ')}"
)
expect(File).to have_received(:write).with("#{report_dir}/widgets/executors.json", deduped_executors)
expect(Open3).to have_received(:capture3).with(
"allure generate --clean --report-name '#{report_name}' " \
"--output #{report_dir} #{common_info_dir} #{result_paths.join(' ')}"
)
expect(File).to have_received(:write).with("#{report_dir}/widgets/executors.json", deduped_executors)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
let(:base_url) { nil }
let(:ci_provider) { nil }
let(:run_id) { "123" }
let(:report_name) { nil }

let(:history_files) do
[
Expand All @@ -33,7 +34,8 @@
bucket: bucket_name,
prefix: prefix,
base_url: base_url,
copy_latest: false
copy_latest: false,
report_name: report_name
}
end

Expand Down
2 changes: 1 addition & 1 deletion spec/allure_report_publisher/lib/uploaders/gcs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
described_class.new(**args).execute

aggregate_failures do
expect(Publisher::ReportGenerator).to have_received(:new).with(result_paths)
expect(Publisher::ReportGenerator).to have_received(:new).with(result_paths, report_name)
expect(report_generator).to have_received(:generate)
end
end
Expand Down
24 changes: 18 additions & 6 deletions spec/allure_report_publisher/lib/uploaders/s3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@
allow(File).to receive(:new).with(Pathname.new(report_latest[:body].path)) { report_latest[:body] }
end

shared_examples "report generator" do
it "generates allure report" do
described_class.new(**args).execute

aggregate_failures do
expect(Publisher::ReportGenerator).to have_received(:new).with(result_paths, report_name)
expect(report_generator).to have_received(:generate)
end
end
end

context "with missing aws credentials" do
let(:err_msg) do
Pastel.new(enabled: true).decorate(<<~MSG.strip, :red)
Expand Down Expand Up @@ -79,13 +90,14 @@
ClimateControl.modify(GITHUB_WORKFLOW: nil, GITLAB_CI: nil) { example.run }
end

it "generates allure report" do
described_class.new(**args).execute
context "without custom report name" do
it_behaves_like "report generator"
end

aggregate_failures do
expect(Publisher::ReportGenerator).to have_received(:new).with(result_paths)
expect(report_generator).to have_received(:generate)
end
context "with custom report name" do
let(:report_name) { "custom_report_name" }

it_behaves_like "report generator"
end

it "uploads allure report to s3" do
Expand Down

0 comments on commit 7db9f51

Please sign in to comment.