Commit f8360024 authored by Carlos Sanchez's avatar Carlos Sanchez

Issue #234 Use organization-module instead organization/module

It is the official naming based on http://docs.puppetlabs.com/puppet/latest/reference/modules_publishing.html
parent 04c4c146
......@@ -2,6 +2,10 @@
## 1.1.x: Requires Ruby >= 1.9, uses Puppet Forge API v3
### 1.1.3
* [Issue #234](https://github.com/rodjek/librarian-puppet/issues/234) Use organization-module instead of organization/module
### 1.1.2
* [Issue #231](https://github.com/rodjek/librarian-puppet/issues/231) Only use the GITHUB_API_TOKEN if it's not empty
......@@ -20,6 +24,10 @@
## 1.0.x: Works on Ruby 1.8, using Puppet Forge API v1
### 1.0.5
* [Issue #234](https://github.com/rodjek/librarian-puppet/issues/234) Use organization-module instead of organization/module
### 1.0.4
* [Issue #231](https://github.com/rodjek/librarian-puppet/issues/231) Only use the GITHUB_API_TOKEN if it's not empty
......
......@@ -54,16 +54,16 @@ This Puppetfile will download all the dependencies listed in your Modulefile fro
forge "https://forge.puppetlabs.com"
mod "puppetlabs/razor"
mod "puppetlabs/ntp", "0.0.3"
mod 'puppetlabs-razor'
mod 'puppetlabs-ntp', "0.0.3"
mod "puppetlabs/apt",
mod 'puppetlabs-apt',
:git => "git://github.com/puppetlabs/puppetlabs-apt.git"
mod "puppetlabs/stdlib",
mod 'puppetlabs-stdlib',
:git => "git://github.com/puppetlabs/puppetlabs-stdlib.git"
mod 'puppetlabs/apache', '0.6.0',
mod 'puppetlabs-apache', '0.6.0',
:github_tarball => 'puppetlabs/puppetlabs-apache'
......@@ -80,29 +80,29 @@ This declares that we want to use the official Puppet Labs Forge as our default
source when pulling down modules. If you run your own local forge, you may
want to change this.
mod "puppetlabs/razor"
mod 'puppetlabs-razor'
Pull in the latest version of the Puppet Labs Razor module from the default
source.
mod "puppetlabs/ntp", "0.0.3"
mod 'puppetlabs-ntp', "0.0.3"
Pull in version 0.0.3 of the Puppet Labs NTP module from the default source.
mod "puppetlabs/apt",
mod 'puppetlabs-apt',
:git => "git://github.com/puppetlabs/puppetlabs-apt.git"
Our puppet infrastructure repository depends on the `apt` module from the
Puppet Labs GitHub repos and checks out the `master` branch.
mod "puppetlabs/apt",
mod 'puppetlabs-apt',
:git => "git://github.com/puppetlabs/puppetlabs-apt.git",
:ref => '0.0.3'
Our puppet infrastructure repository depends on the `apt` module from the
Puppet Labs GitHub repos and checks out a tag of `0.0.3`.
mod "puppetlabs/apt",
mod 'puppetlabs-apt',
:git => "git://github.com/puppetlabs/puppetlabs-apt.git",
:ref => 'feature/master/dans_refactor'
......@@ -124,7 +124,7 @@ with many modules in it. If we need a module from such a repository, we can
use the `:path =>` option here to help Librarian-puppet drill down and find the
module subdirectory.
mod "puppetlabs/apt",
mod 'puppetlabs-apt',
:git => "git://github.com/fake/puppet-modules.git",
:path => "modules/apt"
......
......@@ -20,3 +20,4 @@ Feature: cli/install
Then the exit status should be 0
And the file "modules/stdlib/Modulefile" should match /version *'3\.0\.0'/
And the output should not contain "Executing puppet module install for puppetlabs/stdlib"
And the output should not contain "Executing puppet module install for puppetlabs-stdlib"
......@@ -119,7 +119,7 @@ Feature: cli/install/forge
Then the exit status should be 1
And the output should match:
"""
Unable to find module 'puppetlabs/xxxxx' on http(s)?://forge(api)?.puppetlabs.com
Unable to find module 'puppetlabs-xxxxx' on http(s)?://forge(api)?.puppetlabs.com
"""
Scenario: Install a module with conflicts
......@@ -161,6 +161,22 @@ Feature: cli/install/forge
Then the exit status should be 0
And the file "modules/postgresql/Modulefile" should match /name *'puppetlabs-postgresql'/
Scenario: Source dependencies from Modulefile using dash instead of slash
Given a file named "Puppetfile" with:
"""
forge "http://forge.puppetlabs.com"
modulefile
"""
And a file named "Modulefile" with:
"""
name "random name"
dependency "puppetlabs-postgresql", "2.4.1"
"""
When I run `librarian-puppet install`
Then the exit status should be 0
And the file "modules/postgresql/Modulefile" should match /name *'puppetlabs-postgresql'/
Scenario: Installing a module with duplicated dependencies
Given a file named "Puppetfile" with:
"""
......
......@@ -22,7 +22,7 @@ Feature: cli/outdated
Then the exit status should be 0
And the output should match:
"""
^puppetlabs/stdlib \(3\.1\.0 -> [\.\d]+\)$
^puppetlabs-stdlib \(3\.1\.0 -> [\.\d]+\)$
"""
Scenario: Running outdated with git modules
......@@ -55,6 +55,6 @@ Feature: cli/outdated
Then the exit status should be 0
And PENDING the output should match:
# """
# ^puppetlabs/stdlib \(3\.1\.0 -> [\.\d]+\)$
# ^puppetlabs-stdlib \(3\.1\.0 -> [\.\d]+\)$
# ^test .*$
# """
......@@ -18,7 +18,30 @@ Feature: cli/update
DEPENDENCIES
puppetlabs/stdlib (~> 3.0)
"""
When I run `librarian-puppet update puppetlabs/stdlib`
When I run `librarian-puppet update puppetlabs-stdlib`
Then the exit status should be 0
And the file "Puppetfile.lock" should match /puppetlabs.stdlib \(3\.1\.1\)/
And the file "modules/stdlib/Modulefile" should match /name *'puppetlabs-stdlib'/
And the file "modules/stdlib/Modulefile" should match /version *'3\.1\.1'/
Scenario: Updating a module using organization/module
Given a file named "Puppetfile" with:
"""
forge "http://forge.puppetlabs.com"
mod 'puppetlabs/stdlib', '3.1.x'
"""
And a file named "Puppetfile.lock" with:
"""
FORGE
remote: http://forge.puppetlabs.com
specs:
puppetlabs/stdlib (3.1.0)
DEPENDENCIES
puppetlabs/stdlib (~> 3.0)
"""
When I run `librarian-puppet update --verbose puppetlabs/stdlib`
Then the exit status should be 0
And the file "Puppetfile.lock" should match /puppetlabs.stdlib \(3\.1\.1\)/
And the file "modules/stdlib/Modulefile" should match /name *'puppetlabs-stdlib'/
......
......@@ -8,6 +8,19 @@ module Librarian
end
class Dependency
include Librarian::Puppet::Util
def initialize(name, requirement, source)
assert_name_valid! name
# let's settle on provider-module syntax instead of provider/module
self.name = normalize_name(name)
self.requirement = Requirement.new(requirement)
self.source = source
@manifests = nil
end
class Requirement
def initialize(*args)
args = initialize_normalize_args(args)
......@@ -84,6 +97,8 @@ module Librarian
end
class ManifestSet
include Librarian::Puppet::Util
private
# Check if module doesn't exist and fail fast
......@@ -93,7 +108,7 @@ module Librarian
deps = Set.new
until names.empty?
name = names.shift
name = normalize_name(names.shift)
next if deps.include?(name)
deps << name
......@@ -105,7 +120,6 @@ module Librarian
end
class Manifest
class PreReleaseVersion
# Compares pre-release component ids using Semver 2.0.0 spec
......
......@@ -5,6 +5,7 @@ require 'librarian/manifest_set'
module Librarian
class Lockfile
class Parser
include Librarian::Puppet::Util
def parse(string)
string = string.dup
......@@ -26,8 +27,8 @@ module Librarian
manifests = {}
while lines.first =~ /^ {4}([\w\-\/]+) \((.*)\)$/ # This change allows forward slash
lines.shift
name = $1
manifests[name] = {:version => $2, :dependencies => {}}
name, version = normalize_name($1), $2
manifests[name] = {:version => version, :dependencies => {}}
while lines.first =~ /^ {6}([\w\-\/]+) \((.*)\)$/
lines.shift
manifests[name][:dependencies][$1] = $2.split(/,\s*/)
......@@ -42,9 +43,10 @@ module Librarian
dependencies = []
while lines.first =~ /^ {2}([\w\-\/]+)(?: \((.*)\))?$/ # This change allows forward slash
lines.shift
name, requirement = $1, $2.split(/,\s*/)
name, requirement = normalize_name($1), $2.split(/,\s*/)
dependencies << Dependency.new(name, requirement, manifests_index[name].source)
end
Resolution.new(dependencies, manifests)
end
......
......@@ -121,7 +121,7 @@ module Librarian
end
def install_path(name)
environment.install_path.join(name.split('/').last)
environment.install_path.join(name.split('-').last)
end
def fetch_version(name, version_uri)
......
......@@ -59,7 +59,7 @@ module Librarian
install_path.rmtree
end
unpacked_path = version_unpacked_cache_path(version).join(name.split('/').last)
unpacked_path = version_unpacked_cache_path(version).join(name.split('-').last)
unless unpacked_path.exist?
raise Error, "#{unpacked_path} does not exist, something went wrong. Try removing it manually"
......
......@@ -25,7 +25,7 @@ module Librarian
else
# should never get here as we use one repo object for each module (to be changed in the future)
debug { "Looking up url for #{name}@#{version}" }
release = PuppetForge::Release.find("#{name.sub('/','-')}-#{version}")
release = PuppetForge::Release.find("#{name}-#{version}")
end
"#{source}#{release.file_uri}"
end
......@@ -33,7 +33,7 @@ module Librarian
private
def get_module
@module ||= PuppetForge::Module.find(name.sub('/','-'))
@module ||= PuppetForge::Module.find(name)
raise(Error, "Unable to find module '#{name}' on #{source}") unless @module
@module
end
......
......@@ -98,7 +98,7 @@ module Librarian
end
def install_path(name)
environment.install_path.join(name.split('/').last)
environment.install_path.join(name.split('-').last)
end
def fetch_version(name, version_uri)
......
......@@ -40,11 +40,11 @@ module Librarian
end
def install_version!(version, install_path)
if environment.local? && !vendored?(source.uri.to_s, version)
if environment.local? && !vendored?(vendored_name, version)
raise Error, "Could not find a local copy of #{source.uri} at #{version}."
end
vendor_cache(source.uri.to_s, version) unless vendored?(source.uri.to_s, version)
vendor_cache(source.uri.to_s, version) unless vendored?(vendored_name, version)
cache_version_unpacked! version
......@@ -62,19 +62,19 @@ module Librarian
path.mkpath
target = vendored?(source.uri.to_s, version) ? vendored_path(source.uri.to_s, version) : name
target = vendored?(vendored_name, version) ? vendored_path(vendored_name, version) : name
Librarian::Posix.run!(%W{tar xzf #{target} -C #{path}})
end
def vendor_cache(name, version)
clean_up_old_cached_versions(name)
clean_up_old_cached_versions(vendored_name(name))
url = "https://api.github.com/repos/#{name}/tarball/#{version}"
add_api_token_to_url(url)
environment.vendor!
File.open(vendored_path(name, version).to_s, 'wb') do |f|
File.open(vendored_path(vendored_name(name), version).to_s, 'wb') do |f|
begin
debug { "Downloading <#{url}> to <#{f.path}>" }
open(url,
......@@ -90,7 +90,7 @@ module Librarian
end
def clean_up_old_cached_versions(name)
Dir["#{environment.vendor_cache}/#{name.sub('/', '-')}*.tar.gz"].each do |old_version|
Dir["#{environment.vendor_cache}/#{name}*.tar.gz"].each do |old_version|
FileUtils.rm old_version
end
end
......@@ -159,6 +159,10 @@ module Librarian
options[:headers].each { |k, v| request.add_field k, v }
http.request(request)
end
def vendored_name(name = source.uri.to_s)
name.sub('/','-')
end
end
end
end
......
......@@ -26,11 +26,11 @@ module Librarian
found_path = found_path(name)
raise Error, "Path for #{name} doesn't contain a puppet module" if found_path.nil?
unless name.include? '/'
warn { "Invalid module name '#{name}', you should qualify it with 'ORGANIZATION/#{name}' for resolution to work correctly" }
unless name.include? '/' or name.include? '-'
warn { "Invalid module name '#{name}', you should qualify it with 'ORGANIZATION-#{name}' for resolution to work correctly" }
end
install_path = environment.install_path.join(name.split('/').last)
install_path = environment.install_path.join(name.split('-').last)
if install_path.exist?
debug { "Deleting #{relative_path_to(install_path)}" }
install_path.rmtree
......
......@@ -29,7 +29,7 @@ module Librarian
end
def vendored_path(name, version)
environment.vendor_cache.join("#{name.sub("/", "-")}-#{version}.tar.gz")
environment.vendor_cache.join("#{name}-#{version}.tar.gz")
end
end
......
......@@ -7,16 +7,16 @@ forge "https://forgeapi.puppetlabs.com"
modulefile
# A module from the Puppet Forge
# mod 'puppetlabs/stdlib'
# mod 'puppetlabs-stdlib'
# A module from git
# mod 'puppetlabs/ntp',
# mod 'puppetlabs-ntp',
# :git => 'git://github.com/puppetlabs/puppetlabs-ntp.git'
# A module from a git branch/tag
# mod 'puppetlabs/apt',
# mod 'puppetlabs-apt',
# :git => 'https://github.com/puppetlabs/puppetlabs-apt.git',
# :ref => '1.4.x'
# A module from Github pre-packaged tarball
# mod 'puppetlabs/apache', '0.6.0', :github_tarball => 'puppetlabs/puppetlabs-apache'
# mod 'puppetlabs-apache', '0.6.0', :github_tarball => 'puppetlabs/puppetlabs-apache'
......@@ -33,6 +33,11 @@ module Librarian
new_uri.password = nil
new_uri
end
# normalize module name to use organization-module instead of organization/module
def normalize_name(name)
name.sub('/','-')
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment