Skip to content

Commit

Permalink
Fixed Ruby issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanratcliffe committed Mar 16, 2024
1 parent cf42f96 commit 2e6d552
Show file tree
Hide file tree
Showing 133 changed files with 7,091 additions and 47 deletions.
10 changes: 4 additions & 6 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@
{
"name": "Debian",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/base:bullseye",
"image": "mcr.microsoft.com/devcontainers/ruby:3.2",
"features": {
"ghcr.io/devcontainers/features/ruby:1": {},
"ghcr.io/devcontainers/features/github-cli:1": {}
},

"postAttachCommand": "bundle",
"customizations": {
"vscode": {
"extensions": [
"castwide.ruby-debug",
"CucumberOpen.cucumber-official"
"CucumberOpen.cucumber-official",
"Shopify.ruby-extensions-pack"
]
}
}
},

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
Expand Down
4 changes: 0 additions & 4 deletions .gitmodules

This file was deleted.

3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ end

group :development do
gem 'pry'
gem 'cucumber'
gem 'rubocop'
gem 'rubygems-tasks'
end

# Evaluate Gemfile.local if it exists
Expand Down
1 change: 1 addition & 0 deletions cucumber.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default: --publish-quiet
8 changes: 4 additions & 4 deletions features/zzz_run.feature
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Feature: Run rspec and acceptance test suites
And I should not see message pattern "role::"

# This test is a full test using my controlrepo. It should remain at the end because it takes ages
Scenario: Run advanced spec tests
Given control repo "puppet_controlrepo"
When I run onceover command "run spec -p --force"
Then I should not see any errors
# Scenario: Run advanced spec tests
# Given control repo "puppet_controlrepo"
# When I run onceover command "run spec -p --force"
# Then I should not see any errors
16 changes: 8 additions & 8 deletions lib/onceover/beaker/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
}
#read env vars
env_vars = {
:color => ENV['BEAKER_color'] || ENV['RS_COLOR'],
:nodeset => ENV['BEAKER_set'] || ENV['RS_SET'],
:nodesetfile => ENV['BEAKER_setfile'] || ENV['RS_SETFILE'],
:provision => ENV['BEAKER_provision'] || ENV['RS_PROVISION'],
:keyfile => ENV['BEAKER_keyfile'] || ENV['RS_KEYFILE'],
:debug => ENV['BEAKER_debug'] || ENV['RS_DEBUG'],
:destroy => ENV['BEAKER_destroy'] || ENV['RS_DESTROY'],
}.delete_if {|key, value| value.nil?}
:color => ENV['BEAKER_color'] || ENV.fetch('RS_COLOR', nil),
:nodeset => ENV['BEAKER_set'] || ENV.fetch('RS_SET', nil),
:nodesetfile => ENV['BEAKER_setfile'] || ENV.fetch('RS_SETFILE', nil),
:provision => ENV['BEAKER_provision'] || ENV.fetch('RS_PROVISION', nil),
:keyfile => ENV['BEAKER_keyfile'] || ENV.fetch('RS_KEYFILE', nil),
:debug => ENV['BEAKER_debug'] || ENV.fetch('RS_DEBUG', nil),
:destroy => ENV['BEAKER_destroy'] || ENV.fetch('RS_DESTROY', nil),
}.compact
#combine defaults and env_vars to determine overall options
options = defaults.merge(env_vars)

Expand Down
6 changes: 3 additions & 3 deletions lib/onceover/controlrepo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def self.init(repo)
# Add .onceover to Gitignore
gitignore_path = File.expand_path('.gitignore', repo.root)
if File.exist? gitignore_path
gitignore_content = (File.open(gitignore_path, 'r') {|f| f.read }).split("\n")
gitignore_content = (File.read(gitignore_path)).split("\n")
message = "#{'changed'.green}"
else
message = "#{'created'.green}"
Expand All @@ -526,7 +526,7 @@ def self.init(repo)

unless gitignore_content.include?(".onceover")
gitignore_content << ".onceover\n"
File.open(gitignore_path, 'w') {|f| f.write(gitignore_content.join("\n")) }
File.write(gitignore_path, gitignore_content.join("\n"))
puts "#{message} #{Pathname.new(gitignore_path).relative_path_from(Pathname.new(Dir.pwd)).to_s}"
end
end
Expand Down Expand Up @@ -611,7 +611,7 @@ def self.init_write_file(contents, out_file)
if File.exist?(out_file)
puts "#{'skipped'.yellow} #{Pathname.new(out_file).relative_path_from(Pathname.new(Dir.pwd)).to_s} #{'(exists)'.yellow}"
else
File.open(out_file,'w') {|f| f.write(contents)}
File.write(out_file, contents)
puts "#{'created'.green} #{Pathname.new(out_file).relative_path_from(Pathname.new(Dir.pwd)).to_s}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/onceover/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def deploy_local(repo = Onceover::Controlrepo.new, opts = {})
# Avoid touching thing if we don't need to
if /:control_branch/.match(puppetfile_contents)
logger.debug "replacing :control_branch mentions in the Puppetfile with #{git_branch}"
new_puppetfile_contents = puppetfile_contents.gsub(/:control_branch/, "'#{git_branch}'")
new_puppetfile_contents = puppetfile_contents.gsub(":control_branch", "'#{git_branch}'")
File.write("#{temp_controlrepo}/Puppetfile", new_puppetfile_contents)
end
end
Expand Down
6 changes: 2 additions & 4 deletions lib/onceover/rspec/formatters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@ def dump_failures notification
FileUtils.mkdir_p "#{RSpec.configuration.onceover_tempdir}/parallel"

# Dump the notification to a unique file
File.open("#{RSpec.configuration.onceover_tempdir}/parallel/results-#{random_string}.yaml", "w") do |file|
file.write(extract_failures(notification).to_yaml)
end
File.write("#{RSpec.configuration.onceover_tempdir}/parallel/results-#{random_string}.yaml", extract_failures(notification).to_yaml)
end

def output_results(directory)
Expand All @@ -280,7 +278,7 @@ def output_results(directory)
# Merge data
roles = files.reduce({}) do |errs, file|
# Read all files and merge them
errs.merge(YAML.load(File.read(file))) {|key, oldval, newval| [oldval, newval].flatten }# rubocop:disable Security/YAMLLoad
errs.merge(YAML.load_file(file)) {|key, oldval, newval| [oldval, newval].flatten }
end

# Delete files from the disk
Expand Down
2 changes: 1 addition & 1 deletion lib/onceover/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def run_spec!
Dir.chdir(@repo.tempdir) do
# Disable warnings unless we are running in debug mode
unless logger.level.zero?
previous_rubyopt = ENV['RUBYOPT']
previous_rubyopt = ENV.fetch('RUBYOPT', nil)
ENV['RUBYOPT'] = ENV['RUBYOPT'].to_s + ' -W0'
end

Expand Down
2 changes: 1 addition & 1 deletion lib/onceover/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def to_s
if classes.count > 1
class_msg = "#{classes.count}_classes"
else
class_msg = classes[0].name.gsub(/::/,'__')
class_msg = classes[0].name.gsub("::",'__')
end

if nodes.count > 1
Expand Down
17 changes: 5 additions & 12 deletions onceover.gemspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- encoding: utf-8 -*-

$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift File.expand_path('lib', __dir__)

Gem::Specification.new do |s|
Gem::Specification.new do |s| # rubocop:disable Gemspec/RequireMFA
s.name = "onceover"
s.version = "3.21.0"
s.authors = ["Dylan Ratcliffe"]
Expand All @@ -19,27 +19,20 @@ Gem::Specification.new do |s|

# Runtime dependencies, but also probably dependencies of requiring projects
s.add_runtime_dependency 'backticks', '>= 1.0.2'
s.add_runtime_dependency 'colored', '~> 1.2'
s.add_runtime_dependency 'colored', '>= 1.2'
s.add_runtime_dependency 'cri', '>= 2.6'
s.add_runtime_dependency 'deep_merge', '>= 1.0.0'
s.add_runtime_dependency 'git'
s.add_runtime_dependency 'logging', '>= 2.0.0'
s.add_runtime_dependency 'multi_json', '~> 1.10'
s.add_runtime_dependency 'multi_json', '>= 1.10'
s.add_runtime_dependency 'parallel_tests', ">= 2.0.0"
s.add_runtime_dependency 'puppet', '>=4.0'
s.add_runtime_dependency 'puppetlabs_spec_helper', ">= 0.4.0"
s.add_runtime_dependency 'r10k', '>=2.1.0'
s.add_runtime_dependency 'rake', '>= 10.0.0'
s.add_runtime_dependency 'rspec', '>= 3.0.0'
s.add_runtime_dependency 'rspec-puppet', ">= 2.4.0"
s.add_runtime_dependency 'rspec_junit_formatter', '>= 0.2.0'
s.add_runtime_dependency 'rspec-puppet', ">= 2.4.0"
s.add_runtime_dependency 'terminal-table', '>= 1.8.0'
s.add_runtime_dependency 'versionomy', '>= 0.5.0'

s.add_development_dependency 'cucumber', '~> 4.1'
s.add_development_dependency 'pry', '~> 0.13.1'
# We need to depend on rubocop <= 1.12 in order to support Ruby 2.4 (Puppet
# 5). Once we drop support for Puppet 5 we can re-open this
s.add_development_dependency 'rubocop', '>= 1.6.1', '<= 1.12'
s.add_development_dependency 'rubygems-tasks', '~> 0.2.5'
end
1 change: 0 additions & 1 deletion spec/fixtures/controlrepos/puppet_controlrepo
Submodule puppet_controlrepo deleted from 4ad5d0
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"cmd": "bundle exec onceover run spec",
"name": "onceover spec",
"cwd": "{PROJECT_PATH}",
"errorMatch": [
"compilation:\\s.*production\\/(?<file>[\\w\\/]*.pp):(?<line>\\d*):(?<col>\\d*)"
],
"atomCommandName": "onceover:spec"
}
5 changes: 5 additions & 0 deletions spec/fixtures/controlrepos/puppet_controlrepo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.onceover
.DS_Store
.bundle
Gemfile.lock
vendor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2.2
13 changes: 13 additions & 0 deletions spec/fixtures/controlrepos/puppet_controlrepo/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: ruby

cache:
bundler: true
directories:
- .onceover

script: bundle exec onceover run spec --force
bundler_args: --without development --path vendor/bundle

rvm:
- 2.3.0
- 2.3.3
22 changes: 22 additions & 0 deletions spec/fixtures/controlrepos/puppet_controlrepo/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
source 'https://rubygems.org'

group :development do
gem 'pry'
gem 'pry-byebug'
gem 'rb-readline'
gem 'puppet-debugger'
end

if ENV['ONCEOVER_gem'] == 'local'
gem 'onceover', :path => '/Users/dylan/git/onceover'
# gem 'onceover-octocatalog-diff', :path => '/Users/dylan/git/onceover-octocatalog-diff'
else
gem 'onceover', :git => 'https://github.com/dylanratcliffe/onceover.git'#, :branch => 'issue-51'
# gem 'onceover-octocatalog-diff', :git => 'https://github.com/dylanratcliffe/onceover-octocatalog-diff.git'
end

gem 'hiera-eyaml'
gem 'puppet', ENV['PUPPET_version'] || '~> 8'

# Require by telegraf module
gem 'toml-rb'
50 changes: 50 additions & 0 deletions spec/fixtures/controlrepos/puppet_controlrepo/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
node {
puppet.credentials 'PE-Deploy-Token'
stage('Git Checkout') { // for display purposes
// Get some code from a GitHub repository
checkout([
$class: 'GitSCM',
branches: [[name: env.BRANCH_NAME]],
doGenerateSubmoduleConfigurations: false,
userRemoteConfigs: [[url: 'https://github.com/dylanratcliffe/puppet_controlrepo.git']]])
}
stage('Install Gems') {
// Run the onceover tests
sh '''source /usr/local/rvm/scripts/rvm && bundle install --path=.gems --binstubs'''
}
stage('Run Onceover Tests') {
// Run the onceover tests
try {
sh '''source /usr/local/rvm/scripts/rvm && ./bin/onceover run spec'''
} catch (error) {
junit '.onceover/spec.xml'
throw error
}
}
stage('Deploy Code') {
echo env.BRANCH_NAME
puppet.codeDeploy env.BRANCH_NAME
}
stage('Run Puppet') {
// Get all of the classes that have changed
changedClasses = sh(returnStdout: true, script: './scripts/get_changed_classes.rb').trim().split('\n')
// Get the number of classes that have changed
numChangedClasses = sh(returnStdout: true, script: './scripts/count_changed_classes.rb').trim().toInteger()
// Generate a query that we will use
nodeQuery = ('nodes { resources { type = "Class" and title in ' + ("[\"" + changedClasses.join("\",\"") + "\"]") + ' } and catalog_environment = "' + env.BRANCH_NAME +'" }').toString()
// If things have changed then execute the query
if (numChangedClasses > 0) {
echo nodeQuery
affectedNodes = puppet.query nodeQuery
// If nothing has been affected by the change we don't need to try to
// initiate the run
if (affectedNodes.size() > 0) {
puppet.job env.BRANCH_NAME, query: nodeQuery
} else {
echo "Classes: " + changedClasses.join(",") + " changed. But no nodes were affected, skipping run."
}
} else {
echo "No classes changed, skipping this step."
}
}
}
Loading

0 comments on commit 2e6d552

Please sign in to comment.