Commit 2fdb7dd6 authored by Dan Davison's avatar Dan Davison

Merge branch 'e2e-cicd-github' into 'master'

E2E test for CICD with Github

See merge request gitlab-org/gitlab!50905
parents 6e9ec5d8 1da7b485
......@@ -21,6 +21,7 @@ gem 'rotp', '~> 3.1.0'
gem 'timecop', '~> 0.9.1'
gem 'parallel', '~> 1.19'
gem 'rspec-parameterized', '~> 0.4.2'
gem 'github_api', '~> 0.18.2'
group :development do
gem 'pry-byebug', '~> 3.5.1', platform: :mri
......
......@@ -39,19 +39,31 @@ GEM
adamantium (~> 0.2.0)
equalizer (~> 0.0.9)
concurrent-ruby (1.1.7)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
diff-lcs (1.3)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
equalizer (0.0.11)
faker (1.9.3)
i18n (>= 0.7)
faraday (0.17.3)
multipart-post (>= 1.2, < 3)
github_api (0.18.2)
addressable (~> 2.4)
descendants_tracker (~> 0.0.4)
faraday (~> 0.8)
hashie (~> 3.5, >= 3.5.2)
oauth2 (~> 1.0)
gitlab-qa (4.0.0)
hashie (3.6.0)
http-accept (1.7.0)
http-cookie (1.0.3)
domain_name (~> 0.5)
i18n (1.8.5)
concurrent-ruby (~> 1.0)
ice_nine (0.11.2)
jwt (2.2.2)
knapsack (1.17.1)
rake
launchy (2.4.3)
......@@ -65,10 +77,19 @@ GEM
mini_mime (1.0.2)
mini_portile2 (2.5.0)
minitest (5.14.2)
multi_json (1.15.0)
multi_xml (0.6.0)
multipart-post (2.1.1)
netrc (0.11.0)
nokogiri (1.11.1)
mini_portile2 (~> 2.5.0)
racc (~> 1.4)
oauth2 (1.4.4)
faraday (>= 0.8, < 2.0)
jwt (>= 1.0, < 3.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
parallel (1.19.2)
parallel_tests (2.29.0)
parallel
......@@ -155,6 +176,7 @@ DEPENDENCIES
capybara (~> 3.29.0)
capybara-screenshot (~> 1.0.23)
faker (~> 1.6, >= 1.6.6)
github_api (~> 0.18.2)
gitlab-qa
knapsack (~> 1.17)
nokogiri (~> 1.11.1)
......
......@@ -28,8 +28,8 @@ module QA
element :template_option_row
end
view 'ee/app/views/projects/_new_ci_cd_only_project_tab.html.haml' do
element :ci_cd_project_tab
view 'app/assets/javascripts/projects/experiment_new_project_creation/components/welcome.vue' do
element :cicd_for_external_repo_link, ':data-qa-selector="`${panel.name}_link`"' # rubocop:disable QA/ElementWithPattern
end
end
end
......@@ -50,8 +50,8 @@ module QA
find_element(:instance_template_tab_badge).text
end
def click_ci_cd_for_external_repo
click_element :ci_cd_project_tab
def click_cicd_for_external_repo
click_element :cicd_for_external_repo_link
end
end
end
......
......@@ -8,8 +8,8 @@ module QA
super
end
def go_to_import_tab
QA::Page::Project::New.perform(&:click_ci_cd_for_external_repo)
def go_to_import_page
QA::Page::Project::New.perform(&:click_cicd_for_external_repo)
end
end
end
......
......@@ -30,6 +30,7 @@ module QA
set_path(full_path, name)
import_project(full_path)
wait_for_success
go_to_project(name)
end
private
......@@ -73,6 +74,13 @@ module QA
page.has_content?('Done', wait: 1.0)
end
end
def go_to_project(name)
Page::Main::Menu.perform(&:go_to_projects)
Page::Dashboard::Projects.perform do |dashboard|
dashboard.go_to_project(name)
end
end
end
end
end
......
......@@ -12,7 +12,7 @@ module QA
group.visit!
Page::Group::Show.perform(&:go_to_new_project)
go_to_import_tab
go_to_import_page
Page::Project::New.perform(&:click_github_link)
Page::Project::Import::Github.perform do |import_page|
......@@ -21,7 +21,7 @@ module QA
end
end
def go_to_import_tab
def go_to_import_page
Page::Project::New.perform(&:click_import_project)
end
end
......
# frozen_string_literal: true
require 'github_api'
require 'faker'
require 'base64'
module QA
context 'Verify', :github, only: { subdomain: :staging } do
include Support::Api
describe 'Pipeline for project mirrors Github' do
let(:commit_message) { "Update #{github_data[:file_name]} - #{Time.now}" }
let(:project_name) { 'github-project-with-pipeline' }
let(:api_client) { Runtime::API::Client.new(:gitlab) }
let(:github_client) { Github::Client::Repos::Contents.new oauth_token: github_data[:access_token] }
let(:import_project) do
EE::Resource::ImportRepoWithCICD.fabricate_via_browser_ui! do |project|
project.import = true
project.name = project_name
project.github_personal_access_token = github_data[:access_token]
project.github_repository_path = github_data[:repo_name]
end
end
before do
Flow::Login.sign_in
import_project
Page::Project::Menu.perform(&:click_ci_cd_pipelines)
end
after do
remove_project
end
it 'user commits to GitHub triggers CI pipeline', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/144' do
Page::Project::Pipeline::Index.perform do |index|
expect(index).to have_no_pipeline, 'Expect to have NO pipeline before mirroring.'
edit_github_file
trigger_project_mirror
index.wait_until(reload: false) { index.has_pipeline? }
expect(index).to have_content(commit_message), 'Expect new pipeline to have latest commit message from Github.'
end
end
private
def github_data
{
access_token: Runtime::Env.github_access_token,
repo_owner: 'gitlab-qa-github',
repo_name: 'test-project',
file_name: 'text_file.txt'
}
end
def edit_github_file
file = github_client.get github_data[:repo_owner], github_data[:repo_name], github_data[:file_name]
file_sha = file.body['sha']
file_path = file.body['path']
file_new_content = Faker::Lorem.sentence
github_client.update(github_data[:repo_owner], github_data[:repo_name], github_data[:file_name],
path: file_path, message: commit_message,
content: file_new_content,
sha: file_sha)
Support::Retrier.retry_until(max_attempts: 5, sleep_interval: 2) do
Base64.decode64(github_client.get(user: github_data[:repo_owner], repo: github_data[:repo_name], path: file_path)&.content) == file_new_content
end
end
def import_project_id
request = Runtime::API::Request.new(api_client, import_project.api_get_path)
JSON.parse(get(request.url))['id']
end
def trigger_project_mirror
request = Runtime::API::Request.new(api_client, "/projects/#{import_project_id}/mirror/pull")
post(request.url, nil)
end
def remove_project
delete_project_request = Runtime::API::Request.new(api_client, "/projects/#{CGI.escape("#{Runtime::Namespace.path}/#{import_project.name}")}")
delete delete_project_request.url
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