Skip to content

Commit

Permalink
Use puppet-modulebuilder to build modules
Browse files Browse the repository at this point in the history
This decouples building modules from Puppet <= 5 / PDK.
  • Loading branch information
ekohl committed Apr 23, 2020
1 parent 5b203af commit f955a02
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 28 deletions.
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ $ gem install puppet-blacksmith
Add to your Rakefile

```ruby
require 'puppetlabs_spec_helper/rake_tasks' # needed for some module packaging tasks
require 'puppet_blacksmith/rake_tasks'
```

Expand All @@ -33,6 +32,7 @@ Rake tasks included:

| task | description |
| ------------------ | ----------- |
| module:build | Build the module using puppet-modulebuilder |
| module:bump | Bump module version to the next patch |
| module:bump:patch | Bump module version to the next patch |
| module:bump:minor | Bump module version to the next minor version |
Expand Down Expand Up @@ -73,15 +73,7 @@ $ rake module:bump

### Push a module to a repository

Add the require instructions for blacksmith and the puppetlabs_spec_helper to the Rakefile

```ruby
# Rakefile
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet_blacksmith/rake_tasks'
```

Run rake. Ensure you are doing it in a clean working folder or the puppet module tool will package all the unnecessary files.
Run rake. Ensure you are doing it in a clean working folder or the puppet module builder will package all the unnecessary files.

```console
$ rake module:push
Expand Down
3 changes: 0 additions & 3 deletions features/git.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Feature: git
Then the output should not match /^v1\.0\.1$/
Given a file named "Rakefile" with:
"""
require 'puppetlabs_spec_helper/rake_tasks'
require "#{__dir__}/../../lib/puppet_blacksmith/rake_tasks"
"""
And a file named "metadata.json" with:
Expand Down Expand Up @@ -50,7 +49,6 @@ Feature: git
Then the output should not match /^v1\.0\.1$/
Given a file named "Rakefile" with:
"""
require 'puppetlabs_spec_helper/rake_tasks'
require "#{__dir__}/../../../lib/puppet_blacksmith/rake_tasks"
"""
And a file named "metadata.json" with:
Expand Down Expand Up @@ -87,7 +85,6 @@ Feature: git
Then the output should not match /^1\.0\.1$/
Given a file named "Rakefile" with:
"""
require 'puppetlabs_spec_helper/rake_tasks'
require "#{__dir__}/../../lib/puppet_blacksmith/rake_tasks"
Blacksmith::RakeTask.new do |t|
t.tag_pattern = "%s"
Expand Down
5 changes: 2 additions & 3 deletions features/module.feature
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
Feature: module
puppet-blacksmith needs to work well with puppetlabs_spec_helper
puppet-blacksmith needs to build a module

Scenario: Building a module with metadata.json
Given a file named "Rakefile" with:
"""
require 'puppetlabs_spec_helper/rake_tasks'
require "#{__dir__}/../../lib/puppet_blacksmith/rake_tasks"
"""
And a file named "metadata.json" with:
Expand Down Expand Up @@ -42,6 +41,6 @@ Feature: module
]
}
"""
When I run `rake build`
When I run `rake module:build`
Then the exit status should be 0
And a file named "pkg/maestrodev-test-1.0.0.tar.gz" should exist
1 change: 0 additions & 1 deletion features/push.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Feature: push
Scenario: Pushing a module
Given a file named "Rakefile" with:
"""
require 'puppetlabs_spec_helper/rake_tasks'
require "#{__dir__}/../../lib/puppet_blacksmith/rake_tasks"
"""
And a file named "metadata.json" with:
Expand Down
1 change: 0 additions & 1 deletion features/update_dependency.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Feature: update_dependency_version
Scenario: Bumping a module dependency version when using metadata.json
Given a file named "Rakefile" with:
"""
require 'puppetlabs_spec_helper/rake_tasks'
require "#{__dir__}/../../lib/puppet_blacksmith/rake_tasks"
"""
And a file named "metadata.json" with:
Expand Down
6 changes: 0 additions & 6 deletions features/update_version.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Feature: update_version
Scenario: Bumping a module version when using metadata.json
Given a file named "Rakefile" with:
"""
require 'puppetlabs_spec_helper/rake_tasks'
require "#{__dir__}/../../lib/puppet_blacksmith/rake_tasks"
"""
And a file named "metadata.json" with:
Expand Down Expand Up @@ -81,7 +80,6 @@ Feature: update_version
Scenario: Bumping a module patch version when using metadata.json
Given a file named "Rakefile" with:
"""
require 'puppetlabs_spec_helper/rake_tasks'
require "#{__dir__}/../../lib/puppet_blacksmith/rake_tasks"
"""
And a file named "metadata.json" with:
Expand Down Expand Up @@ -158,7 +156,6 @@ Feature: update_version
Scenario: Bumping a module minor version when using metadata.json
Given a file named "Rakefile" with:
"""
require 'puppetlabs_spec_helper/rake_tasks'
require "#{__dir__}/../../lib/puppet_blacksmith/rake_tasks"
"""
And a file named "metadata.json" with:
Expand Down Expand Up @@ -235,7 +232,6 @@ Feature: update_version
Scenario: Bumping a module major version when using metadata.json
Given a file named "Rakefile" with:
"""
require 'puppetlabs_spec_helper/rake_tasks'
require "#{__dir__}/../../lib/puppet_blacksmith/rake_tasks"
"""
And a file named "metadata.json" with:
Expand Down Expand Up @@ -312,7 +308,6 @@ Feature: update_version
Scenario: Bumping to exact module version when using metadata.json
Given a file named "Rakefile" with:
"""
require 'puppetlabs_spec_helper/rake_tasks'
require "#{__dir__}/../../lib/puppet_blacksmith/rake_tasks"
"""
And I set the environment variables to:
Expand Down Expand Up @@ -392,7 +387,6 @@ Feature: update_version
Scenario: Bumping to exact module version but not setting the environment variable when using metadata.json
Given a file named "Rakefile" with:
"""
require 'puppetlabs_spec_helper/rake_tasks'
require "#{__dir__}/../../lib/puppet_blacksmith/rake_tasks"
"""
And a file named "metadata.json" with:
Expand Down
13 changes: 11 additions & 2 deletions lib/puppet_blacksmith/rake_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def define(args, &task_block)

# clear any (auto-)pre-existing task
[
:build,
:bump,
'bump:major',
'bump:minor',
Expand All @@ -56,6 +57,14 @@ def define(args, &task_block)

namespace :module do

desc 'Build the module using puppet-modulebuilder'
task :build do
require 'puppet/modulebuilder'
builder = Puppet::Modulebuilder::Builder.new(Dir.pwd, nil, nil)
package_file = builder.build
puts "Built #{package_file}"
end

namespace :bump do
[:major, :minor, :patch, :full].each do |level|
desc "Bump module version to the next #{level.upcase} version"
Expand Down Expand Up @@ -126,7 +135,7 @@ def define(args, &task_block)
end

desc "Push module to the Puppet Forge"
task :push => :build do
task :push => :'module:build' do
m = Blacksmith::Modulefile.new
forge = Blacksmith::Forge.new
puts "Uploading to Puppet Forge #{m.author}/#{m.name}"
Expand All @@ -140,7 +149,7 @@ def define(args, &task_block)
end

desc "Release the Puppet module, doing a clean, build, bump_commit, tag, push and git push."
release_dependencies = @build ? [:clean, :build, :bump_commit, :tag, :push] : [:clean, :bump_commit, :tag]
release_dependencies = @build ? [:clean, :'module:build', :bump_commit, :tag, :push] : [:clean, :bump_commit, :tag]
task :release => release_dependencies do
puts "Pushing to remote git repo"
git.push!
Expand Down
3 changes: 1 addition & 2 deletions puppet-blacksmith.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]
s.required_ruby_version = '>= 2.4.0'

s.add_runtime_dependency 'puppet-modulebuilder', '~> 0.1'
s.add_runtime_dependency 'rest-client', '~>2.0'
s.add_development_dependency 'bundler'
s.add_development_dependency 'rake'
s.add_development_dependency 'pdk', '>=1.17.0'
s.add_development_dependency 'puppet', '>=2.7.16'
s.add_development_dependency 'puppetlabs_spec_helper'
s.add_development_dependency 'cucumber'
s.add_development_dependency 'aruba'
s.add_development_dependency 'rspec', '>=3.0.0'
Expand Down

0 comments on commit f955a02

Please sign in to comment.