buildtasks 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: 75634d859b641eb754a9ab76c809ae6557fd543d
4
+ data.tar.gz: 2639328f52ceb6fe6654f8c0fb0867e0e07f52bb
5
+ SHA512:
6
+ metadata.gz: 3e2f96ae4e9d8586987d50283094f4f502d46e76d095a322682c53c3cc9453228941df3438b3823423bfae3a2417da3a1fafed32aada4225d0e426bc68b205e5
7
+ data.tar.gz: d21daf1ddf58962fcb37c64872f72a0237f2a9949b353d90847a9401a9bc746074b2253d0a75fb68f00304a294d1a9a569fdd9ca1daf3230cbf9f38e0c64a231
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ AllCops:
2
+ Include:
3
+ - "Gemfile"
4
+ - "Rakefile"
5
+
6
+ AlignParameters:
7
+ Enabled: false
8
+ Documentation:
9
+ Enabled: false
10
+ Encoding:
11
+ Enabled: false
12
+ FileName:
13
+ Enabled: false
14
+ GuardClause:
15
+ Enabled: false
16
+ HashSyntax:
17
+ EnforcedStyle: hash_rockets
18
+ LineLength:
19
+ Enabled: false
20
+ SingleSpaceBeforeFirstArg:
21
+ Enabled: false
22
+ StringLiterals:
23
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in buildtasks.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,118 @@
1
+ # BuildTasks
2
+
3
+ Rake tasks to build Debian packages with [git-buildpackage] and [fpm-cookery].
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'buildtasks'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install buildtasks
20
+
21
+ ## Usage
22
+
23
+ Require the `buildtasks` gem in a `Rakefile` and call `BuildTasks::Tool.define`,
24
+ where "Tool" is the name of the build tool you want to use (see below for a list
25
+ of options you can pass to `.define`).
26
+
27
+ This will create two Rake tasks:
28
+
29
+ * *build* -- used to build Debian package(s)
30
+ * *publish* -- used to copy built packages to directory specified by
31
+ `PUBLISH_DIR` environment variable
32
+
33
+ Invoke the *build* task to first build the packages, e.g., inside a Vagrant
34
+ machine or Docker container. Afterwards, run the *publish* task to copy the
35
+ resulting packages to a known location, e.g., your host system via a shared
36
+ volume.
37
+
38
+ ### fpm-cookery
39
+
40
+ To build packages with [fpm-cookery], create a `Rakefile` with this content:
41
+
42
+ ```ruby
43
+ require "buildtasks"
44
+
45
+ BuildTasks::FPMCookery.define do
46
+ recipe "recipe.rb" # name of recipe file (optional)
47
+ fpm_cookery_version "0.25.0" # version of fpm-cookery gem to use (optional)
48
+ fpm_version "1.3.3" # version of fpm gem to use (optional)
49
+ end
50
+ ```
51
+
52
+ In case you don't need to configure any attributes:
53
+
54
+ ```ruby
55
+ require "buildtasks"
56
+
57
+ BuildTasks::FPMCookery.define
58
+ ```
59
+
60
+ Note that fpm-cookery will automatically install dependencies specified by the
61
+ `build_depends` and `depends` attributes in `recipe.rb` before building.
62
+
63
+ ### git-buildpackage
64
+
65
+ To build packages with [git-buildpackage], create a `Rakefile` with this
66
+ content:
67
+
68
+ ```ruby
69
+ require "buildtasks"
70
+
71
+ BuildTasks::GitBuildpackage.define do
72
+ name "thrift" # project name
73
+ version "0.9.1" # git ref to build
74
+ source "https://github.com/apache/thrift" # git repository to clone
75
+ apply_patch "patches/THRIFT-2211.patch" # patch to apply before building (optional)
76
+ end
77
+ ```
78
+
79
+ Note that all build dependencies from `debian/control` will be automatically
80
+ installed before building.
81
+
82
+ ### Extending Rake tasks
83
+
84
+ `.define` generates ordinary Rake tasks, which you can extend.
85
+
86
+ For example, here's how to download some file before fpm-cookery starts
87
+ building:
88
+
89
+ ```ruby
90
+ require "buildtasks"
91
+
92
+ BuildTasks::FPMCookery.define
93
+
94
+ task :download do
95
+ sh "curl ..."
96
+ end
97
+ task :build => :download
98
+ ```
99
+
100
+ ## License and Authors
101
+
102
+ Author:: Mathias Lafeldt (mathias.lafeldt@jimdo.com)
103
+
104
+ Copyright:: 2014-2015, Jimdo GmbH
105
+
106
+ Licensed under the Apache 2.0 license. See [LICENSE](LICENSE) for details.
107
+
108
+ ## Contributing
109
+
110
+ 1. [Fork this repository](https://github.com/Jimdo/buildtasks/fork)
111
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
112
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
113
+ 4. Push to the branch (`git push origin my-new-feature`)
114
+ 5. Create a new Pull Request
115
+
116
+
117
+ [fpm-cookery]: https://github.com/bernd/fpm-cookery
118
+ [git-buildpackage]: https://honk.sigxcpu.org/piki/projects/git-buildpackage/
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "rubocop/rake_task"
4
+
5
+ desc "Run RuboCop style and lint checks"
6
+ RuboCop::RakeTask.new(:rubocop) do |t|
7
+ t.options = ["-D"]
8
+ end
9
+
10
+ RSpec::Core::RakeTask.new(:spec) do |t|
11
+ t.rspec_opts = "--color --format documentation"
12
+ end
13
+
14
+ task :test => [:rubocop, :spec]
15
+ task :default => :test
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'buildtasks/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "buildtasks"
8
+ spec.version = BuildTasks::VERSION
9
+ spec.authors = ["Mathias Lafeldt"]
10
+ spec.email = ["mathias.lafeldt@jimdo.com"]
11
+ spec.summary = %q{Rake tasks to build Debian packages}
12
+ spec.description = %q{Rake tasks to build Debian packages}
13
+ spec.homepage = "https://github.com/Jimdo/buildtasks"
14
+ spec.license = "Apache 2.0"
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_dependency "rake"
22
+
23
+ spec.add_development_dependency "bundler"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "rubocop", "~> 0.24.1"
26
+ end
@@ -0,0 +1,4 @@
1
+ module BuildTasks
2
+ class InvalidAttributeError < StandardError; end
3
+ class MissingAttributeError < StandardError; end
4
+ end
@@ -0,0 +1,29 @@
1
+ require "buildtasks/mixins/dsl"
2
+
3
+ module BuildTasks
4
+ module FPMCookery
5
+ class DSL
6
+ include BuildTasks::Mixins::DSL
7
+
8
+ def initialize(&block)
9
+ @recipe = "recipe.rb"
10
+ @fpm_cookery_version = "~> 0.25.0"
11
+ @fpm_version = "~> 1.3.3"
12
+
13
+ instance_eval(&block) if block_given?
14
+ end
15
+
16
+ def recipe(arg = nil)
17
+ set_or_return(:recipe, arg, :kind_of => String)
18
+ end
19
+
20
+ def fpm_cookery_version(arg = nil)
21
+ set_or_return(:fpm_cookery_version, arg, :kind_of => String)
22
+ end
23
+
24
+ def fpm_version(arg = nil)
25
+ set_or_return(:fpm_version, arg, :kind_of => String)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,74 @@
1
+ require "buildtasks/exceptions"
2
+ require "buildtasks/mixins/tasks"
3
+ require "rake/tasklib"
4
+ require "forwardable"
5
+
6
+ module BuildTasks
7
+ module FPMCookery
8
+ class Tasks < ::Rake::TaskLib
9
+ include BuildTasks::Mixins::Tasks
10
+
11
+ extend Forwardable
12
+ def_delegators :@attributes, :recipe, :fpm_cookery_version, :fpm_version
13
+
14
+ def initialize(attributes)
15
+ @attributes = attributes
16
+ validate_attributes
17
+ define_tasks
18
+ end
19
+
20
+ private
21
+
22
+ def validate_attributes
23
+ unless File.exist?(recipe)
24
+ fail InvalidAttributeError, "recipe file '#{recipe}' not found"
25
+ end
26
+
27
+ if File.exist?("Gemfile")
28
+ STDERR.puts "warning: Gemfile overrules fpm_cookery_version and fpm_version"
29
+ end
30
+ end
31
+
32
+ def define_tasks # rubocop:disable MethodLength
33
+ task :default => :build
34
+
35
+ file "Gemfile" do |t|
36
+ generate_gemfile(t.name)
37
+ end
38
+
39
+ desc "Install build dependencies"
40
+ task :deps => "Gemfile" do
41
+ sh "bundle check || bundle install"
42
+ end
43
+
44
+ desc "Build packages"
45
+ task :build => :deps do
46
+ sh sudo("bundle exec fpm-cook package --debug #{recipe}")
47
+ end
48
+
49
+ desc "Publish built packages"
50
+ task :publish => :build do
51
+ publish_dir = ENV["PUBLISH_DIR"]
52
+ fail "PUBLISH_DIR variable not set in environment" unless publish_dir
53
+
54
+ mkdir_p publish_dir
55
+ cp Dir["pkg/*.deb"], publish_dir
56
+ end
57
+
58
+ require "rake/clean"
59
+ CLEAN.include %w(cache tmp-build tmp-dest)
60
+ CLOBBER.include %w(pkg)
61
+
62
+ self
63
+ end
64
+
65
+ def generate_gemfile(path)
66
+ File.open(path, "w") do |f|
67
+ f.write "source 'https://rubygems.org'\n"
68
+ f.write "gem 'fpm-cookery', '#{fpm_cookery_version}'\n"
69
+ f.write "gem 'fpm', '#{fpm_version}'\n"
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,11 @@
1
+ require "buildtasks/fpm_cookery/dsl"
2
+ require "buildtasks/fpm_cookery/tasks"
3
+
4
+ module BuildTasks
5
+ module FPMCookery
6
+ def self.define(&block)
7
+ attributes = BuildTasks::FPMCookery::DSL.new(&block)
8
+ BuildTasks::FPMCookery::Tasks.new(attributes)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,41 @@
1
+ require "buildtasks/mixins/dsl"
2
+
3
+ module BuildTasks
4
+ module GitBuildpackage
5
+ class DSL
6
+ include BuildTasks::Mixins::DSL
7
+
8
+ def initialize(&block)
9
+ @name = nil
10
+ @version = nil
11
+ @source = nil
12
+ @patches = []
13
+ @changelog = nil
14
+
15
+ instance_eval(&block) if block_given?
16
+ end
17
+
18
+ attr_reader :patches, :changelog
19
+
20
+ def name(arg = nil)
21
+ set_or_return(:name, arg, :kind_of => String)
22
+ end
23
+
24
+ def version(arg = nil)
25
+ set_or_return(:version, arg, :kind_of => String)
26
+ end
27
+
28
+ def source(arg = nil)
29
+ set_or_return(:source, arg, :kind_of => String)
30
+ end
31
+
32
+ def apply_patch(patch)
33
+ @patches << patch
34
+ end
35
+
36
+ def update_changelog(text, options = {})
37
+ @changelog = { :text => text }.merge(options)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,120 @@
1
+ require "buildtasks/exceptions"
2
+ require "buildtasks/mixins/tasks"
3
+ require "rake/tasklib"
4
+ require "forwardable"
5
+
6
+ module BuildTasks
7
+ module GitBuildpackage
8
+ class Tasks < ::Rake::TaskLib
9
+ BUILD_CMD = 'debuild -i\.git -I.git -uc -us -b'
10
+
11
+ include BuildTasks::Mixins::Tasks
12
+
13
+ extend Forwardable
14
+ def_delegators :@attributes, :name, :version, :source,
15
+ :patches, :changelog
16
+
17
+ def initialize(attributes)
18
+ @attributes = attributes
19
+ validate_attributes
20
+ define_tasks
21
+ end
22
+
23
+ private
24
+
25
+ def abspath(path)
26
+ File.join(Rake.original_dir, path)
27
+ end
28
+
29
+ def validate_attributes
30
+ fail MissingAttributeError, "name" unless name
31
+ fail MissingAttributeError, "version" unless version
32
+ fail MissingAttributeError, "source" unless source
33
+
34
+ patches.each { |p| fail Errno::ENOENT, p unless File.exist?(abspath(p)) }
35
+ end
36
+
37
+ def update_changelog # rubocop:disable MethodLength
38
+ return unless changelog
39
+
40
+ text = changelog[:text]
41
+ args = if changelog[:version]
42
+ ["--newversion", changelog[:version], "--force-bad-version", text]
43
+ elsif changelog[:suffix]
44
+ ["--local", changelog[:suffix], text]
45
+ elsif changelog[:increment?] == true
46
+ ["--increment", text]
47
+ else
48
+ [text]
49
+ end
50
+ sh "dch", "--no-auto-nmu", *args
51
+ end
52
+
53
+ def define_tasks # rubocop:disable MethodLength
54
+ task :default => :build
55
+
56
+ file git_dir do |t|
57
+ sh "git", "clone", source, t.name
58
+ end
59
+
60
+ desc "Clone Git repository and checkout version"
61
+ task :clone => git_dir do
62
+ in_git_dir do
63
+ sh "git", "checkout", "-qf", version.to_s
64
+ end
65
+ end
66
+
67
+ desc "Apply any patches"
68
+ task :patch => :clone do
69
+ in_git_dir do
70
+ patches.each { |p| sh "git", "apply", "-v", abspath(p) }
71
+ update_changelog
72
+ sh "git", "status", "-s"
73
+ end
74
+ end
75
+
76
+ desc "Install build dependencies"
77
+ task :deps => :patch do
78
+ in_git_dir do
79
+ control_file = "debian/control"
80
+ fail Errno::ENOENT, control_file unless File.exist?(control_file)
81
+ env = "DEBIAN_FRONTEND=noninteractive"
82
+ sh sudo("#{env} mk-build-deps -i -r -t 'apt-get -y' #{control_file}")
83
+ end
84
+ end
85
+
86
+ desc "Build packages"
87
+ task :build => [:clone, :patch, :deps] do
88
+ in_git_dir do
89
+ sh "git-buildpackage", "--git-ignore-branch",
90
+ "--git-ignore-new",
91
+ "--git-builder=#{BUILD_CMD}"
92
+ end
93
+ end
94
+
95
+ desc "Publish built packages"
96
+ task :publish => :build do
97
+ publish_dir = ENV["PUBLISH_DIR"]
98
+ fail "PUBLISH_DIR variable not set in environment" unless publish_dir
99
+
100
+ mkdir_p publish_dir
101
+ cp Dir["*.deb"], publish_dir
102
+ end
103
+
104
+ require "rake/clean"
105
+ CLEAN.include "git-*", "*.build", "*.changes", "*.orig.tar.gz"
106
+ CLOBBER.include "*.deb"
107
+
108
+ self
109
+ end
110
+
111
+ def git_dir
112
+ "git-#{version.to_s.gsub("/", "-")}"
113
+ end
114
+
115
+ def in_git_dir
116
+ cd(git_dir) { yield }
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,11 @@
1
+ require "buildtasks/git_buildpackage/dsl"
2
+ require "buildtasks/git_buildpackage/tasks"
3
+
4
+ module BuildTasks
5
+ module GitBuildpackage
6
+ def self.define(&block)
7
+ attributes = BuildTasks::GitBuildpackage::DSL.new(&block)
8
+ BuildTasks::GitBuildpackage::Tasks.new(attributes)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ module BuildTasks
2
+ module Mixins
3
+ module DSL
4
+ def _validate(symbol, arg, validation)
5
+ kinds = Array(validation.fetch(:kind_of))
6
+ unless kinds.any? { |k| arg.is_a?(k) }
7
+ fail ArgumentError, "#{symbol} must be of kind #{kinds}"
8
+ end
9
+ end
10
+
11
+ def set_or_return(symbol, arg, validation = nil)
12
+ iv_symbol = "@#{symbol}".to_sym
13
+ if arg.nil? && instance_variable_defined?(iv_symbol)
14
+ instance_variable_get(iv_symbol)
15
+ else
16
+ _validate(symbol, arg, validation) if validation
17
+ instance_variable_set(iv_symbol, arg)
18
+ end
19
+ end
20
+
21
+ def codename(name = nil)
22
+ @codename ||= `lsb_release -cs`.strip.to_sym
23
+ return @codename if name.nil?
24
+ yield if name == @codename
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,10 @@
1
+ module BuildTasks
2
+ module Mixins
3
+ module Tasks
4
+ def sudo(cmd)
5
+ return cmd if Process.uid == 0
6
+ "sudo " + cmd
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module BuildTasks
2
+ VERSION = "0.0.1"
3
+ end
data/lib/buildtasks.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "buildtasks/fpm_cookery"
2
+ require "buildtasks/git_buildpackage"
@@ -0,0 +1,37 @@
1
+ require "buildtasks/fpm_cookery/dsl"
2
+
3
+ describe BuildTasks::FPMCookery::DSL do
4
+ subject { BuildTasks::FPMCookery::DSL.new }
5
+
6
+ it "initializes attributes" do
7
+ expect(subject.recipe).to eq "recipe.rb"
8
+ expect(subject.fpm_cookery_version).to eq "~> 0.25.0"
9
+ expect(subject.fpm_version).to eq "~> 1.3.3"
10
+ end
11
+
12
+ it "handles recipe attribute" do
13
+ subject.recipe "some-recipe"
14
+ expect(subject.recipe).to eq "some-recipe"
15
+ end
16
+
17
+ it "handles fpm_cookery_version attribute" do
18
+ subject.fpm_cookery_version "some-version"
19
+ expect(subject.fpm_cookery_version).to eq "some-version"
20
+ end
21
+
22
+ it "handles fpm_version attribute" do
23
+ subject.fpm_version "some-version"
24
+ expect(subject.fpm_version).to eq "some-version"
25
+ end
26
+
27
+ it "handles passing attributes via block" do
28
+ dsl = BuildTasks::FPMCookery::DSL.new do
29
+ recipe "some-recipe"
30
+ fpm_cookery_version "some-version"
31
+ fpm_version "another-version"
32
+ end
33
+ expect(dsl.recipe).to eq "some-recipe"
34
+ expect(dsl.fpm_cookery_version).to eq "some-version"
35
+ expect(dsl.fpm_version).to eq "another-version"
36
+ end
37
+ end
@@ -0,0 +1,47 @@
1
+ require "buildtasks/fpm_cookery/tasks"
2
+ require "tmpdir"
3
+
4
+ describe BuildTasks::FPMCookery::Tasks do
5
+ before(:each) do
6
+ Rake::Task.clear
7
+ end
8
+
9
+ it "creates Rake tasks from DSL attributes" do
10
+ expect(Rake::Task.tasks).to be_empty
11
+
12
+ attributes = double(
13
+ :recipe => "some-recipe",
14
+ :fpm_cookery_version => nil,
15
+ :fpm_version => nil
16
+ )
17
+
18
+ allow(File).to receive(:exist?).with("some-recipe").and_return(true)
19
+ allow(File).to receive(:exist?).with("Gemfile").and_return(false)
20
+
21
+ BuildTasks::FPMCookery::Tasks.new(attributes)
22
+ expect(Rake::Task.task_defined? "build").to be_truthy
23
+ expect(Rake::Task.task_defined? "publish").to be_truthy
24
+ end
25
+
26
+ it "creates Gemfile to define gem dependencies" do
27
+ attributes = double(
28
+ :recipe => "some-recipe",
29
+ :fpm_cookery_version => "some-version",
30
+ :fpm_version => "another-version"
31
+ )
32
+
33
+ allow(File).to receive(:exist?).with("some-recipe").and_return(true)
34
+ allow(File).to receive(:exist?).with("Gemfile").and_return(false)
35
+
36
+ BuildTasks::FPMCookery::Tasks.new(attributes)
37
+
38
+ Dir.mktmpdir do |dir|
39
+ Dir.chdir(dir) do
40
+ Rake::Task["Gemfile"].invoke
41
+ content = File.read("Gemfile")
42
+ expect(content).to include "gem 'fpm-cookery', 'some-version'"
43
+ expect(content).to include "gem 'fpm', 'another-version'"
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,57 @@
1
+ require "buildtasks/git_buildpackage/dsl"
2
+
3
+ describe BuildTasks::GitBuildpackage::DSL do
4
+ subject { BuildTasks::GitBuildpackage::DSL.new }
5
+
6
+ it "initializes attributes" do
7
+ expect(subject.name).to be_nil
8
+ expect(subject.version).to be_nil
9
+ expect(subject.source).to be_nil
10
+ expect(subject.patches).to eq []
11
+ expect(subject.changelog).to eq nil
12
+ end
13
+
14
+ it "handles name attribute" do
15
+ subject.name "some-name"
16
+ expect(subject.name).to eq "some-name"
17
+ end
18
+
19
+ it "handles version attribute" do
20
+ subject.version "some-version"
21
+ expect(subject.version).to eq "some-version"
22
+ end
23
+
24
+ it "handles source attribute" do
25
+ subject.source "some-source"
26
+ expect(subject.source).to eq "some-source"
27
+ end
28
+
29
+ it "handles apply_patch attribute" do
30
+ subject.apply_patch "some-patch"
31
+ subject.apply_patch "another-patch"
32
+ expect(subject.patches).to eq %w(some-patch another-patch)
33
+ end
34
+
35
+ it "handles update_changelog attribute" do
36
+ subject.update_changelog "some-text", :version => "some-version"
37
+ expect(subject.changelog[:text]).to eq "some-text"
38
+ expect(subject.changelog[:version]).to eq "some-version"
39
+ end
40
+
41
+ it "handles passing attributes via block" do
42
+ dsl = BuildTasks::GitBuildpackage::DSL.new do
43
+ name "some-name"
44
+ version "some-version"
45
+ source "some-source"
46
+ apply_patch "some-patch"
47
+ apply_patch "another-patch"
48
+ update_changelog "some-text", :version => "some-version"
49
+ end
50
+ expect(dsl.name).to eq "some-name"
51
+ expect(dsl.version).to eq "some-version"
52
+ expect(dsl.source).to eq "some-source"
53
+ expect(dsl.patches).to eq %w(some-patch another-patch)
54
+ expect(dsl.changelog[:text]).to eq "some-text"
55
+ expect(dsl.changelog[:version]).to eq "some-version"
56
+ end
57
+ end
@@ -0,0 +1,20 @@
1
+ require "buildtasks/git_buildpackage/tasks"
2
+
3
+ describe BuildTasks::GitBuildpackage::Tasks do
4
+ it "creates Rake tasks from DSL attributes" do
5
+ Rake::Task.clear
6
+ expect(Rake::Task.tasks).to be_empty
7
+
8
+ attributes = double(
9
+ :name => "some-name",
10
+ :version => "some-version",
11
+ :source => "some-source",
12
+ :patches => [],
13
+ :changelog => nil
14
+ )
15
+
16
+ BuildTasks::GitBuildpackage::Tasks.new(attributes)
17
+ expect(Rake::Task.task_defined? "build").to be_truthy
18
+ expect(Rake::Task.task_defined? "publish").to be_truthy
19
+ end
20
+ end
@@ -0,0 +1,53 @@
1
+ require "buildtasks/mixins/dsl"
2
+
3
+ describe BuildTasks::Mixins::DSL do
4
+ describe "#set_or_return" do
5
+ it "returns current value" do
6
+ c = Class.new do
7
+ include BuildTasks::Mixins::DSL
8
+ def initialize
9
+ @some_attribute = :some_value
10
+ end
11
+ end.new
12
+ expect(c.set_or_return(:some_attribute, nil)).to eq :some_value
13
+ end
14
+
15
+ it "sets new value" do
16
+ c = Class.new do
17
+ include BuildTasks::Mixins::DSL
18
+ attr_reader :some_attribute
19
+ end.new
20
+ c.set_or_return(:some_attribute, :some_value)
21
+ expect(c.some_attribute).to eq :some_value
22
+ end
23
+
24
+ context "validation" do
25
+ let(:c) do
26
+ Class.new do
27
+ include BuildTasks::Mixins::DSL
28
+ end.new
29
+ end
30
+
31
+ it "checks if value is of a specfic kind" do
32
+ expect do
33
+ c.set_or_return(:some_attribute, "some-value", :kind_of => String)
34
+ c.set_or_return(:some_attribute, :some_value, :kind_of => Symbol)
35
+ c.set_or_return(:some_attribute, 1234, :kind_of => Fixnum)
36
+ c.set_or_return(:some_attribute, true, :kind_of => TrueClass)
37
+ c.set_or_return(:some_attribute, false, :kind_of => FalseClass)
38
+ c.set_or_return(:some_attribute, 1, :kind_of => [TrueClass, Integer])
39
+ end.not_to raise_error
40
+ end
41
+
42
+ it "raises an exception if value is not of kind" do
43
+ expect do
44
+ c.set_or_return(:some_attribute, "some-value", :kind_of => Integer)
45
+ end.to raise_error(ArgumentError, "some_attribute must be of kind [Integer]")
46
+
47
+ expect do
48
+ c.set_or_return(:some_attribute, 1234, :kind_of => [String, TrueClass])
49
+ end.to raise_error(ArgumentError, "some_attribute must be of kind [String, TrueClass]")
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,21 @@
1
+ require "buildtasks/mixins/tasks"
2
+
3
+ describe BuildTasks::Mixins::Tasks do
4
+ let(:c) do
5
+ Class.new do
6
+ include BuildTasks::Mixins::Tasks
7
+ end.new
8
+ end
9
+
10
+ describe "#sudo" do
11
+ it "runs command via sudo if not root" do
12
+ allow(Process).to receive(:uid).and_return 1000
13
+ expect(c.sudo "shutdown -fr").to eq "sudo shutdown -fr"
14
+ end
15
+
16
+ it "runs command as-is if already root" do
17
+ allow(Process).to receive(:uid).and_return 0
18
+ expect(c.sudo "shutdown -fr").to eq "shutdown -fr"
19
+ end
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buildtasks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mathias Lafeldt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.24.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.24.1
69
+ description: Rake tasks to build Debian packages
70
+ email:
71
+ - mathias.lafeldt@jimdo.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rubocop.yml"
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - buildtasks.gemspec
83
+ - lib/buildtasks.rb
84
+ - lib/buildtasks/exceptions.rb
85
+ - lib/buildtasks/fpm_cookery.rb
86
+ - lib/buildtasks/fpm_cookery/dsl.rb
87
+ - lib/buildtasks/fpm_cookery/tasks.rb
88
+ - lib/buildtasks/git_buildpackage.rb
89
+ - lib/buildtasks/git_buildpackage/dsl.rb
90
+ - lib/buildtasks/git_buildpackage/tasks.rb
91
+ - lib/buildtasks/mixins/dsl.rb
92
+ - lib/buildtasks/mixins/tasks.rb
93
+ - lib/buildtasks/version.rb
94
+ - spec/fpm_cookery/dsl_spec.rb
95
+ - spec/fpm_cookery/tasks_spec.rb
96
+ - spec/git_buildpackage/dsl_spec.rb
97
+ - spec/git_buildpackage/tasks_spec.rb
98
+ - spec/mixins/dsl_spec.rb
99
+ - spec/mixins/tasks_spec.rb
100
+ homepage: https://github.com/Jimdo/buildtasks
101
+ licenses:
102
+ - Apache 2.0
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.2.2
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Rake tasks to build Debian packages
124
+ test_files:
125
+ - spec/fpm_cookery/dsl_spec.rb
126
+ - spec/fpm_cookery/tasks_spec.rb
127
+ - spec/git_buildpackage/dsl_spec.rb
128
+ - spec/git_buildpackage/tasks_spec.rb
129
+ - spec/mixins/dsl_spec.rb
130
+ - spec/mixins/tasks_spec.rb