Commit e848e5e0 authored by Sofia Vistas's avatar Sofia Vistas Committed by Dan Davison

Refactor to use fixtures folder instead of CI scripts

parent 1a8b8581
{
"name": "<%= project.path_with_namespace %>/<%= package.name %>",
"description": "Library XY",
"type": "library",
"license": "GPL-3.0-only",
"authors": [
{
"name": "John Doe",
"email": "john@example.com"
}
],
"require": {}
}
\ No newline at end of file
publish:
image: curlimages/curl:latest
stage: build
variables:
URL: "$CI_SERVER_PROTOCOL://$CI_SERVER_HOST:$CI_SERVER_PORT/api/v4/projects/$CI_PROJECT_ID/packages/composer?job_token=$CI_JOB_TOKEN"
script:
- version=$([[ -z "$CI_COMMIT_TAG" ]] && echo "branch=$CI_COMMIT_REF_NAME" || echo "tag=$CI_COMMIT_TAG")
- insecure=$([ "$CI_SERVER_PROTOCOL" = "http" ] && echo "--insecure" || echo "")
- response=$(curl -s -w "%{http_code}" $insecure --data $version $URL)
- code=$(echo "$response" | tail -n 1)
- body=$(echo "$response" | head -n 1)
tags:
- "runner-for-<%= project.name %>"
\ No newline at end of file
image: conanio/gcc7
test_package:
stage: deploy
script:
- conan remote add gitlab <%= gitlab_address_with_port %>/api/v4/projects/<%= project.id %>/packages/conan
- conan new <%= package.name %>/0.1 -t
- conan create . mycompany/stable
- "CONAN_LOGIN_USERNAME=ci_user CONAN_PASSWORD=${CI_JOB_TOKEN} conan upload <%= package.name %>/0.1@mycompany/stable --all --remote=gitlab"
- conan install <%= package.name %>/0.1@mycompany/stable --remote=gitlab
tags:
- runner-for-<%= project.name %>
\ No newline at end of file
image: curlimages/curl:latest
stages:
- upload
- download
upload:
stage: upload
script:
- 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file file.txt ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/<%= package.name %>/0.0.1/file.txt'
tags:
- runner-for-<%= project.name %>
download:
stage: download
script:
- 'wget --header="JOB-TOKEN: $CI_JOB_TOKEN" ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/<%= package.name %>/0.0.1/file.txt -O file_downloaded.txt'
tags:
- runner-for-<%= project.name %>
\ No newline at end of file
apiVersion: v2
name: <%= package_name %>
description: GitLab QA helm package
type: application
version: <%= package_version %>
appVersion: "1.16.0"
\ No newline at end of file
pull:
image: alpine:3
script:
- apk add helm --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing
- helm repo add --username <%= username %> --password <%= access_token %> gitlab_qa ${CI_API_V4_URL}/projects/<%= package_project.id %>/packages/helm/stable
- helm repo update
- helm pull gitlab_qa/<%= package_name %>
only:
- <%= client_project.default_branch %>
tags:
- runner-for-<%=client_project.group.name %>
\ No newline at end of file
deploy:
image: alpine:3
script:
- apk add helm --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing
- apk add curl
- helm create <%= package_name %>
- cp ./Chart.yaml <%= package_name %>
- helm package <%= package_name %>
- http_code=$(curl --write-out "%{http_code}" --request POST --form 'chart=@<%= package_name %>-<%= package_version %>.tgz' --user <%= username %>:<%= access_token %> ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/helm/api/stable/charts --output /dev/null --silent)
- '[ $http_code = "201" ]'
only:
- <%= package_project.default_branch %>
tags:
- runner-for-<%= package_project.group.name %>
\ No newline at end of file
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'
}
\ No newline at end of file
plugins {
id 'java'
id 'maven-publish'
}
publishing {
publications {
library(MavenPublication) {
groupId '<%= group_id %>'
artifactId '<%= artifact_id %>'
version '<%= package_version %>'
from components.java
}
}
repositories {
maven {
url "<%= gitlab_address_with_port %>/api/v4/projects/<%= package_project.id %>/packages/maven"
credentials(HttpHeaderCredentials) {
name = "Private-Token"
value = "<%= personal_access_token %>"
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
}
\ No newline at end of file
<project>
<groupId><%= group_id %></groupId>
<artifactId>maven_client</artifactId>
<version>1.0</version>
<modelVersion>4.0.0</modelVersion>
<repositories>
<repository>
<id><%= package_project.name %></id>
<url><%= gitlab_address_with_port %>/api/v4/groups/<%= package_project.group.id %>/-/packages/maven</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId><%= group_id %></groupId>
<artifactId><%= artifact_id %></artifactId>
<version><%= package_version %></version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
build:
image: gradle:6.5-jdk11
script:
- 'gradle build'
only:
- "<%= client_project.default_branch %>"
tags:
- "runner-for-<%= client_project.group.name %>"
\ No newline at end of file
deploy:
image: gradle:6.5-jdk11
script:
- 'gradle publish'
only:
- "<%= package_project.default_branch %>"
tags:
- "runner-for-<%= package_project.group.name %>"
\ No newline at end of file
install:
image: maven:3.6-jdk-11
script:
- "mvn install -s settings.xml"
only:
- "<%= client_project.default_branch %>"
tags:
- "runner-for-<%= client_project.group.name %>"
\ No newline at end of file
deploy:
image: maven:3.6-jdk-11
script:
- 'mvn deploy -s settings.xml'
only:
- "<%= package_project.default_branch %>"
tags:
- "runner-for-<%= package_project.group.name %>"
\ No newline at end of file
<project>
<groupId><%= group_id %></groupId>
<artifactId><%= artifact_id %></artifactId>
<version><%= package_version %></version>
<modelVersion>4.0.0</modelVersion>
<repositories>
<repository>
<id><%= package_project.name %></id>
<url><%= gitlab_address_with_port %>/api/v4/groups/<%= package_project.group.id %>/-/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id><%= package_project.name %></id>
<url><%= gitlab_address_with_port %>/api/v4/projects/<%= package_project.id %>/packages/maven</url>
</repository>
<snapshotRepository>
<id><%= package_project.name %></id>
<url><%= gitlab_address_with_port %>/api/v4/projects/<%= package_project.id %>/packages/maven</url>
</snapshotRepository>
</distributionManagement>
</project>
\ No newline at end of file
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<servers>
<server>
<id><%= package_project.name %></id>
<configuration>
<httpHeaders>
<property>
<name><%= maven_header_name %></name>
<value><%= token %></value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
\ No newline at end of file
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<servers>
<server>
<id><%= package_project.name %></id>
<configuration>
<httpHeaders>
<property>
<name>Private-Token</name>
<value><%= personal_access_token %></value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
\ No newline at end of file
image: node:latest
stages:
- install
install:
stage: install
script:
- "npm config set @<%= registry_scope %>:registry <%= gitlab_address_with_port %>/api/v4/packages/npm/"
- "npm install <%= package.name %>"
cache:
key: ${CI_BUILD_REF_NAME}
paths:
- node_modules/
artifacts:
paths:
- node_modules/
only:
- "<%= another_project.default_branch %>"
tags:
- "runner-for-<%= another_project.group.name %>"
\ No newline at end of file
image: node:latest
stages:
- deploy
- install
deploy:
stage: deploy
script:
- echo "//${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=<%= auth_token %>">.npmrc
- npm publish
only:
- "<%= project.default_branch %>"
tags:
- "runner-for-<%= project.name %>"
install:
stage: install
script:
- "npm config set @<%= registry_scope %>:registry <%= gitlab_address_with_port %>/api/v4/projects/${CI_PROJECT_ID}/packages/npm/"
- "npm install <%= package.name %>"
cache:
key: ${CI_BUILD_REF_NAME}
paths:
- node_modules/
artifacts:
paths:
- node_modules/
only:
- "<%= project.default_branch %>"
tags:
- "runner-for-<%= project.name %>"
\ No newline at end of file
image: node:latest
stages:
- deploy
deploy:
stage: deploy
script:
- echo "//${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=<%= auth_token %>">.npmrc
- npm publish
only:
- "<%= project.default_branch %>"
tags:
- "runner-for-<%= project.group.name %>"
\ No newline at end of file
{
"name": "<%= package.name %>",
"version": "1.0.0",
"description": "Example package for GitLab npm registry",
"publishConfig": {
"@<%= registry_scope %>:registry": "<%= gitlab_address_with_port %>/api/v4/projects/<%= project.id %>/packages/npm/"
}
}
\ No newline at end of file
{
"name": "<%= package.name %>",
"version": "1.0.0",
"description": "Example package for GitLab npm registry",
"publishConfig": {
"@<%= registry_scope %>:registry": "<%= gitlab_address_with_port %>/api/v4/projects/<%= project.id %>/packages/npm/"
}
}
\ No newline at end of file
image: mcr.microsoft.com/dotnet/sdk:5.0
stages:
- install
install:
stage: install
script:
- dotnet nuget locals all --clear
- dotnet nuget add source "$CI_SERVER_URL/api/v4/groups/<%= another_project.group.id %>/-/packages/nuget/index.json" --name gitlab --username <%= auth_token_username %> --password <%= auth_token_password %> --store-password-in-clear-text
- "dotnet add otherdotnet.csproj package <%= package.name %> --version 1.0.0"
only:
- "<%= another_project.default_branch %>"
tags:
- "runner-for-<%= project.group.name %>"
\ No newline at end of file
image: mcr.microsoft.com/dotnet/sdk:5.0
stages:
- deploy
deploy:
stage: deploy
script:
- dotnet restore -p:Configuration=Release
- dotnet build -c Release
- dotnet pack -c Release -p:PackageID=<%= package.name %>
- dotnet nuget add source "$CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/packages/nuget/index.json" --name gitlab --username <%= auth_token_username %> --password <%= auth_token_password %> --store-password-in-clear-text
- dotnet nuget push "bin/Release/*.nupkg" --source gitlab
rules:
- if: '$CI_COMMIT_BRANCH == "<%= project.default_branch %>"'
tags:
- "runner-for-<%= project.group.name %>"
\ No newline at end of file
image: python:latest
stages:
- run
- install
run:
stage: run
script:
- pip install twine
- python setup.py sdist bdist_wheel
- "TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token python -m twine upload --repository-url <%= gitlab_address_with_port %>/api/v4/projects/${CI_PROJECT_ID}/packages/pypi dist/*"
tags:
- runner-for-<%= project.name %>
install:
stage: install
script:
- "pip install <%= package.name %> --no-deps --index-url <%= uri.scheme %>://<%= personal_access_token %>:<%= personal_access_token %>@<%= gitlab_host_with_port %>/api/v4/projects/${CI_PROJECT_ID}/packages/pypi/simple --trusted-host <%= gitlab_host_with_port %>"
tags:
- runner-for-<%= project.name %>
\ No newline at end of file
import setuptools
setuptools.setup(
name="<%= package.name %>",
version="0.0.1",
author="Example Author",
author_email="author@example.com",
description="A small example package",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
)
\ No newline at end of file
# frozen_string_literal: true
Gem::Specification.new do |s|
s.name = '<%= package.name %>'
s.authors = ['Tanuki Steve', 'Hal 9000']
s.author = 'Tanuki Steve'
s.version = '0.0.1'
s.date = '2011-09-29'
s.summary = 'this is a test package'
s.files = ['lib/hello_gem.rb']
s.require_paths = ['lib']
s.description = 'A test package for GitLab.'
s.email = 'tanuki@not_real.com'
s.homepage = 'https://gitlab.com/ruby-co/my-package'
s.license = 'MIT'
s.metadata = {
'bug_tracker_uri' => 'https://gitlab.com/ruby-co/my-package/issues',
'changelog_uri' => 'https://gitlab.com/ruby-co/my-package/CHANGELOG.md',
'documentation_uri' => 'https://gitlab.com/ruby-co/my-package/docs',
'mailing_list_uri' => 'https://gitlab.com/ruby-co/my-package/mailme',
'source_code_uri' => 'https://gitlab.com/ruby-co/my-package'
}
s.bindir = 'bin'
s.platform = Gem::Platform::RUBY
s.post_install_message = 'Installed, thank you!'
s.rdoc_options = ['--main']
s.required_ruby_version = '>= 2.7.0'
s.required_rubygems_version = '>= 1.8.11'
s.requirements = 'A high powered server or calculator'
s.rubygems_version = '1.8.09'
s.add_dependency 'dependency_1', '~> 1.2.3'
s.add_dependency 'dependency_2', '3.0.0'
s.add_dependency 'dependency_3', '>= 1.0.0'
s.add_dependency 'dependency_4'
end
\ No newline at end of file
image: ruby
test_package:
stage: deploy
before_script:
- mkdir ~/.gem
- echo "---" > ~/.gem/credentials
- |
echo "<%= gitlab_address_with_port %>/api/v4/projects/${CI_PROJECT_ID}/packages/rubygems: '${CI_JOB_TOKEN}'" >> ~/.gem/credentials
- chmod 0600 ~/.gem/credentials
script:
- gem build <%= package.name %>
- gem push <%= package.name %>-0.0.1.gem --host <%= gitlab_address_with_port %>/api/v4/projects/${CI_PROJECT_ID}/packages/rubygems
tags:
- runner-for-<%= project.name %>
\ No newline at end of file
......@@ -33,6 +33,14 @@ module QA
FileUtils.remove_entry(dir, true)
end
def read_fixture(fixture_path, file_name)
file_path = Pathname
.new(__dir__)
.join("../fixtures/#{fixture_path}/#{file_name}")
File.read(file_path)
end
private
def api_client
......
......@@ -32,55 +32,22 @@ module QA
"#{uri.scheme}://#{uri.host}:#{uri.port}"
end
let(:composer_json_file) do
<<~EOF
{
"name": "#{project.path_with_namespace}/#{package.name}",
"description": "Library XY",
"type": "library",
"license": "GPL-3.0-only",
"authors": [
{
"name": "John Doe",
"email": "john@example.com"
}
],
"require": {}
}
EOF
end
let(:gitlab_ci_yaml) do
<<~YAML
publish:
image: curlimages/curl:latest
stage: build
variables:
URL: "$CI_SERVER_PROTOCOL://$CI_SERVER_HOST:$CI_SERVER_PORT/api/v4/projects/$CI_PROJECT_ID/packages/composer?job_token=$CI_JOB_TOKEN"
script:
- version=$([[ -z "$CI_COMMIT_TAG" ]] && echo "branch=$CI_COMMIT_REF_NAME" || echo "tag=$CI_COMMIT_TAG")
- insecure=$([ "$CI_SERVER_PROTOCOL" = "http" ] && echo "--insecure" || echo "")
- response=$(curl -s -w "%{http_code}" $insecure --data $version $URL)
- code=$(echo "$response" | tail -n 1)
- body=$(echo "$response" | head -n 1)
tags:
- "runner-for-#{project.name}"
YAML
end
before do
Flow::Login.sign_in
Support::Retrier.retry_on_exception(max_attempts: 3, sleep_interval: 2) do
Resource::Repository::Commit.fabricate_via_api! do |commit|
composer_yaml = ERB.new(read_fixture('package_managers/composer', 'composer_upload_package.yaml.erb')).result(binding)
composer_json = ERB.new(read_fixture('package_managers/composer', 'composer.json.erb')).result(binding)
commit.project = project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.commit_message = 'Add files'
commit.add_files([{
file_path: '.gitlab-ci.yml',
content: gitlab_ci_yaml
content: composer_yaml
},
{
file_path: 'composer.json',
content: composer_json_file
content: composer_json
}]
)
end
......
......@@ -46,25 +46,13 @@ module QA
Support::Retrier.retry_on_exception(max_attempts: 3, sleep_interval: 2) do
Resource::Repository::Commit.fabricate_via_api! do |commit|
conan_yaml = ERB.new(read_fixture('package_managers/conan', 'conan_upload_install_package.yaml.erb')).result(binding)
commit.project = project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files([{
file_path: '.gitlab-ci.yml',
content:
<<~YAML
image: conanio/gcc7
test_package:
stage: deploy
script:
- "conan remote add gitlab #{gitlab_address_with_port}/api/v4/projects/#{project.id}/packages/conan"
- "conan new #{package.name}/0.1 -t"
- "conan create . mycompany/stable"
- "CONAN_LOGIN_USERNAME=ci_user CONAN_PASSWORD=${CI_JOB_TOKEN} conan upload #{package.name}/0.1@mycompany/stable --all --remote=gitlab"
- "conan install #{package.name}/0.1@mycompany/stable --remote=gitlab"
tags:
- "runner-for-#{project.name}"
YAML
content: conan_yaml
}])
end
end
......
......@@ -3,6 +3,8 @@
module QA
RSpec.describe 'Package', :orchestrated, :packages, :object_storage do
describe 'Generic Repository' do
include Runtime::Fixtures
let(:project) do
Resource::Project.fabricate_via_api! do |project|
project.name = 'generic-package-project'
......@@ -25,29 +27,6 @@ module QA
end
end
let(:gitlab_ci_yaml) do
<<~YAML
image: curlimages/curl:latest
stages:
- upload
- download
upload:
stage: upload
script:
- 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file file.txt ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/#{package.name}/0.0.1/file.txt'
tags:
- "runner-for-#{project.name}"
download:
stage: download
script:
- 'wget --header="JOB-TOKEN: $CI_JOB_TOKEN" ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/#{package.name}/0.0.1/file.txt -O file_downloaded.txt'
tags:
- "runner-for-#{project.name}"
YAML
end
let(:file_txt) do
<<~EOF
Hello, world!
......@@ -59,11 +38,13 @@ module QA
Support::Retrier.retry_on_exception(max_attempts: 3, sleep_interval: 2) do
Resource::Repository::Commit.fabricate_via_api! do |commit|
generic_packages_yaml = ERB.new(read_fixture('package_managers/generic', 'generic_upload_install_package.yaml.erb')).result(binding)
commit.project = project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.commit_message = 'Add files'
commit.add_files([{
file_path: '.gitlab-ci.yml',
content: gitlab_ci_yaml
content: generic_packages_yaml
},
{
file_path: 'file.txt',
......
......@@ -10,64 +10,6 @@ module QA
let(:package_version) { '1.3.7' }
let(:package_type) { 'helm' }
let(:package_gitlab_ci_file) do
{
file_path: '.gitlab-ci.yml',
content:
<<~YAML
deploy:
image: alpine:3
script:
- apk add helm --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing
- apk add curl
- helm create #{package_name}
- cp ./Chart.yaml #{package_name}
- helm package #{package_name}
- http_code=$(curl --write-out "%{http_code}" --request POST --form 'chart=@#{package_name}-#{package_version}.tgz' --user #{username}:#{access_token} ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/helm/api/stable/charts --output /dev/null --silent)
- '[ $http_code = "201" ]'
only:
- "#{package_project.default_branch}"
tags:
- "runner-for-#{package_project.group.name}"
YAML
}
end
let(:package_chart_yaml_file) do
{
file_path: "Chart.yaml",
content:
<<~EOF
apiVersion: v2
name: #{package_name}
description: GitLab QA helm package
type: application
version: #{package_version}
appVersion: "1.16.0"
EOF
}
end
let(:client_gitlab_ci_file) do
{
file_path: '.gitlab-ci.yml',
content:
<<~YAML
pull:
image: alpine:3
script:
- apk add helm --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing
- helm repo add --username #{username} --password #{access_token} gitlab_qa ${CI_API_V4_URL}/projects/#{package_project.id}/packages/helm/stable
- helm repo update
- helm pull gitlab_qa/#{package_name}
only:
- "#{client_project.default_branch}"
tags:
- "runner-for-#{client_project.group.name}"
YAML
}
end
%i[personal_access_token ci_job_token project_deploy_token].each do |authentication_token_type|
context "using a #{authentication_token_type}" do
let(:username) do
......@@ -95,9 +37,21 @@ module QA
it "pushes and pulls a helm chart" do
Support::Retrier.retry_on_exception(max_attempts: 3, sleep_interval: 2) do
Resource::Repository::Commit.fabricate_via_api! do |commit|
helm_upload_yaml = ERB.new(read_fixture('package_managers/helm', 'helm_upload_package.yaml.erb')).result(binding)
helm_chart_yaml = ERB.new(read_fixture('package_managers/helm', 'Chart.yaml.erb')).result(binding)
commit.project = package_project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files([package_gitlab_ci_file, package_chart_yaml_file])
commit.add_files([
{
file_path: '.gitlab-ci.yml',
content: helm_upload_yaml
},
{
file_path: 'Chart.yaml',
content: helm_chart_yaml
}
])
end
end
......@@ -127,9 +81,16 @@ module QA
Support::Retrier.retry_on_exception(max_attempts: 3, sleep_interval: 2) do
Resource::Repository::Commit.fabricate_via_api! do |commit|
helm_install_yaml = ERB.new(read_fixture('package_managers/helm', 'helm_install_package.yaml.erb')).result(binding)
commit.project = client_project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files([client_gitlab_ci_file])
commit.add_files([
{
file_path: '.gitlab-ci.yml',
content: helm_install_yaml
}
])
end
end
......
......@@ -13,76 +13,6 @@ module QA
let(:package_version) { '1.3.7' }
let(:package_type) { 'maven_gradle' }
let(:package_gitlab_ci_file) do
{
file_path: '.gitlab-ci.yml',
content:
<<~YAML
deploy:
image: gradle:6.5-jdk11
script:
- 'gradle publish'
only:
- "#{package_project.default_branch}"
tags:
- "runner-for-#{package_project.group.name}"
YAML
}
end
let(:package_build_gradle_file) do
{
file_path: 'build.gradle',
content:
<<~EOF
plugins {
id 'java'
id 'maven-publish'
}
publishing {
publications {
library(MavenPublication) {
groupId '#{group_id}'
artifactId '#{artifact_id}'
version '#{package_version}'
from components.java
}
}
repositories {
maven {
url "#{gitlab_address_with_port}/api/v4/projects/#{package_project.id}/packages/maven"
credentials(HttpHeaderCredentials) {
name = "Private-Token"
value = "#{personal_access_token}"
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
}
EOF
}
end
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
where(:authentication_token_type, :maven_header_name) do
:personal_access_token | 'Private-Token'
:ci_job_token | 'Job-Token'
......@@ -101,49 +31,24 @@ module QA
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]}" do
Support::Retrier.retry_on_exception(max_attempts: 3, sleep_interval: 2) do
Resource::Repository::Commit.fabricate_via_api! do |commit|
gradle_upload_yaml = ERB.new(read_fixture('package_managers/maven', 'gradle_upload_package.yaml.erb')).result(binding)
build_upload_gradle = ERB.new(read_fixture('package_managers/maven', 'build_upload.gradle.erb')).result(binding)
commit.project = package_project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files([package_gitlab_ci_file, package_build_gradle_file])
commit.add_files([
{
file_path: '.gitlab-ci.yml',
content: gradle_upload_yaml
},
{
file_path: 'build.gradle',
content: build_upload_gradle
}
])
end
end
......@@ -173,9 +78,21 @@ module QA
Support::Retrier.retry_on_exception(max_attempts: 3, sleep_interval: 2) do
Resource::Repository::Commit.fabricate_via_api! do |commit|
gradle_install_yaml = ERB.new(read_fixture('package_managers/maven', 'gradle_install_package.yaml.erb')).result(binding)
build_install_gradle = ERB.new(read_fixture('package_managers/maven', 'build_install.gradle.erb')).result(binding)
commit.project = client_project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files([client_gitlab_ci_file, client_build_gradle_file])
commit.commit_message = 'Add files'
commit.add_files([
{
file_path: '.gitlab-ci.yml',
content: gradle_install_yaml
},
{
file_path: 'build.gradle',
content: build_install_gradle
}
])
end
end
......
......@@ -54,75 +54,6 @@ module QA
end
end
let(:gitlab_ci_deploy_yaml) do
{
file_path: '.gitlab-ci.yml',
content:
<<~YAML
image: node:latest
stages:
- deploy
deploy:
stage: deploy
script:
- echo "//${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=#{auth_token}">.npmrc
- npm publish
only:
- "#{project.default_branch}"
tags:
- "runner-for-#{project.group.name}"
YAML
}
end
let(:gitlab_ci_install_yaml) do
{
file_path: '.gitlab-ci.yml',
content:
<<~YAML
image: node:latest
stages:
- install
install:
stage: install
script:
- "npm config set @#{registry_scope}:registry #{gitlab_address_with_port}/api/v4/packages/npm/"
- "npm install #{package.name}"
cache:
key: ${CI_BUILD_REF_NAME}
paths:
- node_modules/
artifacts:
paths:
- node_modules/
only:
- "#{another_project.default_branch}"
tags:
- "runner-for-#{another_project.group.name}"
YAML
}
end
let(:package_json) do
{
file_path: 'package.json',
content: <<~JSON
{
"name": "#{package.name}",
"version": "1.0.0",
"description": "Example package for GitLab npm registry",
"publishConfig": {
"@#{registry_scope}:registry": "#{gitlab_address_with_port}/api/v4/projects/#{project.id}/packages/npm/"
}
}
JSON
}
end
let(:package) do
Resource::Package.init do |package|
package.name = "@#{registry_scope}/#{project.name}-#{SecureRandom.hex(8)}"
......@@ -157,12 +88,21 @@ module QA
it "push and pull a npm package via CI using a #{params[:token_name]}" do
Support::Retrier.retry_on_exception(max_attempts: 3, sleep_interval: 2) do
npm_upload_yaml = ERB.new(read_fixture('package_managers/npm', 'npm_upload_package_instance.yaml.erb')).result(binding)
package_json = ERB.new(read_fixture('package_managers/npm', 'package_instance.json.erb')).result(binding)
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.commit_message = 'Add files'
commit.add_files([
gitlab_ci_deploy_yaml,
package_json
{
file_path: '.gitlab-ci.yml',
content: npm_upload_yaml
},
{
file_path: 'package.json',
content: package_json
}
])
end
end
......@@ -180,10 +120,15 @@ module QA
Support::Retrier.retry_on_exception(max_attempts: 3, sleep_interval: 2) do
Resource::Repository::Commit.fabricate_via_api! do |commit|
npm_install_yaml = ERB.new(read_fixture('package_managers/npm', 'npm_install_package_instance.yaml.erb')).result(binding)
commit.project = another_project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files([
gitlab_ci_install_yaml
{
file_path: '.gitlab-ci.yml',
content: npm_install_yaml
}
])
end
end
......
......@@ -46,62 +46,6 @@ module QA
end
end
let(:gitlab_ci_yaml) do
{
file_path: '.gitlab-ci.yml',
content:
<<~YAML
image: node:latest
stages:
- deploy
- install
deploy:
stage: deploy
script:
- echo "//${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=#{auth_token}">.npmrc
- npm publish
only:
- "#{project.default_branch}"
tags:
- "runner-for-#{project.name}"
install:
stage: install
script:
- "npm config set @#{registry_scope}:registry #{gitlab_address_with_port}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/"
- "npm install #{package.name}"
cache:
key: ${CI_BUILD_REF_NAME}
paths:
- node_modules/
artifacts:
paths:
- node_modules/
only:
- "#{project.default_branch}"
tags:
- "runner-for-#{project.name}"
YAML
}
end
let(:package_json) do
{
file_path: 'package.json',
content: <<~JSON
{
"name": "#{package.name}",
"version": "1.0.0",
"description": "Example package for GitLab npm registry",
"publishConfig": {
"@#{registry_scope}:registry": "#{gitlab_address_with_port}/api/v4/projects/#{project.id}/packages/npm/"
}
}
JSON
}
end
let(:package) do
Resource::Package.init do |package|
package.name = "@#{registry_scope}/mypackage-#{SecureRandom.hex(8)}"
......@@ -135,11 +79,20 @@ module QA
it "push and pull a npm package via CI using a #{params[:token_name]}" do
Resource::Repository::Commit.fabricate_via_api! do |commit|
npm_upload_install_yaml = ERB.new(read_fixture('package_managers/npm', 'npm_upload_install_package_project.yaml.erb')).result(binding)
package_json = ERB.new(read_fixture('package_managers/npm', 'package_project.json.erb')).result(binding)
commit.project = project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files([
gitlab_ci_yaml,
package_json
{
file_path: '.gitlab-ci.yml',
content: npm_upload_install_yaml
},
{
file_path: 'package.json',
content: package_json
}
])
end
......
......@@ -5,6 +5,7 @@ module QA
describe 'NuGet Repository' do
using RSpec::Parameterized::TableSyntax
include Runtime::Fixtures
let(:project) do
Resource::Project.fabricate_via_api! do |project|
project.name = 'nuget-package-project'
......@@ -96,31 +97,14 @@ module QA
Support::Retrier.retry_on_exception(max_attempts: 3, sleep_interval: 2) do
Resource::Repository::Commit.fabricate_via_api! do |commit|
nuget_upload_yaml = ERB.new(read_fixture('package_managers/nuget', 'nuget_upload_package.yaml.erb')).result(binding)
commit.project = project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.update_files(
[
{
file_path: '.gitlab-ci.yml',
content: <<~YAML
image: mcr.microsoft.com/dotnet/sdk:5.0
stages:
- deploy
deploy:
stage: deploy
script:
- dotnet restore -p:Configuration=Release
- dotnet build -c Release
- dotnet pack -c Release -p:PackageID=#{package.name}
- dotnet nuget add source "$CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/packages/nuget/index.json" --name gitlab --username #{auth_token_username} --password #{auth_token_password} --store-password-in-clear-text
- dotnet nuget push "bin/Release/*.nupkg" --source gitlab
rules:
- if: '$CI_COMMIT_BRANCH == "#{project.default_branch}"'
tags:
- "runner-for-#{project.group.name}"
YAML
content: nuget_upload_yaml
}
]
)
......@@ -142,6 +126,8 @@ module QA
Support::Retrier.retry_on_exception(max_attempts: 3, sleep_interval: 2) do
Resource::Repository::Commit.fabricate_via_api! do |commit|
nuget_install_yaml = ERB.new(read_fixture('package_managers/nuget', 'nuget_install_package.yaml.erb')).result(binding)
commit.project = another_project
commit.commit_message = 'Add new csproj file'
commit.add_files(
......@@ -165,23 +151,7 @@ module QA
[
{
file_path: '.gitlab-ci.yml',
content: <<~YAML
image: mcr.microsoft.com/dotnet/sdk:5.0
stages:
- install
install:
stage: install
script:
- dotnet nuget locals all --clear
- dotnet nuget add source "$CI_SERVER_URL/api/v4/groups/#{another_project.group.id}/-/packages/nuget/index.json" --name gitlab --username #{auth_token_username} --password #{auth_token_password} --store-password-in-clear-text
- "dotnet add otherdotnet.csproj package #{package.name} --version 1.0.0"
only:
- "#{another_project.default_branch}"
tags:
- "runner-for-#{project.group.name}"
YAML
content: nuget_install_yaml
}
]
)
......
......@@ -4,6 +4,7 @@ module QA
RSpec.describe 'Package', :orchestrated, :packages, :object_storage do
describe 'PyPI Repository' do
include Runtime::Fixtures
let(:project) do
Resource::Project.fabricate_via_api! do |project|
project.name = 'pypi-package-project'
......@@ -36,56 +37,18 @@ module QA
Support::Retrier.retry_on_exception(max_attempts: 3, sleep_interval: 2) do
Resource::Repository::Commit.fabricate_via_api! do |commit|
pypi_yaml = ERB.new(read_fixture('package_managers/pypi', 'pypi_upload_install_package.yaml.erb')).result(binding)
pypi_setup_file = ERB.new(read_fixture('package_managers/pypi', 'setup.py.erb')).result(binding)
commit.project = project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.commit_message = 'Add files'
commit.add_files([{
file_path: '.gitlab-ci.yml',
content:
<<~YAML
image: python:latest
stages:
- run
- install
run:
stage: run
script:
- pip install twine
- python setup.py sdist bdist_wheel
- "TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token python -m twine upload --repository-url #{gitlab_address_with_port}/api/v4/projects/${CI_PROJECT_ID}/packages/pypi dist/*"
tags:
- "runner-for-#{project.name}"
install:
stage: install
script:
- "pip install #{package.name} --no-deps --index-url #{uri.scheme}://#{personal_access_token}:#{personal_access_token}@#{gitlab_host_with_port}/api/v4/projects/${CI_PROJECT_ID}/packages/pypi/simple --trusted-host #{gitlab_host_with_port}"
tags:
- "runner-for-#{project.name}"
YAML
content: pypi_yaml
},
{
file_path: 'setup.py',
content:
<<~EOF
import setuptools
setuptools.setup(
name="#{package.name}",
version="0.0.1",
author="Example Author",
author_email="author@example.com",
description="A small example package",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
)
EOF
content: pypi_setup_file
}])
end
end
......
......@@ -48,30 +48,16 @@ module QA
Support::Retrier.retry_on_exception(max_attempts: 3, sleep_interval: 2) do
Resource::Repository::Commit.fabricate_via_api! do |commit|
rubygem_upload_yaml = ERB.new(read_fixture('package_managers/rubygems', 'rubygems_upload_package.yaml.erb')).result(binding)
rubygem_package_gemspec = ERB.new(read_fixture('package_managers/rubygems', 'package.gemspec.erb')).result(binding)
commit.project = project
commit.commit_message = 'Add package files'
commit.add_files(
[
{
file_path: '.gitlab-ci.yml',
content:
<<~YAML
image: ruby
test_package:
stage: deploy
before_script:
- mkdir ~/.gem
- echo "---" > ~/.gem/credentials
- |
echo "#{gitlab_address_with_port}/api/v4/projects/${CI_PROJECT_ID}/packages/rubygems: '${CI_JOB_TOKEN}'" >> ~/.gem/credentials
- chmod 0600 ~/.gem/credentials
script:
- gem build #{package.name}
- gem push #{package.name}-0.0.1.gem --host #{gitlab_address_with_port}/api/v4/projects/${CI_PROJECT_ID}/packages/rubygems
tags:
- "runner-for-#{project.name}"
YAML
content: rubygem_upload_yaml
},
{
file_path: 'lib/hello_gem.rb',
......@@ -86,49 +72,7 @@ module QA
},
{
file_path: "#{package.name}.gemspec",
content:
<<~RUBY
# frozen_string_literal: true
Gem::Specification.new do |s|
s.name = '#{package.name}'
s.authors = ['Tanuki Steve', 'Hal 9000']
s.author = 'Tanuki Steve'
s.version = '0.0.1'
s.date = '2011-09-29'
s.summary = 'this is a test package'
s.files = ['lib/hello_gem.rb']
s.require_paths = ['lib']
s.description = 'A test package for GitLab.'
s.email = 'tanuki@not_real.com'
s.homepage = 'https://gitlab.com/ruby-co/my-package'
s.license = 'MIT'
s.metadata = {
'bug_tracker_uri' => 'https://gitlab.com/ruby-co/my-package/issues',
'changelog_uri' => 'https://gitlab.com/ruby-co/my-package/CHANGELOG.md',
'documentation_uri' => 'https://gitlab.com/ruby-co/my-package/docs',
'mailing_list_uri' => 'https://gitlab.com/ruby-co/my-package/mailme',
'source_code_uri' => 'https://gitlab.com/ruby-co/my-package'
}
s.bindir = 'bin'
s.platform = Gem::Platform::RUBY
s.post_install_message = 'Installed, thank you!'
s.rdoc_options = ['--main']
s.required_ruby_version = '>= 2.7.0'
s.required_rubygems_version = '>= 1.8.11'
s.requirements = 'A high powered server or calculator'
s.rubygems_version = '1.8.09'
s.add_dependency 'dependency_1', '~> 1.2.3'
s.add_dependency 'dependency_2', '3.0.0'
s.add_dependency 'dependency_3', '>= 1.0.0'
s.add_dependency 'dependency_4'
end
RUBY
content: rubygem_package_gemspec
}
]
)
......
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