bosh-plugin-pipeline 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.rmvrc +1 -0
  4. data/.rspec +3 -0
  5. data/.travis.yml +9 -0
  6. data/Gemfile +8 -0
  7. data/Gemfile.lock +260 -0
  8. data/README.md +61 -0
  9. data/Rakefile +5 -0
  10. data/bosh-plugin-pipeline.gemspec +38 -0
  11. data/lib/bosh/bosh_version_updater/helpers.rb +92 -0
  12. data/lib/bosh/bosh_version_updater.rb +11 -0
  13. data/lib/bosh/cli/commands/bosh_version_updater.rb +27 -0
  14. data/lib/bosh/cli/commands/plugin_generator.rb +26 -0
  15. data/lib/bosh/plugin_generator/generator.rb +29 -0
  16. data/lib/bosh/plugin_generator/helpers.rb +106 -0
  17. data/lib/bosh/plugin_generator.rb +11 -0
  18. data/lib/bosh/plugin_pipeline/version.rb +5 -0
  19. data/spec/assets/simple-template.txt +3 -0
  20. data/spec/plugin_generator/generator_spec.rb +25 -0
  21. data/spec/plugin_generator_spec.rb +85 -0
  22. data/spec/spec_helper.rb +17 -0
  23. data/templates/.gitignore +36 -0
  24. data/templates/.ruby-gemset.erb +1 -0
  25. data/templates/.ruby-version.erb +1 -0
  26. data/templates/.travis.yml +6 -0
  27. data/templates/Gemfile +4 -0
  28. data/templates/README.md.erb +33 -0
  29. data/templates/Rakefile +5 -0
  30. data/templates/cli/commands/command.rb.erb +14 -0
  31. data/templates/gemspec.erb +36 -0
  32. data/templates/helpers_folder/helpers.rb.erb +11 -0
  33. data/templates/helpers_folder/version.rb.erb +5 -0
  34. data/templates/licenses/apache2.txt +13 -0
  35. data/templates/licenses/gpl.txt +15 -0
  36. data/templates/licenses/lgpl.txt +8 -0
  37. data/templates/licenses/mit.txt +21 -0
  38. data/templates/main.rb.erb +11 -0
  39. data/templates/spec/.rspec +3 -0
  40. data/templates/spec/command_spec.rb +11 -0
  41. data/templates/spec/spec_helper.rb +12 -0
  42. metadata +257 -0
@@ -0,0 +1,106 @@
1
+ require 'git'
2
+ require 'bosh/versions'
3
+
4
+ module Bosh
5
+ module PluginGenerator
6
+ module Helpers
7
+
8
+ attr_accessor :plugin_name, :plugin_folder, :lib_folder, :helpers_folder,
9
+ :commands_folder, :bosh_version
10
+
11
+ extend Forwardable
12
+ include Bosh::Versions::Helpers
13
+ def_delegator :@generator, :generate
14
+
15
+ def extract_options(plugin_name)
16
+ @plugin_name = plugin_name
17
+ @plugin_folder = plugin_name
18
+ @bosh_version = bosh_gem_latest_version
19
+ @license_type = options[:license]
20
+ @lib_folder = File.join(plugin_name, 'lib', 'bosh')
21
+ @spec_folder = File.join(plugin_name, 'spec')
22
+ @helpers_folder = File.join(lib_folder, short_plugin_name)
23
+ @commands_folder = File.join(lib_folder, 'cli', 'commands')
24
+
25
+ default_context = {
26
+ email: Git.global_config["user.email"],
27
+ author: Git.global_config["user.name"],
28
+ description: "Short description.",
29
+ license: nil,
30
+ full_plugin_name: full_plugin_name,
31
+ short_plugin_name: short_plugin_name,
32
+ class_name: short_plugin_name.split('_').collect(&:capitalize).join,
33
+ bosh_version: bosh_version
34
+ }
35
+ context = default_context.merge(options)
36
+ raise "You need to specify email and author" if context[:email].nil? || context[:author].nil?
37
+ templates_folder = File.expand_path("../../../../templates", __FILE__)
38
+ @generator = Bosh::PluginGenerator::Generator.new(context, source_folder: templates_folder)
39
+ end
40
+
41
+ def generate_files
42
+ generate_command_class
43
+ generate_helpers
44
+ generate_version
45
+ generate_gemspec
46
+ generate_readme
47
+ generate_license if license?
48
+ generate_developer_environment
49
+ end
50
+
51
+ private
52
+
53
+ def full_plugin_name
54
+ return @full_plugin_name if @full_plugin_name
55
+ separator = plugin_name.include?('_') ? '_' : '-'
56
+ @full_plugin_name = plugin_name.start_with?('bosh') ? plugin_name : ['bosh', plugin_name].join(separator)
57
+ end
58
+
59
+ def short_plugin_name
60
+ @short_plugin_name ||= plugin_name.gsub(/^bosh[_-]/, '')
61
+ end
62
+
63
+ def license?
64
+ !!@license_type
65
+ end
66
+
67
+ def generate_command_class
68
+ generate('main.rb.erb', File.join(lib_folder, "#{short_plugin_name}.rb"))
69
+ generate('cli/commands/command.rb.erb', File.join(commands_folder, "#{short_plugin_name}.rb"))
70
+ end
71
+
72
+ def generate_helpers
73
+ generate('helpers_folder/helpers.rb.erb', File.join(helpers_folder, 'helpers.rb'))
74
+ end
75
+
76
+ def generate_version
77
+ generate('helpers_folder/version.rb.erb', File.join(helpers_folder, 'version.rb'))
78
+ end
79
+
80
+ def generate_gemspec
81
+ generate('gemspec.erb', File.join(plugin_name, "#{full_plugin_name}.gemspec"))
82
+ end
83
+
84
+ def generate_readme
85
+ generate('README.md.erb', File.join(plugin_name, 'README.md'))
86
+ end
87
+
88
+ def generate_license
89
+ generate("licenses/#{@license_type}.txt", File.join(plugin_name, 'LICENSE'))
90
+ end
91
+
92
+ def generate_developer_environment
93
+ generate('Gemfile', File.join(plugin_folder, 'Gemfile'))
94
+ generate('Rakefile', File.join(plugin_folder, 'Rakefile'))
95
+ generate('spec/spec_helper.rb', File.join(@spec_folder, 'spec_helper.rb'))
96
+ generate('spec/command_spec.rb', File.join(@spec_folder, 'command_spec.rb'))
97
+ generate('spec/.rspec', File.join(plugin_folder, '.rspec'))
98
+ generate('.gitignore', File.join(plugin_folder, '.gitignore'))
99
+ generate('.ruby-version.erb', File.join(plugin_folder, '.ruby-version'))
100
+ generate('.ruby-gemset.erb', File.join(plugin_folder, '.ruby-gemset'))
101
+ generate('.travis.yml', File.join(plugin_folder, '.travis.yml'))
102
+ end
103
+
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,11 @@
1
+ require "cli"
2
+ require "cli/core_ext"
3
+
4
+ module Bosh
5
+ module PluginGenerator
6
+ include BoshExtensions
7
+ end
8
+ end
9
+
10
+ require "bosh/plugin_generator/generator"
11
+ require "bosh/plugin_generator/helpers"
@@ -0,0 +1,5 @@
1
+ module Bosh
2
+ module PluginPipeline
3
+ VERSION = '0.2.0'
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ I needed to put something here, so here is my question :
2
+
3
+ How many people can read hex if only <%= people.join(', ') %> and dead people can read hex?
@@ -0,0 +1,25 @@
1
+ describe Bosh::PluginGenerator::Generator do
2
+ let(:context) { { people: ['you', 'me'] } }
3
+ let(:tmpdir) { Dir.mktmpdir }
4
+ let(:target) { File.join(tmpdir, 'subfolder-1', 'subfolder-2', 'result.txt') }
5
+ subject { Bosh::PluginGenerator::Generator.new(context, source_folder: File.expand_path('../../assets', __FILE__)) }
6
+ after { FileUtils.remove_entry_secure tmpdir }
7
+
8
+ describe '#generate' do
9
+ before do
10
+ subject.generate('simple-template.txt', target)
11
+ end
12
+
13
+ context 'simple template' do
14
+
15
+ it 'creates file with folder' do
16
+ expect(File).to exist(target)
17
+ end
18
+
19
+ it 'creates renders ERB' do
20
+ expect(File.read(target)).to match(/you, me/)
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,85 @@
1
+ describe 'bosh generate plugin' do
2
+
3
+ describe 'magic command' do
4
+
5
+ before(:context) do
6
+ @current_dir = Dir.pwd
7
+ @tmpdir = Dir.mktmpdir
8
+ Dir.chdir(@tmpdir)
9
+ end
10
+
11
+ after(:context) do
12
+ Dir.chdir(@current_dir)
13
+ FileUtils.remove_entry_secure(@tmpdir)
14
+ end
15
+
16
+ context 'without parameters and "bosh-" preffix' do
17
+ let(:plugin_folder) { File.join(Dir.pwd, 'magic') }
18
+
19
+ before(:all) do
20
+ system('bosh generate plugin magic > /dev/null')
21
+ end
22
+
23
+ it 'creates gem with "bosh-" prefix' do
24
+ gemspec_file = File.join(plugin_folder, 'bosh-magic.gemspec')
25
+ expect(File).to exist(gemspec_file)
26
+ expect(File.read(gemspec_file)).to match(/bosh-magic/)
27
+ end
28
+
29
+ it 'generates gemspec with email from Git setup' do
30
+ expect(File.read("#{plugin_folder}/bosh-magic.gemspec")).to include(Git.global_config["user.name"])
31
+ expect(File.read("#{plugin_folder}/bosh-magic.gemspec")).to include(Git.global_config["user.email"])
32
+ end
33
+
34
+ it 'has no license file' do
35
+ expect(File).not_to exist(File.join(plugin_folder, 'LICENSE'))
36
+ end
37
+
38
+ it 'has initialized git repository' do
39
+ expect(File).to exist(File.join(plugin_folder, '.git'))
40
+ end
41
+
42
+ it 'can run rspec on generated plugin (using rake command)' do
43
+ Dir.chdir(plugin_folder) do
44
+ Bundler.with_clean_env do
45
+ system('bundle exec rake')
46
+ end
47
+ end
48
+ expect($?.exitstatus).to eq(0)
49
+ end
50
+
51
+ end
52
+
53
+ context 'with parameters, license and "bosh-" prefix' do
54
+ let(:plugin_folder) { File.join(Dir.pwd, 'bosh-magic') }
55
+
56
+ before(:all) do
57
+ command = <<-CMD
58
+ bosh generate plugin bosh-magic --email=gandalf@email.com \
59
+ --author=Gandalf \
60
+ --license=mit > /dev/null
61
+ CMD
62
+ system(command)
63
+ end
64
+
65
+ it 'creates folder with the name specified as plugin a name' do
66
+ expect(File).to exist(plugin_folder)
67
+ end
68
+
69
+ it 'creates gem with 'bosh-' prefix' do
70
+ gemspec_file = File.join(plugin_folder, 'bosh-magic.gemspec')
71
+ expect(File).to exist(gemspec_file)
72
+ expect(File.read(gemspec_file)).to match(/bosh-magic/)
73
+ end
74
+
75
+ it 'generates gemspec with correct email' do
76
+ expect(File.read("#{plugin_folder}/bosh-magic.gemspec")).to match(/gandalf@email.com/)
77
+ end
78
+
79
+ it 'creates license file' do
80
+ expect(File).to exist(File.join(plugin_folder, 'LICENSE'))
81
+ end
82
+
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,17 @@
1
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
2
+
3
+ require "rubygems"
4
+ require "bundler"
5
+ Bundler.setup(:default, :test)
6
+
7
+ $:.unshift(File.expand_path("../../lib", __FILE__))
8
+
9
+ require "rspec/core"
10
+ require "rspec/its"
11
+
12
+ require "bosh/plugin_generator"
13
+
14
+ def asset_file(*path)
15
+ assets_file = File.expand_path("../assets", __FILE__)
16
+ File.join(assets_file, *path)
17
+ end
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
35
+ .ruby-gemset
36
+ .ruby-version
@@ -0,0 +1 @@
1
+ <%= full_plugin_name %>
@@ -0,0 +1 @@
1
+ <%= RUBY_VERSION %>
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ before_install:
3
+ - sudo apt-get update -qq --fix-missing
4
+ rvm:
5
+ - 2.1.5
6
+ - 2.2.3
data/templates/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bosh-plugin.gemspec
4
+ gemspec
@@ -0,0 +1,33 @@
1
+ # Bosh plugin generator
2
+
3
+ <%= description || 'Short description here.' %>
4
+
5
+ ## What is BOSH?
6
+
7
+ BOSH orchestrates initial deployments and ongoing updates that are: predictable, repeatable, reliable, self-healing, infrastructure-agnostic. You can take a look on [BOSH project on GitHub](https://github.com/cloudfoundry/bosh) and read more details in [docs](http://docs.cloudfoundry.org/bosh/).
8
+
9
+ ## How to install
10
+ ```
11
+ gem install <%= full_plugin_name %>
12
+ ```
13
+
14
+ ## How to use
15
+ ```
16
+ bosh say hello
17
+ ```
18
+
19
+ ## How to publish gems
20
+
21
+ See [this notes](http://guides.rubygems.org/publishing/) to know how to publish your gem.
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
30
+
31
+ ## Notes
32
+
33
+ Generated by [BOSH plugin generator](https://github.com/Altoros/bosh-plugin-generator)
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ task :default => :spec
5
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,14 @@
1
+ require "bosh/<%= short_plugin_name %>"
2
+
3
+ module Bosh::Cli::Command
4
+ class <%= class_name %> < Base
5
+ include Bosh::<%= class_name %>::Helpers
6
+
7
+ usage "say hello"
8
+ desc "simple BOSH CLI plugin"
9
+ def perform
10
+ say_hello
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'bosh/<%= short_plugin_name %>/version'
6
+ bosh_version = '<%= bosh_version %>'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = '<%= full_plugin_name %>'
10
+ spec.version = Bosh::<%= class_name %>::VERSION
11
+ spec.authors = ['<%= author %>']
12
+ spec.email = ['<%= email %>']
13
+ spec.description = %q{<%= description %>}
14
+ spec.summary = %q{<%= description %>}
15
+ spec.homepage = 'https://github.com/cloudfoundry/bosh'
16
+ <%- if license %>
17
+ spec.license = '<%= license.upcase %>'
18
+ <% end %>
19
+
20
+ spec.files = `git ls-files`.split($/)
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.required_ruby_version = '>= 2.0.0'
26
+
27
+ spec.add_runtime_dependency 'bosh_cli', ">= #{bosh_version}"
28
+ spec.add_runtime_dependency 'bosh_common', ">= #{bosh_version}"
29
+ spec.add_runtime_dependency 'membrane', '~> 1.1.0'
30
+
31
+ spec.add_development_dependency 'bundler', '~> 1.10'
32
+ spec.add_development_dependency 'rspec', '~> 3.3.0'
33
+ spec.add_development_dependency 'rspec-its', '~> 1.2.0'
34
+ spec.add_development_dependency 'rake', '~> 10.4.2'
35
+ spec.add_development_dependency 'rubocop', '~> 0.34.2'
36
+ end
@@ -0,0 +1,11 @@
1
+ module Bosh
2
+ module <%= class_name %>
3
+ module Helpers
4
+
5
+ def say_hello
6
+ say "Hello, world!".make_green
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Bosh
2
+ module <%= class_name %>
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ Copyright <%= Date.today.year %> <%= "#{author} <#{email}>" %>
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,15 @@
1
+ <%= description %>
2
+ Copyright (C) <%= Date.today.year %> <%= "#{author} <#{email}>" %>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -0,0 +1,8 @@
1
+ <%= description %>
2
+ Copyright (C) <%= Date.today.year %> <%= "#{author} <#{email}>" %>
3
+
4
+ This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
5
+
6
+ This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
7
+
8
+ You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) <%= Date.today.year %> <%= "#{author} <#{email}>" %>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,11 @@
1
+ require "cli"
2
+ require "cli/validation"
3
+
4
+ module Bosh
5
+ module <%= class_name %>
6
+ include BoshExtensions
7
+ end
8
+ end
9
+
10
+ require "bosh/<%= short_plugin_name %>/helpers"
11
+ require "bosh/<%= short_plugin_name %>/version"
@@ -0,0 +1,3 @@
1
+ --format progress
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,11 @@
1
+ describe "bosh say hello" do
2
+
3
+ before do
4
+ system("bosh say hello > /dev/null")
5
+ end
6
+
7
+ it "exits without errors" do
8
+ expect($?.exitstatus).to eq(0)
9
+ end
10
+
11
+ end
@@ -0,0 +1,12 @@
1
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
2
+
3
+ require "rubygems"
4
+ require "bundler"
5
+ Bundler.setup(:default, :test)
6
+
7
+ $:.unshift(File.expand_path("../../lib", __FILE__))
8
+
9
+ require "rspec/core"
10
+ require "rspec/its"
11
+
12
+ require "bosh/<%= short_plugin_name %>"