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