Commit 6fbb2cbd authored by Ramya Authappan's avatar Ramya Authappan

Merge branch 'acunskis-allure-attach-version' into 'master'

E2E: attach gitlab version and revision to allure report

See merge request gitlab-org/gitlab!71645
parents 8dec52d0 a2504a32
......@@ -4,7 +4,7 @@ source 'https://rubygems.org'
gem 'gitlab-qa', require: 'gitlab/qa'
gem 'activesupport', '~> 6.1.3.2' # This should stay in sync with the root's Gemfile
gem 'allure-rspec', '~> 2.14.5'
gem 'allure-rspec', '~> 2.15.0'
gem 'capybara', '~> 3.35.0'
gem 'capybara-screenshot', '~> 1.0.23'
gem 'rake', '~> 12.3.3'
......
......@@ -19,10 +19,10 @@ GEM
rack-test (>= 1.1.0, < 2.0)
rest-client (>= 2.0.2, < 3.0)
rspec (~> 3.8)
allure-rspec (2.14.5)
allure-ruby-commons (= 2.14.5)
allure-rspec (2.15.0)
allure-ruby-commons (= 2.15.0)
rspec-core (>= 3.8, < 4)
allure-ruby-commons (2.14.5)
allure-ruby-commons (2.15.0)
mime-types (>= 3.3, < 4)
oj (>= 3.10, < 4)
require_all (>= 2, < 4)
......@@ -136,7 +136,7 @@ GEM
octokit (4.21.0)
faraday (>= 0.9)
sawyer (~> 0.8.0, >= 0.5.3)
oj (3.13.2)
oj (3.13.8)
parallel (1.19.2)
parallel_tests (2.29.0)
parallel
......@@ -241,7 +241,7 @@ PLATFORMS
DEPENDENCIES
activesupport (~> 6.1.3.2)
airborne (~> 0.3.4)
allure-rspec (~> 2.14.5)
allure-rspec (~> 2.15.0)
capybara (~> 3.35.0)
capybara-screenshot (~> 1.0.23)
chemlab (~> 0.9)
......
......@@ -5,6 +5,8 @@ require 'active_support/core_ext/enumerable'
module QA
module Runtime
class AllureReport
extend QA::Support::API
class << self
# Configure allure reports
#
......@@ -77,27 +79,21 @@ module QA
end
end
# Custom environment info hash
# Gitlab version and revision information
#
# @return [Hash]
def environment_info
%w[
CI_COMMIT_SHA
CI_MERGE_REQUEST_SOURCE_BRANCH_SHA
CI_MERGE_REQUEST_IID
TOP_UPSTREAM_SOURCE_SHA
TOP_UPSTREAM_MERGE_REQUEST_IID
DEPLOY_VERSION
GITLAB_VERSION
GITLAB_SHELL_VERSION
GITLAB_ELASTICSEARCH_INDEXER_VERSION
GITLAB_KAS_VERSION
GITLAB_WORKHORSE_VERSION
GITLAB_PAGES_VERSION
GITALY_SERVER_VERSION
QA_IMAGE
QA_BROWSER
].index_with { |val| ENV[val] }.compact_blank
lambda do
return {} unless Env.admin_personal_access_token || Env.personal_access_token
client = Env.admin_personal_access_token ? API::Client.as_admin : API::Client.new
response = get(API::Request.new(client, '/version').url)
JSON.parse(response.body, symbolize_names: true)
rescue StandardError, ArgumentError => e
Logger.error("Failed to attach version info to allure report: #{e}")
{}
end
end
end
end
......
......@@ -45,14 +45,18 @@ describe QA::Runtime::AllureReport do
let(:png_file) { 'png-file' }
let(:html_file) { 'html-file' }
let(:ci_job) { 'ee:relative 5' }
let(:versions) { { version: '14', revision: '6ced31db947' } }
before do
stub_env('CI', 'true')
stub_env('CI_JOB_NAME', ci_job)
stub_env('GITLAB_QA_ADMIN_ACCESS_TOKEN', 'token')
allow(Allure).to receive(:add_attachment)
allow(File).to receive(:open).with(png_path) { png_file }
allow(File).to receive(:open).with(html_path) { html_file }
allow(RestClient::Request).to receive(:execute) { double('response', code: 200, body: versions.to_json) }
allow(QA::Runtime::Scenario).to receive(:method_missing).with(:gitlab_address).and_return('gitlab.com')
described_class.configure!
end
......@@ -61,7 +65,7 @@ describe QA::Runtime::AllureReport do
aggregate_failures do
expect(allure_config.results_directory).to eq('tmp/allure-results')
expect(allure_config.clean_results_directory).to eq(true)
expect(allure_config.environment_properties).to be_a_kind_of(Hash)
expect(allure_config.environment_properties.call).to eq(versions)
expect(allure_config.environment).to eq('ee:relative')
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment