pdksync 0.5.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/pull_request_template.md +15 -0
- data/.github/workflows/ci.yml +23 -0
- data/.github/workflows/labeller.yml +22 -0
- data/.github/workflows/mend.yml +15 -0
- data/.github/workflows/nightly.yml +22 -0
- data/.github/workflows/release.yml +16 -0
- data/.github/workflows/release_prep.yml +20 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +35 -46
- data/CHANGELOG.md +69 -44
- data/CODEOWNERS +2 -0
- data/Gemfile +10 -3
- data/README.md +330 -18
- data/Rakefile +8 -29
- data/lib/pdksync/conf/puppet_abs_supported_platforms.yaml +41 -0
- data/lib/pdksync/configuration.rb +155 -0
- data/lib/pdksync/githubclient.rb +3 -1
- data/lib/pdksync/gitplatformclient.rb +2 -2
- data/lib/pdksync/jenkinsclient.rb +50 -0
- data/lib/pdksync/logger.rb +120 -0
- data/lib/pdksync/rake_tasks.rb +100 -16
- data/lib/pdksync/utils.rb +1296 -0
- data/lib/pdksync/version.rb +3 -0
- data/lib/pdksync.rb +310 -450
- data/managed_modules.yml +16 -33
- data/pdksync.gemspec +20 -17
- data/spec/configuration_spec.rb +56 -0
- data/spec/fixtures/fake_managed_modules.yaml +2 -0
- data/spec/fixtures/pdksync.yml +2 -0
- data/spec/logger_spec.rb +44 -0
- data/spec/pdksync_spec.rb +185 -0
- data/spec/spec_helper.rb +74 -0
- data/spec/utils_spec.rb +134 -0
- metadata +88 -22
- data/.travis.yml +0 -27
- data/lib/pdksync/constants.rb +0 -78
- data/spec/lib/pdksync_spec.rb +0 -58
data/lib/pdksync/githubclient.rb
CHANGED
@@ -10,7 +10,9 @@ class PdkSync::GithubClient
|
|
10
10
|
# supplied access token
|
11
11
|
# @param access_token
|
12
12
|
# The Github access token, required to access the Github API
|
13
|
-
def initialize(access_token)
|
13
|
+
def initialize(access_token, api_endpoint = nil)
|
14
|
+
# USE ENV['OCTOKIT_API_ENDPOINT'] or pass in the api_endpoint
|
15
|
+
Octokit.configure { |c| c.api_endpoint = api_endpoint } unless api_endpoint.nil?
|
14
16
|
@client = Octokit::Client.new(access_token: access_token.to_s)
|
15
17
|
@client.user.login
|
16
18
|
end
|
@@ -26,11 +26,11 @@ class PdkSync::GitPlatformClient
|
|
26
26
|
when :github
|
27
27
|
require 'pdksync/githubclient'
|
28
28
|
|
29
|
-
PdkSync::GithubClient.new(access_token)
|
29
|
+
PdkSync::GithubClient.new(access_token, git_platform_access_settings[:api_endpoint])
|
30
30
|
when :gitlab
|
31
31
|
require 'pdksync/gitlabclient'
|
32
32
|
|
33
|
-
gitlab_api_endpoint = git_platform_access_settings[:gitlab_api_endpoint]
|
33
|
+
gitlab_api_endpoint = git_platform_access_settings[:gitlab_api_endpoint] || git_platform_access_settings[:api_endpoint]
|
34
34
|
PdkSync::GitlabClient.new(access_token, gitlab_api_endpoint)
|
35
35
|
end
|
36
36
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'jenkins_api_client'
|
2
|
+
|
3
|
+
# @summary
|
4
|
+
# This class wraps Gitlab::JenkinsCLient and provides the method implementations
|
5
|
+
# required by pdksync main to access the Jenkins API for creating jobs in jenkins
|
6
|
+
class PdkSync::JenkinsClient
|
7
|
+
# @summary
|
8
|
+
# Creates a new Jenkins::Client and logs in the user based on the
|
9
|
+
# supplied user credentials and the Jenkins API endpoint URL
|
10
|
+
# @param [String] jenkins_platform_access_settings
|
11
|
+
# The Jenkins credentials, required to access the Jenkins API
|
12
|
+
|
13
|
+
def initialize(jenkins_server_url, jenkins_platform_access_settings)
|
14
|
+
jenkins_username = jenkins_platform_access_settings[:jenkins_username]
|
15
|
+
jenkins_password = jenkins_platform_access_settings[:jenkins_password]
|
16
|
+
@client = JenkinsApi::Client.new('server_url' => jenkins_server_url,
|
17
|
+
'username' => jenkins_username,
|
18
|
+
'password' => jenkins_password)
|
19
|
+
end
|
20
|
+
|
21
|
+
# @summary
|
22
|
+
# Creates a new adhoc job against the jenkins
|
23
|
+
# platform
|
24
|
+
# @param [String] github_repo
|
25
|
+
# Repo or Module for which the adhoc job to be created
|
26
|
+
# @param [String] github_branch
|
27
|
+
# The target branch against which to create the adhoc job
|
28
|
+
# @return
|
29
|
+
# Build Id returned by the job
|
30
|
+
def create_adhoc_job(github_repo, github_branch, github_user, job_name)
|
31
|
+
# params to start the build
|
32
|
+
job_params = { 'GITHUB_USER' => github_user,
|
33
|
+
'GITHUB_REPO' => github_repo,
|
34
|
+
'GITHUB_REF' => github_branch }
|
35
|
+
# job name
|
36
|
+
# Wait for up to 30 seconds, attempt to cancel queued build
|
37
|
+
opts = { 'build_start_timeout' => 30,
|
38
|
+
'cancel_on_build_start_timeout' => true,
|
39
|
+
'completion_proc' => lambda { |build_number, cancelled| # rubocop:disable Style/Lambda
|
40
|
+
if build_number
|
41
|
+
PdkSync::Logger.info "Wait over: build #{build_number} started"
|
42
|
+
else
|
43
|
+
PdkSync::Logger.info "Wait over: build not started, build #{cancelled ? '' : 'NOT '} cancelled"
|
44
|
+
end
|
45
|
+
} }
|
46
|
+
|
47
|
+
build_id = @client.job.build(job_name, job_params || {}, opts)
|
48
|
+
build_id
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
class String
|
6
|
+
def colorize(color_code)
|
7
|
+
"\e[#{color_code}m#{self}\e[0m"
|
8
|
+
end
|
9
|
+
|
10
|
+
def bold
|
11
|
+
"\e[1m#{self}\e[22m"
|
12
|
+
end
|
13
|
+
|
14
|
+
def red
|
15
|
+
colorize(31)
|
16
|
+
end
|
17
|
+
|
18
|
+
def green
|
19
|
+
colorize(32)
|
20
|
+
end
|
21
|
+
|
22
|
+
def fatal
|
23
|
+
red
|
24
|
+
end
|
25
|
+
|
26
|
+
def yellow
|
27
|
+
colorize(33)
|
28
|
+
end
|
29
|
+
|
30
|
+
def light_blue
|
31
|
+
colorize(36)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module PdkSync
|
36
|
+
class Logger
|
37
|
+
def self.warn(message)
|
38
|
+
logger.warn(message)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.info(message)
|
42
|
+
logger.info(message)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.debug(message)
|
46
|
+
logger.debug(message)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.fatal(message)
|
50
|
+
logger.fatal(message)
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.error(message)
|
54
|
+
logger.error(message)
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.log_file
|
58
|
+
if ENV['PDKSYNC_LOG_FILENAME'] && File.exist?(ENV['PDKSYNC_LOG_FILENAME'])
|
59
|
+
ENV['PDKSYNC_LOG_FILENAME']
|
60
|
+
else
|
61
|
+
STDOUT
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.logger(file = PdkSync::Logger.log_file)
|
66
|
+
@logger ||= begin
|
67
|
+
log = ::Logger.new(file)
|
68
|
+
log.level = log_level
|
69
|
+
log.progname = 'PdkSync'
|
70
|
+
log.formatter = proc do |severity, datetime, progname, msg|
|
71
|
+
if PdkSync::Logger.log_file == STDOUT
|
72
|
+
"#{severity} - #{progname}: #{msg}\n".send(color(severity))
|
73
|
+
else
|
74
|
+
"#{datetime} #{severity} - #{progname}: #{msg}\n".send(color(severity))
|
75
|
+
end
|
76
|
+
end
|
77
|
+
log
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def logger
|
82
|
+
@logger ||= PdkSync::Logger.logger
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.color(severity)
|
86
|
+
case severity
|
87
|
+
when ::Logger::Severity::WARN, 'WARN'
|
88
|
+
:yellow
|
89
|
+
when ::Logger::Severity::INFO, 'INFO'
|
90
|
+
:green
|
91
|
+
when ::Logger::Severity::FATAL, 'FATAL'
|
92
|
+
:fatal
|
93
|
+
when ::Logger::Severity::ERROR, 'ERROR'
|
94
|
+
:fatal
|
95
|
+
when ::Logger::Severity::DEBUG, 'DEBUG'
|
96
|
+
:light_blue
|
97
|
+
else
|
98
|
+
:green
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.log_level
|
103
|
+
level = ENV['LOG_LEVEL'].downcase if ENV['LOG_LEVEL']
|
104
|
+
case level
|
105
|
+
when 'warn'
|
106
|
+
::Logger::Severity::WARN
|
107
|
+
when 'fatal'
|
108
|
+
::Logger::Severity::FATAL
|
109
|
+
when 'debug'
|
110
|
+
::Logger::Severity::DEBUG
|
111
|
+
when 'info'
|
112
|
+
::Logger::Severity::INFO
|
113
|
+
when 'error'
|
114
|
+
::Logger::Severity::ERROR
|
115
|
+
else
|
116
|
+
::Logger::Severity::INFO
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
data/lib/pdksync/rake_tasks.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'pdksync'
|
2
|
-
require '
|
2
|
+
require 'logger'
|
3
3
|
|
4
4
|
desc 'Run full pdksync process, clone repository, pdk update, create pr. Additional title information can be added to the title, which will be appended before the reference section.'
|
5
5
|
task :pdksync, [:additional_title] do |_task, args|
|
@@ -10,6 +10,23 @@ task :pdksync, [:additional_title] do |_task, args|
|
|
10
10
|
PdkSync.main(steps: [:use_pdk_ref, :clone, :pdk_update, :create_commit, :push, :create_pr], args: args)
|
11
11
|
end
|
12
12
|
|
13
|
+
desc 'Run full gem_testing process, clone repository, gemfile update, create pr. Additional title information can be added to the title, which will be appended before the reference section.'
|
14
|
+
task :gem_testing, [:additional_title, :gem_to_test, :gem_line, :gem_sha_finder, :gem_sha_replacer, :gem_version_finder, :gem_version_replacer, :gem_branch_finder, :gem_branch_replacer] do |_task, args| # rubocop:disable Metrics/LineLength
|
15
|
+
args = { branch_name: 'pdksync_gem_testing{ref}',
|
16
|
+
commit_message: 'pdksync_gem_testing{ref}',
|
17
|
+
pr_title: 'pdksync_gem_testing{ref}',
|
18
|
+
additional_title: args[:additional_title],
|
19
|
+
gem_to_test: args[:gem_to_test],
|
20
|
+
gem_line: args[:gem_line],
|
21
|
+
gem_sha_finder: args[:gem_sha_finder],
|
22
|
+
gem_sha_replacer: args[:gem_sha_replacer],
|
23
|
+
gem_version_finder: args[:gem_version_finder],
|
24
|
+
gem_version_replacer: args[:gem_version_replacer],
|
25
|
+
gem_branch_finder: args[:gem_branch_finder],
|
26
|
+
gem_branch_replacer: args[:gem_branch_replacer] }
|
27
|
+
PdkSync.main(steps: [:use_gem_ref, :clone, :gem_file_update, :create_commit, :push, :create_pr], args: args)
|
28
|
+
end
|
29
|
+
|
13
30
|
namespace :pdksync do
|
14
31
|
desc 'Runs PDK convert against modules'
|
15
32
|
task :pdk_convert do
|
@@ -21,27 +38,89 @@ namespace :pdksync do
|
|
21
38
|
PdkSync.main(steps: [:pdk_validate])
|
22
39
|
end
|
23
40
|
|
24
|
-
desc "Run a command against modules eg rake 'run_a_command[complex command here -f -gx]'"
|
25
|
-
task :run_a_command, [:command] do |_task, args|
|
26
|
-
PdkSync.main(steps: [:run_a_command], args: args
|
41
|
+
desc "Run a command against modules eg rake 'run_a_command[complex command here -f -gx, 'background']'"
|
42
|
+
task :run_a_command, [:command, :option] do |_task, args|
|
43
|
+
PdkSync.main(steps: [:run_a_command], args: args)
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "Gem File Update'gem_file_update[gem_to_test, gem_line, gem_sha_finder, gem_sha_replacer, gem_version_finder, gem_version_replacer, gem_branch_finder, gem_branch_replacer]'"
|
47
|
+
task :gem_file_update, [:gem_to_test, :gem_line, :gem_sha_finder, :gem_sha_replacer, :gem_version_finder, :gem_version_replacer, :gem_branch_finder, :gem_branch_replacer] do |_task, args|
|
48
|
+
PdkSync.main(steps: [:gem_file_update], args: args)
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "Run test against modules eg rake 'run_tests_locally[litmus, 'provision_type']'"
|
52
|
+
task :run_tests_locally, [:provision_type, :puppet_collection] do |_task, args|
|
53
|
+
PdkSync.main(steps: [:run_tests_locally], args: args)
|
54
|
+
end
|
55
|
+
|
56
|
+
desc "Fetch run results against modules eg rake 'fetch_test_results_locally[litmus]'"
|
57
|
+
task :fetch_test_results_locally do
|
58
|
+
PdkSync.main(steps: [:fetch_test_results_locally])
|
59
|
+
end
|
60
|
+
|
61
|
+
desc "Run test in jenkins for traditional modules eg rake 'run_tests_jenkins['jenkins_server_url', 'branchname']'"
|
62
|
+
task :run_tests_jenkins, [:jenkins_server_url, :github_branch, :test_framework, :github_user] do |_task, args|
|
63
|
+
PdkSync.main(steps: [:run_tests_jenkins], args: args)
|
64
|
+
end
|
65
|
+
|
66
|
+
desc 'Multi Gem Testing, multi_gem_testing[gem_name, version_file, build_gem, gem_path, gemfury_username]'
|
67
|
+
task :multi_gem_testing, [:gem_name, :version_file, :build_gem, :gem_path, :gemfury_username] do |_task, args|
|
68
|
+
PdkSync.main(steps: [:multi_gem_testing], args: args)
|
69
|
+
end
|
70
|
+
|
71
|
+
desc 'Multi Gem File Update, multigem_file_update[gem_name, gemfury_username]'
|
72
|
+
task :multigem_file_update, [:gem_name, :gemfury_username] do |_task, args|
|
73
|
+
PdkSync.main(steps: [:multigem_file_update], args: args)
|
27
74
|
end
|
28
75
|
|
29
76
|
desc 'Display the current configuration of pdksync'
|
30
77
|
task :show_config do
|
31
|
-
|
78
|
+
config = PdkSync::Configuration.new
|
32
79
|
puts 'Please note that you can override any of the configuration by using an additional file at `$HOME/.pdksync.yml`.'.bold.red
|
33
|
-
puts
|
34
|
-
|
35
|
-
|
36
|
-
if PdkSync::Constants::GIT_PLATFORM == :gitlab
|
37
|
-
puts '- Gitlab API endpoint: '.bold + PdkSync::Constants::GITLAB_API_ENDPOINT.to_s.cyan
|
80
|
+
puts "\nPDKSync Configuration:".bold.yellow
|
81
|
+
config.to_h.each do |key, value|
|
82
|
+
puts "- #{key}: " + value.to_s.light_blue
|
38
83
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
84
|
+
end
|
85
|
+
|
86
|
+
desc "Fetch run results against traditional modules eg rake 'fetch_traditional_test_results'"
|
87
|
+
task :test_results_jenkins, [:jenkins_server_url] do |_task, args|
|
88
|
+
PdkSync.main(steps: [:test_results_jenkins], args: args)
|
89
|
+
end
|
90
|
+
|
91
|
+
desc 'Add a provision list key to provision.yaml'
|
92
|
+
task :add_provision_list, [:key, :provisioner, :images] do |_task, args|
|
93
|
+
PdkSync.main(steps: [:add_provision_list], args: args)
|
94
|
+
end
|
95
|
+
|
96
|
+
desc 'Generates release checks in provision.yaml based on module compatible platforms and puppet version'
|
97
|
+
task :generate_vmpooler_release_checks, [:puppet_version] do |_task, args|
|
98
|
+
PdkSync.main(steps: [:generate_vmpooler_release_checks], args: args)
|
99
|
+
end
|
100
|
+
|
101
|
+
desc 'Update the metadata.json OS supported list to that defined in conf/supported_os_list.yaml'
|
102
|
+
task :update_os_support do |_task, args|
|
103
|
+
PdkSync.main(steps: [:update_os_support], args: args)
|
104
|
+
end
|
105
|
+
|
106
|
+
desc 'Remove a platform version from the metadata.json'
|
107
|
+
task :remove_platform_from_metadata, [:os, :version] do |_task, args|
|
108
|
+
PdkSync.main(steps: [:remove_platform_from_metadata], args: args)
|
109
|
+
end
|
110
|
+
|
111
|
+
desc 'Add a platform version to the metadata.json'
|
112
|
+
task :add_platform_to_metadata, [:os, :version] do |_task, args|
|
113
|
+
PdkSync.main(steps: [:add_platform_to_metadata], args: args)
|
114
|
+
end
|
115
|
+
|
116
|
+
desc 'Add or update a requirement in the metadata.json'
|
117
|
+
task :update_requirements, [:name, :key, :value] do |_task, args|
|
118
|
+
PdkSync.main(steps: [:update_requirements], args: args)
|
119
|
+
end
|
120
|
+
|
121
|
+
desc 'Normalise the OS and OS versions in the metadata.json'
|
122
|
+
task :normalize_metadata_supported_platforms do |_task, args|
|
123
|
+
PdkSync.main(steps: [:normalize_metadata_supported_platforms], args: args)
|
45
124
|
end
|
46
125
|
end
|
47
126
|
|
@@ -51,6 +130,11 @@ namespace :git do
|
|
51
130
|
PdkSync.main(steps: [:clone])
|
52
131
|
end
|
53
132
|
|
133
|
+
desc 'Clone managed gem'
|
134
|
+
task :clone_gem, [:gem_name] do |_task, args|
|
135
|
+
PdkSync.main(steps: [:clone_gem], args: args)
|
136
|
+
end
|
137
|
+
|
54
138
|
desc "Stage commits for modules, branchname and commit message eg rake 'git:create_commit[flippity, commit messagez]'"
|
55
139
|
task :create_commit, [:branch_name, :commit_message] do |_task, args|
|
56
140
|
PdkSync.main(steps: [:create_commit], args: args)
|