everyleaf-embulk_helper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 47199c2195e7f7c5eaa82fcb8bc724b9d8cb6b81
4
+ data.tar.gz: 36e4cef37bfec31361c210c996cae6631d4e38b7
5
+ SHA512:
6
+ metadata.gz: bcccc09f44218259902ef6f47cc435f22e62060e8c988b997715bc4b889eb27e28ec050de016062686e8283d96c549aa5c1e268e52db5c109dc78d81dc420da6
7
+ data.tar.gz: 6ea9fb9a61bc3365e851021506a450610c63a350fe7f593e7ab78a8ff85ae7ddcab865bebc9b1350c16e1ff764c73253f8276ccb0d6e3e06b619c7e554ed8d69
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - jruby-19mode
4
+ addons:
5
+ code_climate:
6
+ repo_token:
7
+ secure: "Ael9qV6oxuruF2I4l5GVm85EXmsTFJB2AxcwT3Ni2fALj+/xUdR5n9FwPxLwTqSFhLmr/ccefOIyqMDCo9LNcDc8ib7ypYHsTbNu8vZHlM5mbDA4/N5fpvahpAd532XCxOg4B90oOIbVlyalPGmO4mhCDTr17GnvPXgOfdf2zzq7xRL3gUjP7MGGLCCXhvuu6/D6+YhKCHUGymeaxFUxUeTI0h8Uempl7fhqcOyJlgMB+m7iK4Owy6sX6DWHzcYBbnWXUw0Czy47JrZHbN3YseURDpe6WTXL9eC42wo2LhMnqQH9fkMNpKRN80XE0P636ckI4nwmsPjAkV4/Q8X4oXE1Q8Muuei9ZHFV8k26GY0aaJ+zEo5ajfBXZPBQcFrhYzUuWpSym0JBCr0lEywr1DVLl1Qf/2+9782JCs8Bjvq3qTMY4AB45OqpLBScRbx0WoK03yuHLNtHLc9IftCQolxb0Wi08Q48NJmg4nsBcSaaJKlry/yr/vZ5kdKZJG8hWQfMUUjE1WP4l3gr1l2tP46s62t3B4cLcZ8wCEjzHNFKc30AfomfmABGV8M9LdRaYaNkLBaHhQVzlGJB32WDZWU5xClYDy2K6PjuXWp1BY4JcMWRkS9vAyezwRxvkXzX68DUerpUpk6+XensYcjgdOY60EYcY7FIiSm91hzB6l0="
8
+ notifications:
9
+ slack:
10
+ secure: DWXP4y5GvW5EyuZbcpXH3pnbb4lycfQ3SnxFUErjNnZacKRXLf1r93D5nT9GFvDERU7T3LIm8qwei6h3O5YNQDU1TKOhpWrGgkVYh0/VsyJhVeKSAErurmuMrBaloZ3pfszaTIK+v/WFj8E+25w1QLJaNoQ5aMCsq0r+ipuW/nDwX9HFAuLshjSy0ALmHmdha67iTZidfMLW8JbaAf1BnbmqHjFI2QuzSU01Yl2hOdY8k4JBpVtR5ntQJEaBVd+O07oNiY+GdETAD2n7jViJInjTz2Oy5c6j1ijcIknnzzlufFA7+fBmzXYQlcVOJE//DpfdAjYxlm6qKIoTKlI8JRbfX2e94qGsaLAi4OrDIdChlp+oF1Id3VDPnf3ckz1s5b+tbBtjbu5FO2+i6GvimQPysj3af2RvUZ9UkzQEgOxy+sT9STNm8Aa/2zg+TgKHvZ2E89YmMO57k/pac/Bn1BiAkActKu/gZdun6l4PC7/0qUbEI/ndnNMbpKx5gOgmpiIWkTAMo6oDbigygUwduonsoKx0oT9rm8q1AQA6PrxORj7+5cd6kmEaPvSvZS4oiSVwJvgs4RLp65grG6TxmHDzBizbJlEveDvZ9sgG9wgH7/ihtqKVG1KxXycierEJUoYvN0IUDKYQWMzzNKl5rSw58lHDEu606U15gUk5mXY=
11
+ jdk:
12
+ - oraclejdk8
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ ## 0.0.1 - 2015-08-11
2
+
3
+ The first release!!
4
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in everyleaf-embulk_helper.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ everyleaf-embulk_helper (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ codeclimate-test-reporter (0.4.7)
10
+ simplecov (>= 0.7.1, < 1.0.0)
11
+ coderay (1.1.0)
12
+ docile (1.1.5)
13
+ ffi (1.9.10-java)
14
+ json (1.8.3)
15
+ json (1.8.3-java)
16
+ method_source (0.8.2)
17
+ power_assert (0.2.3)
18
+ pry (0.10.1)
19
+ coderay (~> 1.1.0)
20
+ method_source (~> 0.8.1)
21
+ slop (~> 3.4)
22
+ pry (0.10.1-java)
23
+ coderay (~> 1.1.0)
24
+ method_source (~> 0.8.1)
25
+ slop (~> 3.4)
26
+ spoon (~> 0.0)
27
+ rake (10.4.2)
28
+ rr (1.1.2)
29
+ simplecov (0.10.0)
30
+ docile (~> 1.1.0)
31
+ json (~> 1.8)
32
+ simplecov-html (~> 0.10.0)
33
+ simplecov-html (0.10.0)
34
+ slop (3.6.0)
35
+ spoon (0.0.4)
36
+ ffi
37
+ test-unit (3.1.2)
38
+ power_assert
39
+ test-unit-rr (1.0.3)
40
+ rr (>= 1.1.1)
41
+ test-unit (>= 2.5.2)
42
+
43
+ PLATFORMS
44
+ java
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ bundler (~> 1.7)
49
+ codeclimate-test-reporter
50
+ everyleaf-embulk_helper!
51
+ pry
52
+ rake (~> 10.0)
53
+ test-unit
54
+ test-unit-rr
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 uu59
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,126 @@
1
+ [![Build Status](https://travis-ci.org/everyleaf/everyleaf-embulk_helper.svg?branch=master)](https://travis-ci.org/everyleaf/everyleaf-embulk_helper)
2
+ [![Code Climate](https://codeclimate.com/github/everyleaf/everyleaf-embulk_helper/badges/gpa.svg)](https://codeclimate.com/github/everyleaf/everyleaf-embulk_helper)
3
+ [![Test Coverage](https://codeclimate.com/github/everyleaf/everyleaf-embulk_helper/badges/coverage.svg)](https://codeclimate.com/github/everyleaf/everyleaf-embulk_helper/coverage)
4
+
5
+ # Everyleaf::EmbulkHelper
6
+
7
+
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'everyleaf-embulk_helper'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install everyleaf-embulk_helper
24
+
25
+ Load rake tasks at your Rakefile:
26
+
27
+ require "bundler/gem_tasks"
28
+ require "everyleaf/embulk_helper/tasks"
29
+
30
+ Everyleaf::EmbulkHelper::Tasks.install({
31
+ gemspec: "./embulk-input-your-plugin.gemspec",
32
+ github_name: "uu59/embulk-input-your-plugin",
33
+ })
34
+
35
+ ## Usage
36
+
37
+ $ bundle exec rake -T
38
+ rake build # Build embulk-input-your-plugin-0.1.0.gem into the pkg directory
39
+ rake generate:bump_version # Bump version
40
+ rake generate:changelog # Generate CHANGELOG.md from previous release
41
+ rake generate:gemfiles # Generate gemfiles to test this plugin with released Embulk versions (since MIN_VERSION)
42
+ rake generate:prepare_release # Generate chengelog then bump version
43
+ rake generate:travis # Generate .travis.yml with gemfiles
44
+ rake install # Build and install embulk-input-your-plugin-0.1.0.gem into system gems
45
+ rake release # Create tag v0.1.0 and build and push embulk-input-your-plugin-0.1.0.gem to Rubygems
46
+
47
+ ### generate:gemfiles
48
+
49
+ $ mkdir gemfiles
50
+ $ cat > gemfiles/template.erb
51
+ source 'https://rubygems.org/'
52
+ gemspec :path => '../'
53
+
54
+ gem "embulk", "<%= version %>"
55
+
56
+ $ tree gemfiles
57
+ gemfiles
58
+ └── template.erb
59
+
60
+ 0 directories, 1 file
61
+ $ bundle exec rake generate:gemfiles MIN_VERSION=0.6.10
62
+ I, [2015-08-11T11:03:37.202083 #10238] INFO -- : Generate Embulk gemfiles from '0.6.10' to latest
63
+ I, [2015-08-11T11:03:38.966539 #10238] INFO -- : Updated Gemfiles '0.6.10' to '0.6.21'
64
+ $ tree gemfiles
65
+ gemfiles
66
+ ├── embulk-0.6.10
67
+ ├── embulk-0.6.11
68
+ ├── embulk-0.6.12
69
+ ├── embulk-0.6.13
70
+ ├── embulk-0.6.14
71
+ ├── embulk-0.6.15
72
+ ├── embulk-0.6.16
73
+ ├── embulk-0.6.17
74
+ ├── embulk-0.6.18
75
+ ├── embulk-0.6.19
76
+ ├── embulk-0.6.20
77
+ ├── embulk-0.6.21
78
+ ├── embulk-latest
79
+ └── template.erb
80
+ $ cat gemfiles/embulk-latest
81
+ source 'https://rubygems.org/'
82
+ gemspec :path => '../'
83
+
84
+ gem "embulk", "> 0.6.10"
85
+
86
+ $ cat gemfiles/embulk-0.6.18
87
+ source 'https://rubygems.org/'
88
+ gemspec :path => '../'
89
+
90
+ gem "embulk", "0.6.18"
91
+
92
+ ### generate:travis
93
+
94
+ NOTE: `versions` in template is assigned by file globbing from `gemfiles/*`, thus run `rake generate:gemfiles` before `rake generate:travis`.
95
+
96
+ $ cat > .travis.yml.erb
97
+ gemfiles:
98
+ <% versions.each do |v| -%>
99
+ - gemfiles/<%= v %>
100
+ <% end -%>
101
+
102
+ $ bundle exec rake generate:travis
103
+ I, [2015-08-11T11:06:53.375018 #10911] INFO -- : Updated .travis.yml
104
+ $ cat .travis.yml
105
+ gemfiles:
106
+ - gemfiles/embulk-0.6.10
107
+ - gemfiles/embulk-0.6.11
108
+ - gemfiles/embulk-0.6.12
109
+ - gemfiles/embulk-0.6.13
110
+ - gemfiles/embulk-0.6.14
111
+ - gemfiles/embulk-0.6.15
112
+ - gemfiles/embulk-0.6.16
113
+ - gemfiles/embulk-0.6.17
114
+ - gemfiles/embulk-0.6.18
115
+ - gemfiles/embulk-0.6.19
116
+ - gemfiles/embulk-0.6.20
117
+ - gemfiles/embulk-0.6.21
118
+ - gemfiles/embulk-latest
119
+
120
+ ## Contributing
121
+
122
+ 1. Fork it ( https://github.com/[my-github-username]/everyleaf-embulk_helper/fork )
123
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
124
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
125
+ 4. Push to the branch (`git push origin my-new-feature`)
126
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default => :test
4
+
5
+ desc "Run tests"
6
+ task :test do
7
+ ruby("test/run-test.rb", "--use-color=yes", "--collector=dir")
8
+ end
data/Rakefile.test ADDED
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH.unshift "./lib"
2
+ require "everyleaf/embulk_helper/tasks"
3
+
4
+ Everyleaf::EmbulkHelper::Tasks.install({
5
+ gemspec: "./everyleaf-embulk_helper.gemspec",
6
+ github_name: "everyleaf/everyleaf-embulk_helper",
7
+ })
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'everyleaf/embulk_helper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "everyleaf-embulk_helper"
8
+ spec.version = Everyleaf::EmbulkHelper::VERSION
9
+ spec.authors = ["yoshihara", "uu59"]
10
+ spec.email = ["h.yoshihara@everyleaf.com", "k@uu59.org"]
11
+ spec.summary = %q{Add some handy helpers for developing Embulk plugins}
12
+ spec.description = %q{Add some handy helpers for developing Embulk plugins}
13
+ spec.homepage = "https://github.com/everyleaf/everyleaf-embulk_helper"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "test-unit"
24
+ spec.add_development_dependency "test-unit-rr"
25
+ spec.add_development_dependency "pry"
26
+ spec.add_development_dependency 'codeclimate-test-reporter'
27
+ end
@@ -0,0 +1,72 @@
1
+ require "pathname"
2
+ require "open-uri"
3
+ require "logger"
4
+ require "rake"
5
+ require "erb"
6
+ require "json"
7
+ require "rubygems"
8
+
9
+ module Everyleaf
10
+ module EmbulkHelper
11
+ module Tasks
12
+ module Common
13
+ class OptionError < StandardError; end
14
+
15
+ include Rake::DSL
16
+
17
+ attr_reader :options
18
+
19
+ def initialize(options = {})
20
+ raise "options should be a Hash, given #{options.class}: #{options} " unless options.is_a?(Hash)
21
+ @options = options
22
+ validate_options
23
+ end
24
+
25
+ def self.included(klass)
26
+ Tasks.register(klass)
27
+ end
28
+
29
+ def install_tasks
30
+ raise NotImplementedError
31
+ end
32
+
33
+ def validate_options
34
+ raise OptionError, "gemspec file path is required" unless options[:gemspec]
35
+ raise OptionError, "gemspec file '#{options[:gemspec]}' is not found" unless File.exists?(options[:gemspec])
36
+
37
+ required_options.map(&:to_sym).each do |opt|
38
+ raise OptionError, "#{opt} is required" unless options[opt]
39
+ end
40
+ end
41
+
42
+ def logger
43
+ ::Logger.new(STDERR)
44
+ end
45
+
46
+ def gemspec_path
47
+ Pathname.new(File.expand_path(options[:gemspec]))
48
+ end
49
+
50
+ def root_dir
51
+ gemspec_path.dirname
52
+ end
53
+
54
+ def gemfiles_dir
55
+ root_dir.join("gemfiles")
56
+ end
57
+
58
+ def required_options
59
+ [] # Implement this in subclass if needed
60
+ end
61
+
62
+ def embulk_tags
63
+ JSON.parse(open("https://api.github.com/repos/embulk/embulk/tags").read)
64
+ end
65
+
66
+ def embulk_versions
67
+ embulk_tags.map{|tag| Gem::Version.new(tag["name"][/v(.*)/, 1])}.sort
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,121 @@
1
+ require "everyleaf/embulk_helper/tasks/common"
2
+
3
+ module Everyleaf
4
+ module EmbulkHelper
5
+ module Tasks
6
+ module Generator
7
+ class Changelog
8
+ include Tasks::Common
9
+
10
+ DEFAULT_CHANGELOG_TEMPLATE = "changelog.erb".freeze
11
+
12
+ def install_tasks
13
+ namespace :generate do
14
+ desc "Generate chengelog then bump version"
15
+ task :prepare_release => [:changelog, :bump_version]
16
+
17
+ desc "Generate CHANGELOG.md from previous release"
18
+ task :changelog do
19
+ changelog
20
+ end
21
+
22
+ desc "Bump version. UP=major to do major version up, UP=minor, UP=patch(default) so on."
23
+ task :bump_version do
24
+ bump_version
25
+ update_gemfile_lock
26
+ end
27
+ end
28
+ end
29
+
30
+ def changelog
31
+ content = new_changelog
32
+ File.open(changelog_path, "w") do |f|
33
+ f.write content
34
+ end
35
+ end
36
+
37
+ def bump_version
38
+ logger.info "Version bump '#{current_version}' to '#{next_version}'"
39
+ old_content = gemspec_path.read
40
+ new_content = old_content.gsub(/(spec\.version += *)".*?"/, %Q!\\1"#{next_version}"!)
41
+ File.open(gemspec_path, "w") do |f|
42
+ f.write new_content
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def required_options
49
+ %w(github_name)
50
+ end
51
+
52
+ def current_version
53
+ Gem::Version.new(gemspec_path.read[/spec\.version += *"([0-9]+\.[0-9]+\.[0-9]+)"/, 1])
54
+ end
55
+
56
+ def next_version
57
+ major, minor, patch = current_version.segments
58
+ ver = case version_target
59
+ when "patch"
60
+ [major, minor, patch + 1].join(".")
61
+ when "minor"
62
+ [major, minor + 1, 0].join(".")
63
+ when "major"
64
+ [major + 1, 0, 0].join(".")
65
+ end
66
+
67
+ Gem::Version.new(ver)
68
+ end
69
+
70
+ def version_target
71
+ ENV["UP"] || options[:version_target] || "patch"
72
+ end
73
+
74
+ def update_gemfile_lock
75
+ system("bundle install")
76
+ end
77
+
78
+ def github_name
79
+ options[:github_name]
80
+ end
81
+
82
+ def pull_request_numbers
83
+ sync_git_repo
84
+ `git log v#{old_version}..origin/master --oneline`.scan(/#[0-9]+/).map do |num_with_hash|
85
+ num_with_hash[/[0-9]+/]
86
+ end
87
+ end
88
+
89
+ def pull_request_info(number)
90
+ body = open("https://api.github.com/repos/#{github_name}/issues/#{number}").read
91
+ JSON.parse(body)
92
+ end
93
+
94
+ def changes
95
+ pull_request_numbers.map do |number|
96
+ payload = pull_request_info(number)
97
+ "* [] #{payload["title"]} [##{number}](https://github.com/#{github_name}/pull/#{number})"
98
+ end
99
+ end
100
+
101
+ def new_changelog
102
+ <<-HEADER
103
+ ## #{next_version} - #{Time.now.strftime("%Y-%m-%d")}
104
+ #{changes.join("\n")}
105
+
106
+ #{changelog_path.read.chomp}
107
+ HEADER
108
+ end
109
+
110
+ def sync_git_repo
111
+ system('git fetch --all')
112
+ end
113
+
114
+ def changelog_path
115
+ root_dir.join("CHANGELOG.md")
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,79 @@
1
+ require "everyleaf/embulk_helper/tasks/common"
2
+
3
+ module Everyleaf
4
+ module EmbulkHelper
5
+ module Tasks
6
+ module Generator
7
+ class Gemfiles
8
+ include Tasks::Common
9
+
10
+ DEFAULT_EMBULK_GEMFILE_TEMPLATE = "gemfiles/template.erb".freeze
11
+
12
+ def install_tasks
13
+ namespace :generate do
14
+ desc "Generate gemfiles to test this plugin with released Embulk versions (since MIN_VERSION)"
15
+ task :gemfiles do
16
+ gemfiles
17
+ end
18
+ end
19
+ end
20
+
21
+ def gemfiles
22
+ logger.info "Generate Embulk gemfiles from '#{min_version}' to latest"
23
+ init
24
+ create_gemfiles
25
+ logger.info "Updated Gemfiles '#{min_version}' to '#{embulk_versions.max}'"
26
+ end
27
+
28
+ private
29
+
30
+ def init
31
+ FileUtils.mkdir_p File.dirname(gemfile_template_path)
32
+ unless File.exists?(gemfile_template_path)
33
+ logger.info "Generate gemfiles template file (#{gemfile_template_path})"
34
+ File.open(gemfile_template_path, "w") do |f|
35
+ f.write initial_template
36
+ end
37
+ end
38
+ end
39
+
40
+ def initial_template
41
+ <<-ERB
42
+ source 'https://rubygems.org/'
43
+ gemspec :path => '#{File.dirname(gemspec_path)}'
44
+
45
+ gem "embulk", "<%= version %>"
46
+ ERB
47
+ end
48
+
49
+ def create_gemfiles
50
+ FileUtils.mkdir_p(gemfiles_dir)
51
+
52
+ Dir[gemfiles_dir.join("embulk-*")].each{|f| File.unlink(f)}
53
+
54
+ embulk_versions.each do |version|
55
+ next if version < min_version
56
+ create_gemfile(version)
57
+ end
58
+ create_gemfile("> #{min_version}", "latest")
59
+ end
60
+
61
+ def create_gemfile(version, name = nil)
62
+ erb = ERB.new(gemfile_template_path.read)
63
+ File.open(gemfiles_dir.join("embulk-#{name || version}"), "w") do |f|
64
+ f.write erb.result(binding())
65
+ end
66
+ end
67
+
68
+ def min_version
69
+ Gem::Version.new(ENV["MIN_VERSION"] || options[:min_version] || "0.0.1")
70
+ end
71
+
72
+ def gemfile_template_path
73
+ root_dir.join(options[:gemfile_template] || DEFAULT_EMBULK_GEMFILE_TEMPLATE)
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,73 @@
1
+ require "everyleaf/embulk_helper/tasks/common"
2
+
3
+ module Everyleaf
4
+ module EmbulkHelper
5
+ module Tasks
6
+ module Generator
7
+ class Travis
8
+ include Tasks::Common
9
+
10
+ DEFAULT_TRAVIS_YML_TEMPLATE = ".travis.yml.erb".freeze
11
+
12
+ def install_tasks
13
+ namespace :generate do
14
+ desc "Generate .travis.yml with gemfiles"
15
+ task :travis do
16
+ travis
17
+ end
18
+ end
19
+ end
20
+
21
+ def travis
22
+ init
23
+ create_travis_yml
24
+ logger.info "Updated .travis.yml"
25
+ end
26
+
27
+ private
28
+
29
+ def init
30
+ FileUtils.mkdir_p File.dirname(travis_yml_template_path)
31
+ unless File.exists?(travis_yml_template_path)
32
+ logger.info "Generate travis.yml template (#{travis_yml_template_path})"
33
+ File.open(travis_yml_template_path, "w") do |f|
34
+ f.write initial_template
35
+ end
36
+ end
37
+ end
38
+
39
+ def initial_template
40
+ <<-YML
41
+ language: ruby
42
+ rvm:
43
+ - jruby-19mode
44
+ jdk:
45
+ - oraclejdk8
46
+
47
+ gemfile:
48
+ <% versions.each do |file| -%>
49
+ - gemfiles/<%= file %>
50
+ <% end -%>
51
+ YML
52
+ end
53
+
54
+ def travis_yml_template_path
55
+ root_dir.join(options[:travis_yml_template] || DEFAULT_TRAVIS_YML_TEMPLATE)
56
+ end
57
+
58
+ def create_travis_yml
59
+ erb = ERB.new(travis_yml_template_path.read, nil, "-")
60
+ versions = gemfiles.map(&:basename)
61
+ File.open(root_dir.join(".travis.yml"), "w") do |f|
62
+ f.puts erb.result(binding())
63
+ end
64
+ end
65
+
66
+ def gemfiles
67
+ Pathname.glob(gemfiles_dir.join("embulk-*"))
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,8 @@
1
+ module Everyleaf
2
+ module EmbulkHelper
3
+ module Tasks
4
+ module Generator
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,24 @@
1
+ require "everyleaf/embulk_helper/tasks/common"
2
+
3
+ module Everyleaf
4
+ module EmbulkHelper
5
+ module Tasks
6
+ def self.tasks
7
+ @tasks ||= []
8
+ end
9
+
10
+ def self.register(task_class)
11
+ tasks << task_class
12
+ end
13
+
14
+ def self.install(options = {})
15
+ tasks.each do |task_class|
16
+ task_class.new(options).install_tasks
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ dir = File.expand_path("../tasks", __FILE__)
24
+ Dir["#{dir}/**/*.rb"].each{|f| require f}
@@ -0,0 +1,5 @@
1
+ module Everyleaf
2
+ module EmbulkHelper
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require "everyleaf/embulk_helper/version"
2
+
3
+ module Everyleaf
4
+ module EmbulkHelper
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,154 @@
1
+ module Everyleaf
2
+ module EmbulkHelper
3
+ module Tasks
4
+ module Generator
5
+ class TestChangelog < Test::Unit::TestCase
6
+ def setup
7
+ FileUtils.touch(gemspec_path)
8
+
9
+ @task = Changelog.new(options)
10
+ mute_logger(@task)
11
+
12
+ File.open(gemspec_path, "w") do |f|
13
+ f.write <<-SPEC
14
+ spec.version = "0.1.2"
15
+ SPEC
16
+ end
17
+ end
18
+
19
+ def test_task_installed
20
+ Everyleaf::EmbulkHelper::Tasks.install(options)
21
+ tasks = Rake::Task.tasks.find_all do |task|
22
+ %w(generate:prepare_release generate:changelog generate:bump_version).include?(task.name)
23
+ end
24
+ assert_equal(3, tasks.length)
25
+ ensure
26
+ Rake::Task.clear
27
+ end
28
+
29
+ class TestChangelog < self
30
+ def setup
31
+ super
32
+ stub(@task).sync_git_repo {}
33
+ File.open(changelog_path, "w") do |f|
34
+ f.write old_content
35
+ end
36
+ end
37
+
38
+ def test_changelog_content
39
+ stub(@task).changes { [
40
+ "foo",
41
+ "bar",
42
+ ]}
43
+ @task.changelog
44
+
45
+ new_content = changelog_path.read
46
+ assert new_content.include?(old_content)
47
+ assert new_content.include?("foo")
48
+ assert new_content.include?("bar")
49
+ end
50
+
51
+ def test_task_installed
52
+ any_instance_of(Changelog) do |klass|
53
+ mock(klass).changelog
54
+ end
55
+ Tasks.install(options)
56
+ task = Rake::Task.tasks.find {|task| task.name == "generate:changelog"}
57
+ task.execute
58
+ ensure
59
+ Rake::Task.clear
60
+ end
61
+
62
+ private
63
+
64
+ def changelog_path
65
+ @task.root_dir.join("CHANGELOG.md")
66
+ end
67
+
68
+ def old_content
69
+ <<-TXT
70
+ ## 0.0.1 - 1999-12-25
71
+ Merry Xmas!
72
+ TXT
73
+ end
74
+ end
75
+
76
+ class TestBumpVersion < self
77
+ def test_bump_version_task
78
+ any_instance_of(Changelog) do |klass|
79
+ mock(klass).bump_version
80
+ mock(klass).update_gemfile_lock
81
+ end
82
+ Tasks.install(options)
83
+ task = Rake::Task.tasks.find {|task| task.name == "generate:bump_version"}
84
+ task.execute
85
+ ensure
86
+ Rake::Task.clear
87
+ end
88
+
89
+ def test_without_option
90
+ @task = Changelog.new(options)
91
+ mute_logger(@task)
92
+
93
+ @task.bump_version
94
+
95
+ assert_equal(<<-SPEC, gemspec_path.read)
96
+ spec.version = "0.1.3"
97
+ SPEC
98
+ end
99
+
100
+ def test_with_patch
101
+ @task = Changelog.new(options.merge(version_target: "patch"))
102
+ mute_logger(@task)
103
+
104
+ @task.bump_version
105
+
106
+ assert_equal(<<-SPEC, gemspec_path.read)
107
+ spec.version = "0.1.3"
108
+ SPEC
109
+ end
110
+
111
+ def test_with_minor
112
+ @task = Changelog.new(options.merge(version_target: "minor"))
113
+ mute_logger(@task)
114
+
115
+ @task.bump_version
116
+
117
+ assert_equal(<<-SPEC, gemspec_path.read)
118
+ spec.version = "0.2.0"
119
+ SPEC
120
+ end
121
+
122
+ def test_with_major
123
+ @task = Changelog.new(options.merge(version_target: "major"))
124
+ mute_logger(@task)
125
+
126
+ @task.bump_version
127
+
128
+ assert_equal(<<-SPEC, gemspec_path.read)
129
+ spec.version = "1.0.0"
130
+ SPEC
131
+ end
132
+ end
133
+
134
+ private
135
+
136
+ def gemspec_path
137
+ Pathname.new("/tmp/changelog.gemspec")
138
+ end
139
+
140
+ def options
141
+ {
142
+ gemspec: gemspec_path.to_s,
143
+ github_name: "everyleaf/everyleaf-embulk_helper",
144
+ }
145
+ end
146
+
147
+ def mute_logger(task)
148
+ stub(task).logger { ::Logger.new(File::NULL) }
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,111 @@
1
+ module Everyleaf
2
+ module EmbulkHelper
3
+ module Tasks
4
+ module Generator
5
+ class TestGemfiles < Test::Unit::TestCase
6
+ def setup
7
+ FileUtils.touch(gemspec)
8
+
9
+ @task = Gemfiles.new(options)
10
+ mute_logger(@task)
11
+ template = Pathname.new("/tmp/gem.erb")
12
+ stub(@task).gemfile_template_path { template }
13
+ File.open(template, "w") do |f|
14
+ f.write <<-ERB
15
+ gem "embulk", "<%= version %>"
16
+ ERB
17
+ end
18
+ stub(@task).embulk_versions { embulk_versions }
19
+ end
20
+
21
+ class TestMinVersion < self
22
+ def test_without_specified
23
+ @task.gemfiles
24
+ files = Dir["#{@task.root_dir}/gemfiles/embulk-*"]
25
+
26
+ # all versions + latest version
27
+ assert_equal(embulk_versions.length + 1, files.length)
28
+ end
29
+
30
+ def test_0_1_1_with_env
31
+ ENV["MIN_VERSION"] = "0.1.1"
32
+ @task.gemfiles
33
+ files = Dir["#{@task.root_dir}/gemfiles/embulk-*"]
34
+
35
+ # all versions + latest version - 0.1.1
36
+ assert_equal(4, files.length)
37
+ ensure
38
+ ENV.delete("MIN_VERSION")
39
+ end
40
+
41
+ def test_0_1_1_with_options
42
+ opt = options
43
+ stub(self).options { opt[:min_vesion] = "0.1.1"; opt }
44
+ files = Dir["#{@task.root_dir}/gemfiles/embulk-*"]
45
+
46
+ # all versions + latest version - 0.1.1
47
+ assert_equal(4, files.length)
48
+ end
49
+ end
50
+
51
+ class TestContent < self
52
+ def test_content_latest
53
+ @task.gemfiles
54
+ content = @task.root_dir.join("gemfiles/embulk-latest").read
55
+ assert_equal(<<-TXT, content)
56
+ gem "embulk", "> 0.0.1"
57
+ TXT
58
+ end
59
+
60
+ def test_content_0_1_2
61
+ @task.gemfiles
62
+ content = @task.root_dir.join("gemfiles/embulk-0.1.2").read
63
+ assert_equal(<<-TXT, content)
64
+ gem "embulk", "0.1.2"
65
+ TXT
66
+ end
67
+ end
68
+
69
+ def test_task_installed
70
+ Everyleaf::EmbulkHelper::Tasks.install(options)
71
+ gemfiles_task = Rake::Task.tasks.find do |task|
72
+ task.name == "generate:gemfiles"
73
+ end
74
+ assert gemfiles_task
75
+ ensure
76
+ Rake::Task.clear
77
+ end
78
+
79
+ def test_gemfiles_create
80
+ @task.gemfiles
81
+ files = Dir["#{@task.root_dir}/gemfiles/embulk-*"]
82
+
83
+ # each version + latest version
84
+ assert_equal(embulk_versions.length + 1, files.length)
85
+ end
86
+
87
+ private
88
+
89
+ def gemspec
90
+ "/tmp/foo.gemspec"
91
+ end
92
+
93
+ def embulk_versions
94
+ %W(0.1.0 0.1.1 0.1.2 0.2.0).map{|v| Gem::Version.new(v)}
95
+ end
96
+
97
+ def options
98
+ {
99
+ gemspec: gemspec,
100
+ github_name: "everyleaf/everyleaf-embulk_helper",
101
+ }
102
+ end
103
+
104
+ def mute_logger(task)
105
+ stub(task).logger { ::Logger.new(File::NULL) }
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,67 @@
1
+ module Everyleaf
2
+ module EmbulkHelper
3
+ module Tasks
4
+ module Generator
5
+ class TestTravis < Test::Unit::TestCase
6
+ def setup
7
+ FileUtils.touch(gemspec)
8
+
9
+ @task = Travis.new(options)
10
+ mute_logger(@task)
11
+ File.open(template_path, "w") do |f|
12
+ f.write <<-ERB
13
+ <% versions.each do |v| -%>
14
+ - <%= v %>
15
+ <% end -%>
16
+ ERB
17
+ end
18
+ stub(@task).embulk_versions { embulk_versions }
19
+ end
20
+
21
+ def test_task_installed
22
+ Everyleaf::EmbulkHelper::Tasks.install(options)
23
+ travis_task = Rake::Task.tasks.find do |task|
24
+ task.name == "generate:travis"
25
+ end
26
+ assert travis_task
27
+ ensure
28
+ Rake::Task.clear
29
+ end
30
+
31
+ def test_travis_yml_create
32
+ stub(@task).gemfiles { %w(/tmp/foo /tmp/bar).map{|f| Pathname.new(f) } }
33
+ @task.travis
34
+ file = @task.root_dir.join(".travis.yml")
35
+
36
+ assert_equal(<<-YML, file.read)
37
+ - foo
38
+ - bar
39
+ YML
40
+ end
41
+
42
+ private
43
+
44
+ def gemspec
45
+ "/tmp/foo.gemspec"
46
+ end
47
+
48
+ def template_path
49
+ Pathname.new("/tmp/travis.erb")
50
+ end
51
+
52
+ def options
53
+ {
54
+ gemspec: gemspec,
55
+ travis_yml_template: template_path.to_s,
56
+ github_name: "everyleaf/everyleaf-embulk_helper",
57
+ }
58
+ end
59
+
60
+ def mute_logger(task)
61
+ stub(task).logger { ::Logger.new(File::NULL) }
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
data/test/run-test.rb ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
+ lib_dir = File.join(base_dir, "lib")
5
+ test_dir = File.join(base_dir, "test")
6
+
7
+ require "test-unit"
8
+ require "test/unit/rr"
9
+ require "codeclimate-test-reporter"
10
+ require "pry"
11
+
12
+ $LOAD_PATH.unshift(lib_dir)
13
+ $LOAD_PATH.unshift(test_dir)
14
+
15
+ ENV["TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE"] ||= "5000"
16
+
17
+ CodeClimate::TestReporter.start
18
+
19
+ require "everyleaf/embulk_helper/tasks"
20
+
21
+ exit Test::Unit::AutoRunner.run(true, test_dir)
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: everyleaf-embulk_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - yoshihara
8
+ - uu59
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-08-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ name: bundler
21
+ prerelease: false
22
+ type: :development
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.7'
28
+ - !ruby/object:Gem::Dependency
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ name: rake
35
+ prerelease: false
36
+ type: :development
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ name: test-unit
49
+ prerelease: false
50
+ type: :development
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ name: test-unit-rr
63
+ prerelease: false
64
+ type: :development
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ name: pry
77
+ prerelease: false
78
+ type: :development
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ name: codeclimate-test-reporter
91
+ prerelease: false
92
+ type: :development
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ description: Add some handy helpers for developing Embulk plugins
99
+ email:
100
+ - h.yoshihara@everyleaf.com
101
+ - k@uu59.org
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - .travis.yml
107
+ - CHANGELOG.md
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - Rakefile.test
114
+ - everyleaf-embulk_helper.gemspec
115
+ - lib/everyleaf/embulk_helper.rb
116
+ - lib/everyleaf/embulk_helper/tasks.rb
117
+ - lib/everyleaf/embulk_helper/tasks/common.rb
118
+ - lib/everyleaf/embulk_helper/tasks/generator.rb
119
+ - lib/everyleaf/embulk_helper/tasks/generator/changelog.rb
120
+ - lib/everyleaf/embulk_helper/tasks/generator/gemfiles.rb
121
+ - lib/everyleaf/embulk_helper/tasks/generator/travis.rb
122
+ - lib/everyleaf/embulk_helper/version.rb
123
+ - test/everyleaf/embulk_helper/tasks/generator/test_changelog.rb
124
+ - test/everyleaf/embulk_helper/tasks/generator/test_gemfiles.rb
125
+ - test/everyleaf/embulk_helper/tasks/generator/test_travis.rb
126
+ - test/run-test.rb
127
+ homepage: https://github.com/everyleaf/everyleaf-embulk_helper
128
+ licenses:
129
+ - MIT
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.4.6
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: Add some handy helpers for developing Embulk plugins
151
+ test_files:
152
+ - test/everyleaf/embulk_helper/tasks/generator/test_changelog.rb
153
+ - test/everyleaf/embulk_helper/tasks/generator/test_gemfiles.rb
154
+ - test/everyleaf/embulk_helper/tasks/generator/test_travis.rb
155
+ - test/run-test.rb