Commit f97f1e4e authored by Phil Hughes's avatar Phil Hughes

Merge branch '10io-qa-add-pull-test-for-gradle' into 'master'

Improve gradle QA scenario

See merge request gitlab-org/gitlab!64419
parents c0db0637 85558bab
......@@ -38,7 +38,7 @@
- if packages_registry_enabled?(group_or_project)
%fieldset.form-group.form-check
= f.check_box :read_package_registry, class: 'form-check-input'
= f.check_box :read_package_registry, class: 'form-check-input', data: { qa_selector: 'deploy_token_read_package_registry_checkbox' }
= f.label :read_package_registry, 'read_package_registry', class: 'label-bold form-check-label'
.text-secondary= s_('DeployTokens|Allows read access to the package registry.')
......
......@@ -9,6 +9,7 @@ module QA
element :deploy_token_name_field
element :deploy_token_expires_at_field
element :deploy_token_read_repository_checkbox
element :deploy_token_read_package_registry_checkbox
element :deploy_token_read_registry_checkbox
element :create_deploy_token_button
end
......@@ -27,8 +28,9 @@ module QA
fill_element(:deploy_token_expires_at_field, expires_at.to_s + "\n")
end
def fill_scopes(read_repository:, read_registry:)
def fill_scopes(read_repository: false, read_registry: false, read_package_registry: false)
check_element(:deploy_token_read_repository_checkbox) if read_repository
check_element(:deploy_token_read_package_registry_checkbox) if read_package_registry
check_element(:deploy_token_read_registry_checkbox) if read_registry
end
......
......@@ -37,7 +37,7 @@ module QA
setting.expand_deploy_tokens do |page|
page.fill_token_name(name)
page.fill_token_expires_at(expires_at)
page.fill_scopes(read_repository: true, read_registry: false)
page.fill_scopes(read_repository: true, read_package_registry: true)
page.add_token
end
......
......@@ -15,11 +15,10 @@ module QA
end
attribute :id do
packages = project.packages
return unless (this_package = packages&.find { |package| package[:name] == "#{project.path_with_namespace}/#{name}" }) # rubocop:disable Cop/AvoidReturnFromBlocks
this_package = project.packages
&.find { |package| package[:name] == name }
this_package[:id]
this_package.try(:fetch, :id)
end
def fabricate!
......
......@@ -3,39 +3,45 @@
module QA
RSpec.describe 'Package', :orchestrated, :packages do
describe 'Maven Repository with Gradle' do
using RSpec::Parameterized::TableSyntax
include Runtime::Fixtures
let(:group_id) { 'com.gitlab.qa' }
let(:artifact_id) { 'maven_gradle' }
let(:package_name) { "#{group_id}/#{artifact_id}".tr('.', '/') }
let(:auth_token) do
unless Page::Main::Menu.perform(&:signed_in?)
Flow::Login.sign_in
end
let(:package_version) { '1.3.7' }
Resource::PersonalAccessToken.fabricate!.token
end
let(:personal_access_token) { Runtime::Env.personal_access_token }
let(:project) do
let(:package_project) do
Resource::Project.fabricate_via_api! do |project|
project.name = 'maven-with-gradle-project'
project.initialize_with_readme = true
project.visibility = :private
end
end
let(:client_project) do
Resource::Project.fabricate_via_api! do |client_project|
client_project.name = 'gradle_client'
client_project.initialize_with_readme = true
client_project.group = package_project.group
end
end
let(:package) do
Resource::Package.init do |package|
package.name = package_name
package.project = project
package.project = package_project
end
end
let!(:runner) do
let(:runner) do
Resource::Runner.fabricate! do |runner|
runner.name = "qa-runner-#{Time.now.to_i}"
runner.tags = ["runner-for-#{project.name}"]
runner.tags = ["runner-for-#{package_project.group.name}"]
runner.executor = :docker
runner.project = project
runner.token = package_project.group.runners_token
end
end
......@@ -44,16 +50,15 @@ module QA
"#{uri.scheme}://#{uri.host}:#{uri.port}"
end
after do
runner.remove_via_api!
package.remove_via_api!
let(:project_deploy_token) do
Resource::DeployToken.fabricate_via_browser_ui! do |deploy_token|
deploy_token.name = 'maven-with-gradle-deploy-token'
deploy_token.project = package_project
end
end
it 'publishes a maven package via gradle', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1074' do
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files([{
let(:package_gitlab_ci_file) do
{
file_path: '.gitlab-ci.yml',
content:
<<~YAML
......@@ -62,11 +67,14 @@ module QA
script:
- 'gradle publish'
only:
- "#{project.default_branch}"
- "#{package_project.default_branch}"
tags:
- "runner-for-#{project.name}"
- "runner-for-#{package_project.group.name}"
YAML
},
}
end
let(:package_build_gradle_file) do
{
file_path: 'build.gradle',
content:
......@@ -81,15 +89,16 @@ module QA
library(MavenPublication) {
groupId '#{group_id}'
artifactId '#{artifact_id}'
version '#{package_version}'
from components.java
}
}
repositories {
maven {
url "#{gitlab_address_with_port}/api/v4/projects/#{project.id}/packages/maven"
url "#{gitlab_address_with_port}/api/v4/projects/#{package_project.id}/packages/maven"
credentials(HttpHeaderCredentials) {
name = "Private-Token"
value = "#{auth_token}"
value = "#{personal_access_token}"
}
authentication {
header(HttpHeaderAuthentication)
......@@ -98,10 +107,103 @@ module QA
}
}
EOF
}])
}
end
project.visit!
let(:client_gitlab_ci_file) do
{
file_path: '.gitlab-ci.yml',
content:
<<~YAML
build:
image: gradle:6.5-jdk11
script:
- 'gradle build'
only:
- "#{client_project.default_branch}"
tags:
- "runner-for-#{client_project.group.name}"
YAML
}
end
before do
Flow::Login.sign_in_unless_signed_in
runner
end
after do
runner.remove_via_api!
package.remove_via_api!
package_project.remove_via_api!
client_project.remove_via_api!
end
where(:authentication_token_type, :maven_header_name) do
:personal_access_token | 'Private-Token'
:ci_job_token | 'Job-Token'
:project_deploy_token | 'Deploy-Token'
end
with_them do
let(:token) do
case authentication_token_type
when :personal_access_token
"\"#{personal_access_token}\""
when :ci_job_token
'System.getenv("CI_JOB_TOKEN")'
when :project_deploy_token
"\"#{project_deploy_token.password}\""
end
end
let(:client_build_gradle_file) do
{
file_path: 'build.gradle',
content:
<<~EOF
plugins {
id 'java'
id 'application'
}
repositories {
jcenter()
maven {
url "#{gitlab_address_with_port}/api/v4/projects/#{package_project.id}/packages/maven"
name "GitLab"
credentials(HttpHeaderCredentials) {
name = '#{maven_header_name}'
value = #{token}
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
dependencies {
implementation group: '#{group_id}', name: '#{artifact_id}', version: '#{package_version}'
testImplementation 'junit:junit:4.12'
}
application {
mainClassName = 'gradle_maven_app.App'
}
EOF
}
end
it "pushes and pulls a maven package via gradle using #{params[:authentication_token_type]}", testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1074' do
# pushing
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = package_project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files([package_gitlab_ci_file, package_build_gradle_file])
end
package_project.visit!
Flow::Pipeline.visit_latest_pipeline
Page::Project::Pipeline::Show.perform do |pipeline|
......@@ -120,11 +222,28 @@ module QA
index.click_package(package_name)
end
Page::Project::Packages::Show.perform(&:click_delete)
Page::Project::Packages::Show.perform do |show|
expect(show).to have_package_info(package_name, package_version)
end
Page::Project::Packages::Index.perform do |index|
expect(index).to have_content("Package deleted successfully")
expect(index).not_to have_package(package_name)
# pulling
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = client_project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files([client_gitlab_ci_file, client_build_gradle_file])
end
client_project.visit!
Flow::Pipeline.visit_latest_pipeline
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('build')
end
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 800)
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