rake-release 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76709329a0abc045a218bd13ee7ee291d5ccdcda
4
- data.tar.gz: 8abd79fb3c9714e64bf8b9e85793c74cd2bd32b3
3
+ metadata.gz: 9b765b7e4a6fa595d55c6eb83b41562b32624fce
4
+ data.tar.gz: 672abe5d9a19fe73061a7bdd46148222b4677b17
5
5
  SHA512:
6
- metadata.gz: 3e7cb2a395fd5098ad5355652e84f1da6e581586b0f272a509fe1db2657ce5e33268695cec399f02744178a64e74917dbbe1990b16f99ffcabf4cf9d8cf53a31
7
- data.tar.gz: 16f8eeb5f2627b524dcb1a4c5e2a634efe2c4a2e02a798da3215b4bdf2ebc6c91a617187ea2b5f942690730c5ffb933c483862b6265de6566d29ac74221bd747
6
+ metadata.gz: d1418a8e642439637a45a2d52514519d052bd190451962d4d94041b03529b34782a44c3914ee8a66d6ea8c40acc5e80fdc1c1ab3dcf78c790c0d9026ab13936d
7
+ data.tar.gz: 427aec58e984d2ed8bbba388e806077e05fab3f6869ca4ef229b24c9976384e95b7effa2d0a45a23b419a20c261aabc2aee91995a749936e0cb2f88560a66524
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/examples.txt
10
+ /test/tmp/
11
+ /test/version_tmp/
12
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rake-release.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Jan Graichen
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Rake::Release
2
+
3
+ Customized fork for bundlers gem task helpers.
4
+
5
+ Automatically detects multiple gemspecs and protect from releasing code not matching git version tag.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rake-release'
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ Simply require in Rakefile:
18
+
19
+ ```ruby
20
+ require 'rake/release'
21
+ ```
22
+
23
+ Check with `rake -D`:
24
+
25
+ ```
26
+ rake build
27
+ Build rake-release-0.2.1.gem.gem into the pkg directory.
28
+
29
+ rake install
30
+ Build and install rake-release-0.2.1.gem into system gems.
31
+
32
+ rake install:local
33
+ Build and install rake-release-0.2.1.gem into system gems without network access.
34
+
35
+ rake release[remote]
36
+ Create and push tag v0.2.1, build gem and publish to rubygems.org.
37
+ ```
38
+
39
+ # License
40
+
41
+ MIT
@@ -0,0 +1 @@
1
+ require 'rake/release'
@@ -0,0 +1,34 @@
1
+ require 'rake/release/spec'
2
+ require 'rake/release/task'
3
+
4
+ require 'bundler'
5
+ require 'pathname'
6
+
7
+ module Rake
8
+ module Release
9
+ class << self
10
+ def pwd
11
+ @pwd ||= Pathname.new Bundler::SharedHelpers.pwd
12
+ end
13
+
14
+ def ui
15
+ @ui ||= Bundler::UI::Shell.new
16
+ end
17
+
18
+ def autodetect!
19
+ specs = Spec.scan pwd.join '{*/*/,*/,}*.gemspec'
20
+ specs.uniq! {|spec| spec.name }
21
+
22
+ if specs.size == 1
23
+ Task.new specs.first
24
+ else
25
+ specs.each do |spec|
26
+ Task.new spec, namespace: spec.name
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ autodetect!
33
+ end
34
+ end
@@ -0,0 +1,89 @@
1
+ require 'forwardable'
2
+ require 'uri'
3
+
4
+ module Rake
5
+ module Release
6
+ class Spec
7
+ extend Forwardable
8
+
9
+ EMPTY_STR = ''.freeze
10
+
11
+ delegate name: :@gemspec
12
+ delegate version: :@gemspec
13
+
14
+ attr_reader :base
15
+ attr_reader :gemspec
16
+ attr_reader :gemspec_path
17
+
18
+ attr_accessor :namespace
19
+
20
+ def initialize(path, namespace: nil)
21
+ path = Release.pwd.join(path.to_s).expand_path
22
+
23
+ if path.directory?
24
+ @base = path
25
+
26
+ gemspecs = Dir[@base.join('*.gemspec')]
27
+
28
+ if gemspecs.size != 1
29
+ raise 'Unable to determine gemspec file.'
30
+ end
31
+
32
+ @gemspec_path = Pathname.new gemspecs.first
33
+ else
34
+ @base = path.parent
35
+ @gemspec_path = path
36
+ end
37
+
38
+ @gemspec = Bundler.load_gemspec @gemspec_path
39
+
40
+ raise RuntimeError.new 'Cannot load gemspec' unless @gemspec
41
+ end
42
+
43
+ def push_host
44
+ @push_host ||= begin
45
+ if @gemspec.metadata['allowed_push_host'].to_s.empty?
46
+ @push_host = URI 'https://rubygems.org'
47
+ else
48
+ @push_host = URI @gemspec.metadata['allowed_push_host']
49
+ end
50
+ end
51
+ end
52
+
53
+ def push_host_name
54
+ push_host.host.to_s
55
+ end
56
+
57
+ def pkg_path
58
+ @pkg_path ||= base.join 'pkg'
59
+ end
60
+
61
+ def pkg_file_name
62
+ @pkg_file_name ||= "#{name}-#{version}.gem"
63
+ end
64
+
65
+ def pkg_file_path
66
+ @pkg_file_path ||= pkg_path.join pkg_file_name
67
+ end
68
+
69
+ def version_tag
70
+ "v#{version}"
71
+ end
72
+
73
+ class << self
74
+ def load(*args, &block)
75
+ new(*args, &block)
76
+ rescue
77
+ nil
78
+ end
79
+
80
+ def scan(path = Release.pwd.join('*.gemspec'))
81
+ Pathname
82
+ .glob(path)
83
+ .map {|path| Rake::Release::Spec.load path }
84
+ .reject {|spec| spec.nil? }
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,212 @@
1
+ require 'bundler/vendored_thor' unless defined?(Thor)
2
+
3
+ require 'open3'
4
+ require 'bundler'
5
+ require 'pathname'
6
+ require 'fileutils'
7
+
8
+ require 'rake/release/spec'
9
+
10
+ module Rake
11
+ module Release
12
+ class Task
13
+ include Rake::DSL
14
+
15
+ def initialize(spec = nil, **kwargs, &block)
16
+ @spec = spec || Rake::Release::Spec.new(**kwargs, &block)
17
+
18
+ namespace = @spec.namespace || kwargs[:namespace]
19
+
20
+ if namespace
21
+ send(:namespace, namespace) { setup }
22
+ else
23
+ setup
24
+ end
25
+ end
26
+
27
+ protected
28
+
29
+ def setup
30
+ desc <<-EOF.strip
31
+ Build #{@spec.pkg_file_name}.gem into the pkg directory.
32
+ EOF
33
+ task(:build) { build }
34
+
35
+ desc <<-EOF.strip
36
+ Build and install #{@spec.pkg_file_name} into system gems.
37
+ EOF
38
+ task(install: [:build]) { install }
39
+
40
+ desc <<-EOF.strip
41
+ Build and install #{@spec.pkg_file_name} into system gems without network access.
42
+ EOF
43
+ task('install:local' => [:build]) { install local: true }
44
+
45
+ desc <<-EOF.strip
46
+ Create and push tag #{@spec.version_tag}, build gem and publish to #{@spec.push_host_name}.
47
+ EOF
48
+ task :release, [:remote] => %w(build release:push release:publish)
49
+
50
+ task 'release:guard:clean' do
51
+ guard_clean
52
+ end
53
+
54
+ task 'release:guard:tag' do
55
+ guard_tag
56
+ end
57
+
58
+ task 'release:push', [:remote] => %w(release:guard:clean) do |_, args|
59
+ tag_version { git_push(args[:remote]) } unless already_tagged?
60
+ end
61
+
62
+ task 'release:publish' => %w(release:guard:tag) do
63
+ publish if publish?
64
+ end
65
+ end
66
+
67
+ def guard_clean
68
+ return if clean? && committed?
69
+ raise 'There are files that need to be committed first.'
70
+ end
71
+
72
+ def guard_tag
73
+ out, ret = sh! 'git', 'tag', '--points-at', 'HEAD'
74
+
75
+ if not out.split("\n").include? @spec.version_tag
76
+ raise "Tag #{@spec.version_tag} does not point to current HEAD. Cannot release wrong code."
77
+ end
78
+ end
79
+
80
+ def build
81
+ @spec.pkg_path.mkpath
82
+
83
+ sh! 'gem', 'build', '-V', @spec.gemspec_path
84
+
85
+ @spec.pkg_path.mkpath
86
+ FileUtils.mv @spec.pkg_file_name, @spec.pkg_path.join(@spec.pkg_file_name)
87
+
88
+ Release.ui.confirm "#{@spec.name} #{@spec.version} built to #{@spec.pkg_path}."
89
+ end
90
+
91
+ def install(local: false)
92
+ cmd = %w(gem install) + [@spec.pkg_file_path]
93
+ cmd << '--local' if local
94
+
95
+ sh! *cmd
96
+
97
+ Release.ui.confirm "#{@spec.name} (#{@spec.version}) installed."
98
+ end
99
+
100
+ def publish
101
+ cmd = %w(gem push)
102
+ cmd << @spec.pkg_file_path
103
+ cmd << '--host'
104
+ cmd << @spec.push_host
105
+
106
+ sh! *cmd
107
+
108
+ Release.ui.confirm "Pushed #{@spec.pkg_file_name} to #{@spec.push_host}"
109
+ end
110
+
111
+ def git_clean
112
+ clean? && committed? || raise("There are files that need to be committed first.")
113
+ end
114
+
115
+ def clean?
116
+ out, ret = sh 'git', 'diff', '--exit-code'
117
+
118
+ ret == 0
119
+ end
120
+
121
+ def committed?
122
+ out, ret = sh 'git', 'diff-index', '--quiet', '--cached', 'HEAD'
123
+
124
+ ret == 0
125
+ end
126
+
127
+ def tag_version
128
+ sh! 'git', 'tag', '-a', '-m', "Version #{@spec.version}", @spec.version_tag
129
+
130
+ Release.ui.confirm "Tagged #{@spec.version_tag}."
131
+
132
+ yield if block_given?
133
+ rescue
134
+ Release.ui.error "Untagging #{@spec.version_tag} due to error."
135
+
136
+ sh! 'git', 'tag', '-d', @spec.version_tag
137
+
138
+ raise
139
+ end
140
+
141
+ def already_tagged?
142
+ out, ret = sh 'git', 'tag'
143
+
144
+ unless out.split(/\n/).include? @spec.version_tag
145
+ return false
146
+ end
147
+
148
+ Release.ui.confirm "Tag #{@spec.version_tag} has already been created."
149
+
150
+ true
151
+ end
152
+
153
+ def git_push(remote)
154
+ cmd = %w(git push --quiet)
155
+
156
+ if not remote.to_s.empty?
157
+ cmd << remote
158
+ end
159
+
160
+ sh! *cmd
161
+ sh! *cmd, '--tags'
162
+
163
+ Release.ui.confirm 'Pushed git commits and tags.'
164
+ end
165
+
166
+ def publish?
167
+ ! %w(n no nil false off 0).include?(ENV["gem_push"].to_s.downcase)
168
+ end
169
+
170
+ def sh!(*cmd, **kwargs, &block)
171
+ cmd = cmd.flatten.map(&:to_s)
172
+
173
+ out, ret = sh(*cmd, **kwargs, &block)
174
+
175
+ if ret != 0
176
+ raise RuntimeError.new <<-EOS.gsub /^\s*\.?/, ''
177
+ Running `#{cmd}` failed, exit code: #{ret}
178
+ .#{out.gsub(/\n/, "\n ")}
179
+ EOS
180
+ end
181
+
182
+ [out, ret]
183
+ end
184
+
185
+ def sh(*cmd, chdir: @spec.base, raise_error: true, &block)
186
+ cmd = cmd.flatten.map(&:to_s)
187
+
188
+ Release.ui.debug cmd
189
+
190
+ Open3.popen2(*cmd, chdir: chdir) do |stdin, out, t|
191
+ stdin.close
192
+
193
+ status = t.value
194
+
195
+ [out.read, status.exitstatus]
196
+ end
197
+ end
198
+
199
+ class << self
200
+ def load_all(dir = Release.pwd)
201
+ specs = Spec.scan dir
202
+
203
+ if block_given?
204
+ specs.each(&Proc.new)
205
+ end
206
+
207
+ specs.each {|spec| Task.new spec }
208
+ end
209
+ end
210
+ end
211
+ end
212
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'rake-release'
5
+ spec.version = '0.3.1'
6
+ spec.authors = ['Jan Graichen']
7
+ spec.email = ['jgraichen@altimos.de']
8
+ spec.licenses = ['MIT']
9
+
10
+ spec.summary = %q{Configurable fork of bundlers release tasks.}
11
+ spec.description = %q{Configurable fork of bundlers release tasks.}
12
+ spec.homepage = 'https://github.com/jgraichen/rake-release'
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.require_paths = %w(lib)
17
+
18
+ spec.add_dependency 'bundler', '~> 1.11'
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.11'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rake/release"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rake-release
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-20 00:00:00.000000000 Z
11
+ date: 2016-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,7 +58,18 @@ email:
58
58
  executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
- files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE
65
+ - README.md
66
+ - Rakefile
67
+ - lib/rake/release.rb
68
+ - lib/rake/release/spec.rb
69
+ - lib/rake/release/task.rb
70
+ - rake-release.gemspec
71
+ - scripts/console
72
+ - scripts/setup
62
73
  homepage: https://github.com/jgraichen/rake-release
63
74
  licenses:
64
75
  - MIT