diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..56ed051 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,12 @@ +name: CI + +on: pull_request + +concurrency: + group: ${{ github.ref_name }}-${{ github.workflow }} + cancel-in-progress: true + +jobs: + test: + name: Tests + uses: theforeman/actions/.github/workflows/smart_proxy_plugin.yml@v0 diff --git a/Gemfile b/Gemfile index 6642277..eadcb93 100644 --- a/Gemfile +++ b/Gemfile @@ -3,8 +3,7 @@ source 'https://rubygems.org' gemspec group :development do - gem 'smart_proxy', git: 'https://github.com/theforeman/smart-proxy', - branch: 'develop' + gem 'smart_proxy', github: 'theforeman/smart-proxy', branch: ENV['SMART_PROXY_BRANCH'] #gem 'smart_proxy', path: '../smart-proxy' gem 'pry' gem 'pry-byebug' diff --git a/lib/smart_proxy_ansible/playbooks_reader.rb b/lib/smart_proxy_ansible/playbooks_reader.rb index f88db8b..e381240 100644 --- a/lib/smart_proxy_ansible/playbooks_reader.rb +++ b/lib/smart_proxy_ansible/playbooks_reader.rb @@ -14,13 +14,13 @@ def playbooks(playbooks_to_import) end def get_playbooks_names(collections_path) - Dir.glob("#{collections_path}/ansible_collections/*/*/playbooks/*").map do |path| + glob_path("#{collections_path}/ansible_collections/*/*/playbooks/*").map do |path| ReaderHelper.playbook_or_role_full_name(path) end end def read_collection_playbooks(collections_path, playbooks_to_import = nil) - Dir.glob("#{collections_path}/ansible_collections/*/*/playbooks/*").map do |path| + glob_path("#{collections_path}/ansible_collections/*/*/playbooks/*").map do |path| name = ReaderHelper.playbook_or_role_full_name(path) { name: name, @@ -31,6 +31,12 @@ def read_collection_playbooks(collections_path, playbooks_to_import = nil) message = "Could not read Ansible playbooks #{collections_path} - #{e.message}" raise ReadPlaybooksException, message end + + private + + def glob_path(path) + Dir.glob path + end end end end diff --git a/lib/smart_proxy_ansible/roles_reader.rb b/lib/smart_proxy_ansible/roles_reader.rb index b690caf..e6181da 100644 --- a/lib/smart_proxy_ansible/roles_reader.rb +++ b/lib/smart_proxy_ansible/roles_reader.rb @@ -44,7 +44,7 @@ def glob_path(path) end def read_collection_roles(collections_path) - Dir.glob("#{collections_path}/ansible_collections/*/*/roles/*").map do |path| + glob_path("#{collections_path}/ansible_collections/*/*/roles/*").map do |path| ReaderHelper.playbook_or_role_full_name(path) end rescue Errno::ENOENT, Errno::EACCES => e diff --git a/smart_proxy_ansible.gemspec b/smart_proxy_ansible.gemspec index 431a6c4..5644042 100644 --- a/smart_proxy_ansible.gemspec +++ b/smart_proxy_ansible.gemspec @@ -24,16 +24,10 @@ Gem::Specification.new do |gem| gem.extra_rdoc_files = ['README.md', 'LICENSE'] gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ['lib'] - gem.license = 'GPL-3.0' - gem.required_ruby_version = '>= 2.5' + gem.license = 'GPL-3.0-only' + gem.required_ruby_version = '>= 2.7' gem.add_development_dependency 'rake', '~> 13.0' - gem.add_development_dependency('mocha', '~> 1') - gem.add_development_dependency('webmock', '~> 3') - gem.add_development_dependency('rack-test', '~> 0') - gem.add_development_dependency('logger') - gem.add_development_dependency('smart_proxy') - gem.add_runtime_dependency('net-ssh') gem.add_runtime_dependency('smart_proxy_dynflow', '~> 0.8') gem.add_runtime_dependency('smart_proxy_remote_execution_ssh', '~> 0.4') end diff --git a/test/playbooks_reader_test.rb b/test/playbooks_reader_test.rb index 8190de1..5a1a026 100644 --- a/test/playbooks_reader_test.rb +++ b/test/playbooks_reader_test.rb @@ -54,24 +54,23 @@ class PlaybooksReaderTest < Minitest::Test end describe 'playbooks_names method' do - let(:playbooks_names) { %w[xprazak2.forklift_collection.freeipa_server.yml xprazak2.forklift_collection.upgrade.yaml] } before do - Dir.expects(:glob).with('/usr/share/ansible/collections/ansible_collections/*/*/playbooks/*').returns([]) - Dir.expects(:glob).with('/etc/ansible/collections/ansible_collections/*/*/playbooks/*').returns(playbooks_names) + Proxy::Ansible::PlaybooksReader.expects(:glob_path).with('/usr/share/ansible/collections/ansible_collections/*/*/playbooks/*').returns([]) + collection_playbooks = [ + '/etc/ansible/collections/ansible_collections/xprazak2/forklift_collection/playbooks/freeipa_server.yml', + '/etc/ansible/collections/ansible_collections/xprazak2/forklift_collection/playbooks/upgrade.yaml', + ] + Proxy::Ansible::PlaybooksReader.expects(:glob_path).with('/etc/ansible/collections/ansible_collections/*/*/playbooks/*').returns(collection_playbooks) end it 'should return playbooks names as an array' do res = Proxy::Ansible::PlaybooksReader.playbooks_names assert_equal Array, res.class - assert_equal 2, res.count end it 'should return playbooks names with no .yml or .yaml extension' do res = Proxy::Ansible::PlaybooksReader.playbooks_names - assert_equal Array, res.class - assert_equal 2, res.count - assert not(res.first.match(/.ya?ml/)) - assert not(res.last.match(/.ya?ml/)) + assert_equal %w[xprazak2.forklift_collection.freeipa_server xprazak2.forklift_collection.upgrade], res end end end