hoe-travis 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +8 -0
- data/.gemtest +0 -0
- data/History.txt +5 -0
- data/Manifest.txt +7 -0
- data/README.rdoc +115 -0
- data/Rakefile +24 -0
- data/lib/hoe/travis.rb +537 -0
- data/test/test_hoe_travis.rb +215 -0
- data.tar.gz.sig +0 -0
- metadata +165 -0
- metadata.gz.sig +0 -0
data/.autotest
ADDED
data/.gemtest
ADDED
File without changes
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
= hoe-travis
|
2
|
+
|
3
|
+
home :: https://github.com/drbrain/hoe-travis
|
4
|
+
rdoc :: http://docs.seattlerb.org/hoe-travis
|
5
|
+
bugs :: https://github.com/drbrain/hoe-travis/issues
|
6
|
+
|
7
|
+
== Description
|
8
|
+
|
9
|
+
hoe-travis is a Hoe plugin that allows your gem to gain maximum benefit from
|
10
|
+
http://travis-ci.org. The plugin contains a <code>.travis.yml</code>
|
11
|
+
generator and a pre-defined rake task which runs the tests and ensures your
|
12
|
+
manifest file is correct.
|
13
|
+
|
14
|
+
With hoe-travis it is easy to add additional checks. Custom checks can be
|
15
|
+
easily verified locally by simply running a rake task instead of committing
|
16
|
+
and pushing a change, waiting for travis to run your tests, then trying a new
|
17
|
+
commit if you didn't fix the problem.
|
18
|
+
|
19
|
+
== Features
|
20
|
+
|
21
|
+
* .travis.yml generation task
|
22
|
+
* Pre-defined rake tasks which are run by travis-ci
|
23
|
+
* Easy to hook up rake tasks for additional travis-ci setup or checks
|
24
|
+
|
25
|
+
== Getting Started
|
26
|
+
|
27
|
+
If you're not already using Hoe with your project, see: http://docs.seattlerb.org/hoe/Hoe.pdf
|
28
|
+
|
29
|
+
To get started with hoe-travis, first install it:
|
30
|
+
|
31
|
+
sudo gem install hoe-travis
|
32
|
+
|
33
|
+
Then add hoe-travis as a plugin to your Rakefile:
|
34
|
+
|
35
|
+
Hoe.plugin :travis
|
36
|
+
|
37
|
+
Then generate a .travis.yml
|
38
|
+
|
39
|
+
$ rake travis:generate
|
40
|
+
|
41
|
+
This will bring up your EDITOR with your travis.yml for any desired tweaks.
|
42
|
+
Save the file when you're done, then check in your .travis.yml. For further
|
43
|
+
details of how the configuration is generated see Hoe::Travis@Setup and
|
44
|
+
Hoe::Travis@Hoe+Configuration.
|
45
|
+
|
46
|
+
(If you don't have the EDITOR environment variable set to your favorite
|
47
|
+
editor, please do so. Note that some editors may need extra flags to wait for
|
48
|
+
files to be edited. For MacVIM, <code>export EDITOR="mvim
|
49
|
+
--remote-wait"</code> will wait for the file to be closed before returning.)
|
50
|
+
|
51
|
+
If you would like to make future changes to your .travis.yml you can run:
|
52
|
+
|
53
|
+
$ rake travis:edit
|
54
|
+
|
55
|
+
Which, like <code>travis:generate</code>, will bring up your EDITOR with your
|
56
|
+
.travis.yml. When you've saved the file the changes will be checked by
|
57
|
+
travis-lint before writing back to .travis.yml and give you a chance to
|
58
|
+
correct them.
|
59
|
+
|
60
|
+
If you've edited your .travis.yml by hand you can run:
|
61
|
+
|
62
|
+
$ rake travis:check
|
63
|
+
|
64
|
+
to check it.
|
65
|
+
|
66
|
+
Testing your travis-ci setup is easy with hoe-travis. You can run:
|
67
|
+
|
68
|
+
$ rake travis
|
69
|
+
|
70
|
+
to run the same checks travis-ci will. By default this includes running the
|
71
|
+
tests and ensuring the Manifest.txt file is complete. There is also the
|
72
|
+
before script:
|
73
|
+
|
74
|
+
$ rake travis:before
|
75
|
+
|
76
|
+
Which will run the setup tasks needed for your project.
|
77
|
+
|
78
|
+
You can also enable and disable travis-ci using <code>rake
|
79
|
+
travis:enable</code> and <code>rake travis:disable</code>. See
|
80
|
+
Hoe::Travis@Setup for details.
|
81
|
+
|
82
|
+
== Developers
|
83
|
+
|
84
|
+
After checking out the source, run:
|
85
|
+
|
86
|
+
$ rake newb
|
87
|
+
|
88
|
+
This task will install any missing dependencies, run the tests/specs,
|
89
|
+
and generate the RDoc.
|
90
|
+
|
91
|
+
== License
|
92
|
+
|
93
|
+
(The MIT License)
|
94
|
+
|
95
|
+
Copyright (c) Eric Hodel
|
96
|
+
|
97
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
98
|
+
a copy of this software and associated documentation files (the
|
99
|
+
'Software'), to deal in the Software without restriction, including
|
100
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
101
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
102
|
+
permit persons to whom the Software is furnished to do so, subject to
|
103
|
+
the following conditions:
|
104
|
+
|
105
|
+
The above copyright notice and this permission notice shall be
|
106
|
+
included in all copies or substantial portions of the Software.
|
107
|
+
|
108
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
109
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
110
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
111
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
112
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
113
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
114
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
115
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
# Bootstrap for travis-ci
|
4
|
+
$LOAD_PATH.unshift 'lib'
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'hoe'
|
8
|
+
|
9
|
+
Hoe.plugin :minitest
|
10
|
+
Hoe.plugin :git
|
11
|
+
Hoe.plugin :travis
|
12
|
+
|
13
|
+
Hoe.spec 'hoe-travis' do
|
14
|
+
developer 'Eric Hodel', 'drbrain@segment7.net'
|
15
|
+
|
16
|
+
rdoc_locations << 'docs.seattlerb.org:/data/www/docs.seattlerb.org/hoe-travis/'
|
17
|
+
|
18
|
+
self.extra_deps << ['travis-lint', '~> 1.2']
|
19
|
+
# this explicit dependency is so `gem install hoe-travis` will fetch
|
20
|
+
# hoe and rake, simplifying the before_script command list
|
21
|
+
self.extra_deps << ['hoe', '~> 2.14']
|
22
|
+
end
|
23
|
+
|
24
|
+
# vim: syntax=ruby
|
data/lib/hoe/travis.rb
ADDED
@@ -0,0 +1,537 @@
|
|
1
|
+
require 'hoe'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'net/http'
|
4
|
+
require 'net/https' # for Ruby 1.8
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
##
|
8
|
+
# The travis plugin for Hoe manages your .travis.yml file for you in a clean
|
9
|
+
# and extensible way you can use across projects or by through integration
|
10
|
+
# with other Hoe plugins.
|
11
|
+
#
|
12
|
+
# == Setup
|
13
|
+
#
|
14
|
+
# The travis plugin can be used without this setup. By following these
|
15
|
+
# instructions you can enable and disable a travis-ci hook for your ruby
|
16
|
+
# projects from rake through <code>rake travis:enable</code> and <code>rake
|
17
|
+
# travis:disable</code>.
|
18
|
+
#
|
19
|
+
# === Github API access
|
20
|
+
#
|
21
|
+
# Set your github username and password in your ~/.gitconfig:
|
22
|
+
#
|
23
|
+
# git config --global github.user username
|
24
|
+
# git config --global github.password password
|
25
|
+
# chmod 600 ~/.gitconfig
|
26
|
+
#
|
27
|
+
# === Travis token
|
28
|
+
#
|
29
|
+
# As of this writing there isn't an easy way to retrieve the travis token
|
30
|
+
# programmatically. You can find your travis token at
|
31
|
+
# http://travis-ci.org/profile underneath your github username and email
|
32
|
+
# address.
|
33
|
+
#
|
34
|
+
# To set this in your hoerc run <code>rake config_hoe</code> and edit the
|
35
|
+
# "token:" entry.
|
36
|
+
#
|
37
|
+
# == Tasks
|
38
|
+
#
|
39
|
+
# You can extend the following tasks in your Rakefile or Hoe plugins to add
|
40
|
+
# extra checks to travis-ci.
|
41
|
+
#
|
42
|
+
# travis::
|
43
|
+
# Run by travis-ci. Defaults to running your tests and checking your
|
44
|
+
# manifest file. You can run this locally to check what travis-ci will do.
|
45
|
+
#
|
46
|
+
# travis:before::
|
47
|
+
# Runs as the before_script on travis-ci. Defaults to installing your
|
48
|
+
# development dependencies.
|
49
|
+
#
|
50
|
+
# travis:check::
|
51
|
+
# Runs travis-lint against your .travis.yml.
|
52
|
+
#
|
53
|
+
# travis:edit::
|
54
|
+
# Pulls up your .travis.yml in your EDITOR and runs travis-lint upon saving.
|
55
|
+
# Does not allow you to save a bad .travis.yml.
|
56
|
+
#
|
57
|
+
# travis:generate::
|
58
|
+
# Generates a .travis.yml based on your Hoe spec and .hoerc then brings it
|
59
|
+
# up in your EDITOR and runs travis-lint upon saving. Does not allow you to
|
60
|
+
# save a bad .travis.yml.
|
61
|
+
#
|
62
|
+
# travis:enable::
|
63
|
+
# Enables the travis hook on github.com. Requires further setup as
|
64
|
+
# described below.
|
65
|
+
#
|
66
|
+
# travis:disable::
|
67
|
+
# Disables the travis hook on github.com. Requires further setup as
|
68
|
+
# described below.
|
69
|
+
#
|
70
|
+
# travis:force::
|
71
|
+
# Forces a travis-ci run, equivalent to clicking the "test" button on the
|
72
|
+
# travis-ci hook page.
|
73
|
+
#
|
74
|
+
# == Hoe Configuration
|
75
|
+
#
|
76
|
+
# The Hoe configuration is used to generate the .travis.yml. After you've
|
77
|
+
# generated a .travis.yml you may any changes you wish to it and the following
|
78
|
+
# defaults will not apply. If you have multiple projects, setting up a common
|
79
|
+
# custom configuration in ~/.hoerc can save you time.
|
80
|
+
#
|
81
|
+
# The following default configuration options are provided under the "travis"
|
82
|
+
# key of the Hoe configuration (accessible from Hoe#with_config):
|
83
|
+
#
|
84
|
+
# before_script::
|
85
|
+
# Array of commands run before the test script. Defaults to installing
|
86
|
+
# hoe-travis and its dependencies (rake and hoe) followed by running the
|
87
|
+
# travis:before rake task.
|
88
|
+
#
|
89
|
+
# script::
|
90
|
+
# Runs the travis rake task.
|
91
|
+
#
|
92
|
+
# token::
|
93
|
+
# Your travis-ci token. See @Setup above
|
94
|
+
#
|
95
|
+
# versions::
|
96
|
+
# The versions of ruby used to run your tests. Note that if you have
|
97
|
+
# multiruby installed, your installed versions will be preferred over the
|
98
|
+
# defaults of ruby 1.8.7, 1.9.2 and 1.9.3.
|
99
|
+
#
|
100
|
+
# In your .hoerc you may provide a "notifications" key such as:
|
101
|
+
#
|
102
|
+
# travis:
|
103
|
+
# notifications:
|
104
|
+
# irc: "irc.example#your_channel"
|
105
|
+
#
|
106
|
+
# Notifications specified in a .hoerc will override the default email
|
107
|
+
# notifications created from the Hoe spec.
|
108
|
+
|
109
|
+
module Hoe::Travis
|
110
|
+
|
111
|
+
##
|
112
|
+
# This version of Hoe::Travis
|
113
|
+
|
114
|
+
VERSION = '1.0'
|
115
|
+
|
116
|
+
YAML_EXCEPTIONS = if defined?(Psych) then # :nodoc:
|
117
|
+
if Psych.const_defined? :Exception then
|
118
|
+
[Psych::SyntaxError] # Ruby 1.9.2
|
119
|
+
else
|
120
|
+
[Psych::Exception, Psych::SyntaxError]
|
121
|
+
end
|
122
|
+
else
|
123
|
+
[YAML::Error]
|
124
|
+
end
|
125
|
+
|
126
|
+
YAML_EXCEPTIONS << ArgumentError
|
127
|
+
|
128
|
+
Hoe::DEFAULT_CONFIG['travis'] = {
|
129
|
+
'before_script' => [
|
130
|
+
'gem install hoe-travis --no-rdoc --no-ri',
|
131
|
+
'rake travis:before',
|
132
|
+
],
|
133
|
+
'script' => 'rake travis',
|
134
|
+
'token' => 'FIX - See: ri Hoe::Travis',
|
135
|
+
'versions' => %w[
|
136
|
+
1.8.7
|
137
|
+
1.9.2
|
138
|
+
1.9.3
|
139
|
+
],
|
140
|
+
}
|
141
|
+
|
142
|
+
def initialize_travis # :nodoc:
|
143
|
+
@github_api = URI 'https://api.github.com'
|
144
|
+
end
|
145
|
+
|
146
|
+
##
|
147
|
+
# Adds travis tasks to rake
|
148
|
+
|
149
|
+
def define_travis_tasks
|
150
|
+
desc "Runs your tests for travis"
|
151
|
+
task :travis => %w[test travis:fake_config check_manifest]
|
152
|
+
|
153
|
+
namespace :travis do
|
154
|
+
desc "Run by travis-ci before your running the default checks"
|
155
|
+
task :before => %w[
|
156
|
+
check_extra_deps
|
157
|
+
install_plugins
|
158
|
+
]
|
159
|
+
|
160
|
+
desc "Runs travis-lint on your .travis.yml"
|
161
|
+
task :check do
|
162
|
+
abort unless check_travis_yml '.travis.yml'
|
163
|
+
end
|
164
|
+
|
165
|
+
desc "Disables the travis-ci hook"
|
166
|
+
task :disable do
|
167
|
+
travis_disable
|
168
|
+
end
|
169
|
+
|
170
|
+
desc "Brings .travis.yml up in your EDITOR then checks it on save"
|
171
|
+
task :edit do
|
172
|
+
Tempfile.open 'travis.yml' do |io|
|
173
|
+
io.write File.read '.travis.yml'
|
174
|
+
io.rewind
|
175
|
+
|
176
|
+
ok = travis_yml_edit io.path
|
177
|
+
|
178
|
+
travis_yml_write io.path if ok
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
desc "Enables the travis-ci hook"
|
183
|
+
task :enable do
|
184
|
+
travis_enable
|
185
|
+
end
|
186
|
+
|
187
|
+
desc "Triggers the travis-ci hook"
|
188
|
+
task :force do
|
189
|
+
travis_force
|
190
|
+
end
|
191
|
+
|
192
|
+
task :fake_config do
|
193
|
+
travis_fake_config
|
194
|
+
end
|
195
|
+
|
196
|
+
desc "Generates a new .travis.yml and allows you to customize it with your EDITOR"
|
197
|
+
task :generate do
|
198
|
+
Tempfile.open 'travis.yml' do |io|
|
199
|
+
io.write travis_yml_generate
|
200
|
+
io.rewind
|
201
|
+
|
202
|
+
ok = travis_yml_edit io.path
|
203
|
+
|
204
|
+
travis_yml_write io.path if ok
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
##
|
211
|
+
# Extracts the travis before_script from your .hoerc
|
212
|
+
|
213
|
+
def travis_before_script
|
214
|
+
with_config { |config, _|
|
215
|
+
config['travis']['before_script'] or
|
216
|
+
Hoe::DEFAULT_CONFIG['travis']['before_script']
|
217
|
+
}
|
218
|
+
end
|
219
|
+
|
220
|
+
##
|
221
|
+
# Disables travis-ci for this repository.
|
222
|
+
|
223
|
+
def travis_disable
|
224
|
+
_, repo, = travis_github_check
|
225
|
+
|
226
|
+
if hook = travis_have_hook?(repo) then
|
227
|
+
travis_edit_hook repo, hook, false if hook['active']
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
##
|
232
|
+
# Edits the travis +hook+ definition for +repo+ (from the github URL) to
|
233
|
+
# +enable+ (default) or disable it.
|
234
|
+
|
235
|
+
def travis_edit_hook repo, hook, enable = true
|
236
|
+
patch = unless Net::HTTP.const_defined? :Patch then
|
237
|
+
# Ruby 1.8
|
238
|
+
Class.new Net::HTTPRequest do |c|
|
239
|
+
c.const_set :METHOD, 'PATCH'
|
240
|
+
c.const_set :REQUEST_HAS_BODY, true
|
241
|
+
c.const_set :RESPONSE_HAS_BODY, true
|
242
|
+
end
|
243
|
+
else
|
244
|
+
Net::HTTP::Patch
|
245
|
+
end
|
246
|
+
|
247
|
+
|
248
|
+
id = hook['id']
|
249
|
+
|
250
|
+
body = {
|
251
|
+
'name' => hook['name'],
|
252
|
+
'active' => enable,
|
253
|
+
'config' => hook['config']
|
254
|
+
}
|
255
|
+
|
256
|
+
travis_github_request "/repos/#{repo}/hooks/#{id}", body, patch
|
257
|
+
end
|
258
|
+
|
259
|
+
##
|
260
|
+
# Enables travis-ci for this repository.
|
261
|
+
|
262
|
+
def travis_enable
|
263
|
+
user, repo, token = travis_github_check
|
264
|
+
|
265
|
+
if hook = travis_have_hook?(repo) then
|
266
|
+
travis_edit_hook repo, hook unless hook['active']
|
267
|
+
else
|
268
|
+
travis_make_hook repo, user, token
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
##
|
273
|
+
# Creates a fake config file for use on travis-ci. Running this with a
|
274
|
+
# pre-existing .hoerc has no effect.
|
275
|
+
|
276
|
+
def travis_fake_config
|
277
|
+
fake_hoerc = File.expand_path '~/.hoerc'
|
278
|
+
|
279
|
+
return if File.exist? fake_hoerc
|
280
|
+
|
281
|
+
config = { 'exclude' => /\.(git|travis)/ }
|
282
|
+
|
283
|
+
open fake_hoerc, 'w' do |io|
|
284
|
+
YAML.dump config, io
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
##
|
289
|
+
# Forces the travis-ci hook
|
290
|
+
|
291
|
+
def travis_force
|
292
|
+
user, repo, token = travis_github_check
|
293
|
+
|
294
|
+
unless hook = travis_have_hook?(repo)
|
295
|
+
hook = travis_make_hook repo, user, token
|
296
|
+
end
|
297
|
+
|
298
|
+
travis_github_request "/repos/#{repo}/hooks/#{hook['id']}/test", {}
|
299
|
+
end
|
300
|
+
|
301
|
+
##
|
302
|
+
# Ensures you have proper setup for editing the github travis hook
|
303
|
+
|
304
|
+
def travis_github_check
|
305
|
+
user = `git config github.user`.chomp
|
306
|
+
abort <<-ABORT unless user
|
307
|
+
Set your github user and token in ~/.gitconfig
|
308
|
+
|
309
|
+
See: ri Hoe::Travis and
|
310
|
+
\thttp://help.github.com/set-your-user-name-email-and-github-token/
|
311
|
+
ABORT
|
312
|
+
|
313
|
+
`git config remote.origin.url` =~ /^git@github\.com:(.*).git$/
|
314
|
+
repo = $1
|
315
|
+
|
316
|
+
abort <<-ABORT unless repo
|
317
|
+
Unable to determine your github repository.
|
318
|
+
|
319
|
+
Expected \"git@github.com:[repo].git\" as your remote origin
|
320
|
+
ABORT
|
321
|
+
|
322
|
+
token = with_config do |config, _|
|
323
|
+
config['travis']['token']
|
324
|
+
end
|
325
|
+
|
326
|
+
abort 'Please set your travis token via `rake config_hoe` - ' \
|
327
|
+
'See: ri Hoe::Travis' if token =~ /FIX/
|
328
|
+
|
329
|
+
return user, repo, token
|
330
|
+
end
|
331
|
+
|
332
|
+
##
|
333
|
+
# Makes a github request at +path+ with an optional +body+ Hash which will
|
334
|
+
# be sent as JSON. The default +method+ without a body is a GET request,
|
335
|
+
# otherwise POST.
|
336
|
+
|
337
|
+
def travis_github_request(path, body = nil,
|
338
|
+
method = body ? Net::HTTP::Post : Net::HTTP::Get)
|
339
|
+
begin
|
340
|
+
require 'json'
|
341
|
+
rescue LoadError => e
|
342
|
+
raise unless e.message.end_with? 'json'
|
343
|
+
|
344
|
+
abort 'Please gem install json like modern ruby versions have'
|
345
|
+
end
|
346
|
+
|
347
|
+
uri = @github_api + path
|
348
|
+
|
349
|
+
http = Net::HTTP.new uri.host, uri.port
|
350
|
+
http.use_ssl = uri.scheme.downcase == 'https'
|
351
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
352
|
+
http.cert_store = OpenSSL::X509::Store.new
|
353
|
+
http.cert_store.set_default_paths
|
354
|
+
|
355
|
+
req = method.new uri.request_uri
|
356
|
+
if body then
|
357
|
+
req.content_type = 'application/json'
|
358
|
+
req.body = JSON.dump body
|
359
|
+
end
|
360
|
+
|
361
|
+
user = `git config github.user`.chomp
|
362
|
+
pass = `git config github.password`.chomp
|
363
|
+
req.basic_auth user, pass
|
364
|
+
|
365
|
+
res = http.request req
|
366
|
+
|
367
|
+
body = JSON.parse res.body if res.class.body_permitted?
|
368
|
+
|
369
|
+
unless Net::HTTPSuccess === res then
|
370
|
+
message = ": #{res['message']}" if body
|
371
|
+
|
372
|
+
raise "github API error #{res.code}#{message}"
|
373
|
+
end
|
374
|
+
|
375
|
+
body
|
376
|
+
end
|
377
|
+
|
378
|
+
##
|
379
|
+
# Returns the github hook definition for the "travis" hook on +repo+ (from
|
380
|
+
# the github URL), if it exists.
|
381
|
+
|
382
|
+
def travis_have_hook? repo
|
383
|
+
body = travis_github_request "/repos/#{repo}/hooks"
|
384
|
+
|
385
|
+
body.find { |hook| hook['name'] == 'travis' }
|
386
|
+
end
|
387
|
+
|
388
|
+
##
|
389
|
+
# Creates a travis hook for +user+ on the given +repo+ (from the github URL)
|
390
|
+
# that uses the users +token+.
|
391
|
+
|
392
|
+
def travis_make_hook repo, user, token
|
393
|
+
body = {
|
394
|
+
"name" => "travis",
|
395
|
+
"active" => true,
|
396
|
+
"config" => {
|
397
|
+
"domain" => "",
|
398
|
+
"token" => token,
|
399
|
+
"user" => user,
|
400
|
+
}
|
401
|
+
}
|
402
|
+
|
403
|
+
travis_github_request "/repos/#{repo}/hooks", body
|
404
|
+
end
|
405
|
+
|
406
|
+
##
|
407
|
+
# Creates the travis notifications hash from the developers for your
|
408
|
+
# project. The developer will be merged with the travis notifications from
|
409
|
+
# your .hoerc.
|
410
|
+
|
411
|
+
def travis_notifications
|
412
|
+
email = @email.compact
|
413
|
+
email.delete ''
|
414
|
+
|
415
|
+
default_notifications = { 'email' => email }
|
416
|
+
notifications = with_config do |config, _|
|
417
|
+
config['travis']['notifications'] or
|
418
|
+
Hoe::DEFAULT_CONFIG['travis']['notifications']
|
419
|
+
end || {}
|
420
|
+
|
421
|
+
default_notifications.merge notifications
|
422
|
+
end
|
423
|
+
|
424
|
+
##
|
425
|
+
# Extracts the travis script from your .hoerc
|
426
|
+
|
427
|
+
def travis_script
|
428
|
+
with_config { |config, _|
|
429
|
+
config['travis']['script'] or
|
430
|
+
Hoe::DEFAULT_CONFIG['travis']['script']
|
431
|
+
}
|
432
|
+
end
|
433
|
+
|
434
|
+
##
|
435
|
+
# Determines the travis versions from multiruby, if available, or your
|
436
|
+
# .hoerc.
|
437
|
+
|
438
|
+
def travis_versions
|
439
|
+
if have_gem? 'ZenTest' and
|
440
|
+
File.exist?(File.expand_path('~/.multiruby')) then
|
441
|
+
`multiruby -v` =~ /^Passed: (.*)/
|
442
|
+
|
443
|
+
$1.split(', ').map do |ruby_release|
|
444
|
+
ruby_release.sub(/-.*/, '')
|
445
|
+
end
|
446
|
+
else
|
447
|
+
with_config do |config, _|
|
448
|
+
config['travis']['versions'] or
|
449
|
+
Hoe::DEFAULT_CONFIG['travis']['versions']
|
450
|
+
end
|
451
|
+
end.sort
|
452
|
+
end
|
453
|
+
|
454
|
+
##
|
455
|
+
# Runs travis-lint against the travis.yml in +path+. If the file is OK true
|
456
|
+
# is returned, otherwise the issues are displayed on $stderr and false is
|
457
|
+
# returned.
|
458
|
+
|
459
|
+
def travis_yml_check path
|
460
|
+
require 'travis/lint'
|
461
|
+
|
462
|
+
travis_yml = YAML.load_file path
|
463
|
+
|
464
|
+
issues = Travis::Lint::Linter.validate travis_yml
|
465
|
+
|
466
|
+
return true if issues.empty?
|
467
|
+
|
468
|
+
issues.each do |issue|
|
469
|
+
warn "There is an issue with the key #{issue[:key].inspect}:"
|
470
|
+
warn "\t#{issue[:issue]}"
|
471
|
+
end
|
472
|
+
|
473
|
+
false
|
474
|
+
rescue *YAML_EXCEPTIONS => e
|
475
|
+
warn "invalid YAML in travis.yml file at #{path}: #{e.message}"
|
476
|
+
|
477
|
+
return false
|
478
|
+
end
|
479
|
+
|
480
|
+
##
|
481
|
+
# Loads the travis.yml in +path+ in your EDITOR (or vi if unset). Upon
|
482
|
+
# saving the travis.yml is checked with travis-lint. If any problems are
|
483
|
+
# found you will be asked to retry the edit.
|
484
|
+
#
|
485
|
+
# If the edited travis.yml is OK true is returned, otherwise false.
|
486
|
+
|
487
|
+
def travis_yml_edit path
|
488
|
+
loop do
|
489
|
+
editor = ENV['EDITOR'] || 'vi'
|
490
|
+
|
491
|
+
system "#{editor} #{path}"
|
492
|
+
|
493
|
+
break true if travis_yml_check path
|
494
|
+
|
495
|
+
abort unless $stdout.tty?
|
496
|
+
|
497
|
+
print "\nRetry edit? [Yn]\n> "
|
498
|
+
$stdout.flush
|
499
|
+
|
500
|
+
break false if $stdin.gets =~ /\An/i
|
501
|
+
end
|
502
|
+
end
|
503
|
+
|
504
|
+
##
|
505
|
+
# Generates a travis.yml from .hoerc, the Hoe spec and the default
|
506
|
+
# configuration.
|
507
|
+
|
508
|
+
def travis_yml_generate
|
509
|
+
travis_yml = {
|
510
|
+
'before_script' => travis_before_script,
|
511
|
+
'language' => 'ruby',
|
512
|
+
'notifications' => travis_notifications,
|
513
|
+
'rvm' => travis_versions,
|
514
|
+
'script' => travis_script,
|
515
|
+
}
|
516
|
+
|
517
|
+
travis_yml.each do |key, value|
|
518
|
+
travis_yml.delete key unless value
|
519
|
+
end
|
520
|
+
|
521
|
+
YAML.dump travis_yml
|
522
|
+
end
|
523
|
+
|
524
|
+
##
|
525
|
+
# Writes the travis.yml in +source_file+ to .travis.yml in the current
|
526
|
+
# directory. Overwrites an existing .travis.yml.
|
527
|
+
|
528
|
+
def travis_yml_write source_file
|
529
|
+
open source_file do |source_io|
|
530
|
+
open '.travis.yml', 'w' do |dest_io|
|
531
|
+
dest_io.write source_io.read
|
532
|
+
end
|
533
|
+
end
|
534
|
+
end
|
535
|
+
|
536
|
+
end
|
537
|
+
|
@@ -0,0 +1,215 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'hoe/travis'
|
3
|
+
require 'tmpdir'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
class TestHoeTravis < MiniTest::Unit::TestCase
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@hoe = Hoe.spec "blah" do
|
10
|
+
developer 'author', 'email@example'
|
11
|
+
developer 'silent', ''
|
12
|
+
|
13
|
+
self.readme_file = 'README.rdoc'
|
14
|
+
end
|
15
|
+
|
16
|
+
@hoe.extend Hoe::Travis
|
17
|
+
|
18
|
+
@editor = ENV['EDITOR']
|
19
|
+
@home = ENV['HOME']
|
20
|
+
end
|
21
|
+
|
22
|
+
def teardown
|
23
|
+
ENV['EDITOR'] = @editor
|
24
|
+
ENV['HOME'] = @home
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_travis_before_script
|
28
|
+
expected = [
|
29
|
+
'gem install hoe-travis --no-rdoc --no-ri',
|
30
|
+
'rake travis:before',
|
31
|
+
]
|
32
|
+
|
33
|
+
assert_equal expected, @hoe.travis_before_script
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_travis_fake_config
|
37
|
+
Dir.mktmpdir do |path|
|
38
|
+
ENV['HOME'] = path
|
39
|
+
|
40
|
+
fake_config = File.expand_path '~/.hoerc'
|
41
|
+
|
42
|
+
@hoe.travis_fake_config
|
43
|
+
|
44
|
+
assert File.exist? fake_config
|
45
|
+
|
46
|
+
expected = {
|
47
|
+
'exclude' => /\.(git|travis)/
|
48
|
+
}
|
49
|
+
|
50
|
+
assert_equal expected, YAML.load_file(fake_config)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_travis_notifications
|
55
|
+
expected = {
|
56
|
+
'email' => %w[email@example]
|
57
|
+
}
|
58
|
+
|
59
|
+
assert_equal expected, @hoe.travis_notifications
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_travis_notifications_config
|
63
|
+
Hoe::DEFAULT_CONFIG['travis']['notifications'] = {
|
64
|
+
'email' => %w[other@example],
|
65
|
+
'irc' => %w[irc.example#channel],
|
66
|
+
}
|
67
|
+
|
68
|
+
expected = {
|
69
|
+
'email' => %w[other@example],
|
70
|
+
'irc' => %w[irc.example#channel],
|
71
|
+
}
|
72
|
+
|
73
|
+
Dir.mktmpdir do |dir|
|
74
|
+
ENV['HOME'] = dir
|
75
|
+
assert_equal expected, @hoe.travis_notifications
|
76
|
+
end
|
77
|
+
ensure
|
78
|
+
Hoe::DEFAULT_CONFIG['travis'].delete 'notifications'
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_travis_script
|
82
|
+
expected = 'rake travis'
|
83
|
+
|
84
|
+
|
85
|
+
assert_equal expected, @hoe.travis_script
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_travis_versions
|
89
|
+
def @hoe.have_gem?(name) false end
|
90
|
+
|
91
|
+
assert_equal %w[1.8.7 1.9.2 1.9.3], @hoe.travis_versions
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_travis_versions_multiruby
|
95
|
+
def @hoe.have_gem?(name) true end
|
96
|
+
def @hoe.`(command) "Passed: 1.6.8, 1.8.0" end
|
97
|
+
|
98
|
+
Dir.mktmpdir do |path|
|
99
|
+
ENV['HOME'] = path
|
100
|
+
|
101
|
+
FileUtils.touch File.join(path, '.multiruby')
|
102
|
+
|
103
|
+
assert_equal %w[1.6.8 1.8.0], @hoe.travis_versions
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_travis_versions_multiruby_unused
|
108
|
+
def @hoe.have_gem?(name) true end
|
109
|
+
|
110
|
+
Dir.mktmpdir do |path|
|
111
|
+
ENV['HOME'] = path
|
112
|
+
|
113
|
+
assert_equal %w[1.8.7 1.9.2 1.9.3], @hoe.travis_versions
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_travis_yml_check
|
118
|
+
Tempfile.open 'travis' do |io|
|
119
|
+
io.write "---\nlanguage: ruby\nrvm:\n - 1.8.7\n"
|
120
|
+
io.rewind
|
121
|
+
|
122
|
+
assert @hoe.travis_yml_check io.path
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_travis_yml_check_invalid
|
127
|
+
Tempfile.open 'travis' do |io|
|
128
|
+
io.write "---\nlanguage: ruby\n"
|
129
|
+
io.rewind
|
130
|
+
|
131
|
+
out, err = capture_io do
|
132
|
+
refute @hoe.travis_yml_check io.path
|
133
|
+
end
|
134
|
+
|
135
|
+
assert_empty out
|
136
|
+
refute_empty err
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_travis_yml_edit
|
141
|
+
Tempfile.open 'out' do |out_io|
|
142
|
+
ENV['EDITOR'] = "cat > #{out_io.path} < "
|
143
|
+
|
144
|
+
Tempfile.open 'travis' do |io|
|
145
|
+
io.write "---\nlanguage: ruby\nrvm:\n - 1.8.7\n"
|
146
|
+
io.rewind
|
147
|
+
|
148
|
+
@hoe.travis_yml_edit io.path
|
149
|
+
end
|
150
|
+
|
151
|
+
assert_equal "---\nlanguage: ruby\nrvm:\n - 1.8.7\n", out_io.read
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_travis_yml_edit_bad
|
156
|
+
ENV['EDITOR'] = "cat > /dev/null < "
|
157
|
+
|
158
|
+
Tempfile.open 'travis' do |io|
|
159
|
+
io.write "travis: woo"
|
160
|
+
io.rewind
|
161
|
+
|
162
|
+
e = assert_raises SystemExit do
|
163
|
+
capture_io do
|
164
|
+
@hoe.travis_yml_edit io.path
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
assert_equal 1, e.status
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_travis_yml_generate
|
173
|
+
def @hoe.have_gem?(name) false end
|
174
|
+
|
175
|
+
Dir.mktmpdir do |path|
|
176
|
+
Dir.chdir path do
|
177
|
+
travis_yml = YAML.load @hoe.travis_yml_generate
|
178
|
+
|
179
|
+
expected = YAML.load <<-TRAVIS_YML
|
180
|
+
---
|
181
|
+
before_script:
|
182
|
+
- gem install hoe-travis --no-rdoc --no-ri
|
183
|
+
- rake travis:before
|
184
|
+
language: ruby
|
185
|
+
notifications:
|
186
|
+
email:
|
187
|
+
- email@example
|
188
|
+
rvm:
|
189
|
+
- 1.8.7
|
190
|
+
- 1.9.2
|
191
|
+
- 1.9.3
|
192
|
+
script: rake travis
|
193
|
+
TRAVIS_YML
|
194
|
+
|
195
|
+
assert_equal expected, travis_yml
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_travis_yml_write
|
201
|
+
Dir.mktmpdir do |path|
|
202
|
+
Dir.chdir path do
|
203
|
+
open 'travis', 'w' do |io| io.write 'travis' end
|
204
|
+
|
205
|
+
@hoe.travis_yml_write 'travis'
|
206
|
+
|
207
|
+
assert File.exist? '.travis.yml'
|
208
|
+
|
209
|
+
assert_equal 'travis', File.read('.travis.yml')
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
215
|
+
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hoe-travis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: "1.0"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Eric Hodel
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain:
|
16
|
+
- |
|
17
|
+
-----BEGIN CERTIFICATE-----
|
18
|
+
MIIDeDCCAmCgAwIBAgIBATANBgkqhkiG9w0BAQUFADBBMRAwDgYDVQQDDAdkcmJy
|
19
|
+
YWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZFgNu
|
20
|
+
ZXQwHhcNMTIwMjI4MTc1NDI1WhcNMTMwMjI3MTc1NDI1WjBBMRAwDgYDVQQDDAdk
|
21
|
+
cmJyYWluMRgwFgYKCZImiZPyLGQBGRYIc2VnbWVudDcxEzARBgoJkiaJk/IsZAEZ
|
22
|
+
FgNuZXQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCbbgLrGLGIDE76
|
23
|
+
LV/cvxdEzCuYuS3oG9PrSZnuDweySUfdp/so0cDq+j8bqy6OzZSw07gdjwFMSd6J
|
24
|
+
U5ddZCVywn5nnAQ+Ui7jMW54CYt5/H6f2US6U0hQOjJR6cpfiymgxGdfyTiVcvTm
|
25
|
+
Gj/okWrQl0NjYOYBpDi+9PPmaH2RmLJu0dB/NylsDnW5j6yN1BEI8MfJRR+HRKZY
|
26
|
+
mUtgzBwF1V4KIZQ8EuL6I/nHVu07i6IkrpAgxpXUfdJQJi0oZAqXurAV3yTxkFwd
|
27
|
+
g62YrrW26mDe+pZBzR6bpLE+PmXCzz7UxUq3AE0gPHbiMXie3EFE0oxnsU3lIduh
|
28
|
+
sCANiQ8BAgMBAAGjezB5MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
|
29
|
+
BBS5k4Z75VSpdM0AclG2UvzFA/VW5DAfBgNVHREEGDAWgRRkcmJyYWluQHNlZ21l
|
30
|
+
bnQ3Lm5ldDAfBgNVHRIEGDAWgRRkcmJyYWluQHNlZ21lbnQ3Lm5ldDANBgkqhkiG
|
31
|
+
9w0BAQUFAAOCAQEAPeWzFnrcvC6eVzdlhmjUub2s6qieBkongKRDHQz5MEeQv4LS
|
32
|
+
SARnoHY+uCAVL/1xGAhmpzqQ3fJGWK9eBacW/e8E5GF9xQcV3mE1bA0WNaiDlX5j
|
33
|
+
U2aI+ZGSblqvHUCxKBHR1s7UMHsbz1saOmgdRTyPx0juJs68ocbUTeYBLWu9V4KP
|
34
|
+
zdGAG2JXO2gONg3b4tYDvpBLbry+KOX27iAJulUaH9TiTOULL4ITJVFsK0mYVqmR
|
35
|
+
Q8Tno9S3e4XGGP1ZWfLrTWEJbavFfhGHut2iMRwfC7s/YILAHNATopaJdH9DNpd1
|
36
|
+
U81zGHMUBOvz/VGT6wJwYJ3emS2nfA2NOHFfgA==
|
37
|
+
-----END CERTIFICATE-----
|
38
|
+
|
39
|
+
date: 2012-03-02 00:00:00 Z
|
40
|
+
dependencies:
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: travis-lint
|
43
|
+
prerelease: false
|
44
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ~>
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
hash: 11
|
50
|
+
segments:
|
51
|
+
- 1
|
52
|
+
- 2
|
53
|
+
version: "1.2"
|
54
|
+
type: :runtime
|
55
|
+
version_requirements: *id001
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: hoe
|
58
|
+
prerelease: false
|
59
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ~>
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 31
|
65
|
+
segments:
|
66
|
+
- 2
|
67
|
+
- 14
|
68
|
+
version: "2.14"
|
69
|
+
type: :runtime
|
70
|
+
version_requirements: *id002
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: minitest
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ~>
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
hash: 23
|
80
|
+
segments:
|
81
|
+
- 2
|
82
|
+
- 10
|
83
|
+
version: "2.10"
|
84
|
+
type: :development
|
85
|
+
version_requirements: *id003
|
86
|
+
- !ruby/object:Gem::Dependency
|
87
|
+
name: rdoc
|
88
|
+
prerelease: false
|
89
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
hash: 19
|
95
|
+
segments:
|
96
|
+
- 3
|
97
|
+
- 10
|
98
|
+
version: "3.10"
|
99
|
+
type: :development
|
100
|
+
version_requirements: *id004
|
101
|
+
description: |-
|
102
|
+
hoe-travis is a Hoe plugin that allows your gem to gain maximum benefit from
|
103
|
+
http://travis-ci.org. The plugin contains a <code>.travis.yml</code>
|
104
|
+
generator and a pre-defined rake task which runs the tests and ensures your
|
105
|
+
manifest file is correct.
|
106
|
+
|
107
|
+
With hoe-travis it is easy to add additional checks. Custom checks can be
|
108
|
+
easily verified locally by simply running a rake task instead of committing
|
109
|
+
and pushing a change, waiting for travis to run your tests, then trying a new
|
110
|
+
commit if you didn't fix the problem.
|
111
|
+
email:
|
112
|
+
- drbrain@segment7.net
|
113
|
+
executables: []
|
114
|
+
|
115
|
+
extensions: []
|
116
|
+
|
117
|
+
extra_rdoc_files:
|
118
|
+
- History.txt
|
119
|
+
- Manifest.txt
|
120
|
+
- README.rdoc
|
121
|
+
files:
|
122
|
+
- .autotest
|
123
|
+
- History.txt
|
124
|
+
- Manifest.txt
|
125
|
+
- README.rdoc
|
126
|
+
- Rakefile
|
127
|
+
- lib/hoe/travis.rb
|
128
|
+
- test/test_hoe_travis.rb
|
129
|
+
- .gemtest
|
130
|
+
homepage: https://github.com/drbrain/hoe-travis
|
131
|
+
licenses: []
|
132
|
+
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options:
|
135
|
+
- --main
|
136
|
+
- README.rdoc
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
hash: 3
|
145
|
+
segments:
|
146
|
+
- 0
|
147
|
+
version: "0"
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
hash: 3
|
154
|
+
segments:
|
155
|
+
- 0
|
156
|
+
version: "0"
|
157
|
+
requirements: []
|
158
|
+
|
159
|
+
rubyforge_project: hoe-travis
|
160
|
+
rubygems_version: 1.8.12
|
161
|
+
signing_key:
|
162
|
+
specification_version: 3
|
163
|
+
summary: hoe-travis is a Hoe plugin that allows your gem to gain maximum benefit from http://travis-ci.org
|
164
|
+
test_files:
|
165
|
+
- test/test_hoe_travis.rb
|
metadata.gz.sig
ADDED
Binary file
|