puppetfile-updater 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzY1M2M4NDEzYzgyZjQ1NzFmOWNhMzE5MDc1OTczOGI5NzIyNDcxOA==
5
+ data.tar.gz: !binary |-
6
+ OGFlODkwZGIyYTg3M2IxZmY1OTIyNjRmNjA0OTUyY2FiNGViNjRhZQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YmQ1MmIxNWFjMWYzZjY3NzcyMjA2MjZkOGZiZGY3NWY2ZjZkZjc1MjdkNTkz
10
+ NzQyMmU2MDRhOGZiMjM1ZGQ2MzcyNTU5MDViYTFlYWZhOTFmNDkzMjY3NTUy
11
+ MWMzMjE2OWVkZDI0YTQ3YTE4MDczOWM2YjM5NDA1OWU0ZTU5NmE=
12
+ data.tar.gz: !binary |-
13
+ MDg2ODI4MzZiYzg3OWJlNjkwZmUyM2E5NjM2YzhhMDI4MzBiMjBjZjQyNzY5
14
+ ZTA2ODg2M2Q2ZDVlMWZjMjVlYzY5MDZhYjU2NGJmM2VjMjI1MTRiOWJlMzNm
15
+ MTU2MjkyODY0ZGQ4N2JmMDZjOGRhNzQwZDA0NDM5ZWFkZTUwMTY=
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ Puppetfile-updater
2
+ ===================
3
+
4
+ [![Build Status](https://img.shields.io/travis/camptocamp/puppetfile-updater.svg)](https://travis-ci.org/camptocamp/puppetfile-updater)
5
+ [![Gem Version](https://img.shields.io/gem/v/puppetfile-updater.svg)](https://rubygems.org/gems/puppetfile-updater)
6
+ [![Gem Downloads](https://img.shields.io/gem/dt/puppetfile-updater.svg)](https://rubygems.org/gems/puppetfile-updater)
7
+ [![Coverage Status](https://img.shields.io/coveralls/camptocamp/puppetfile-updater.svg)](https://coveralls.io/r/camptocamp/puppetfile-updater?branch=master)
8
+ [![Gemnasium](https://img.shields.io/gemnasium/camptocamp/puppetfile-updater.svg)](https://gemnasium.com/camptocamp/puppetfile-updater)
9
+
10
+ Puppetfile is a cool format, used by [librarian-puppet](https://github.com/rodjek/librarian-puppet) and [r10k](https://github.com/puppetlabs/r10k) to install and maintain collection of Puppet modules.
11
+
12
+ However, keeping it up-to-date with newer versions of said modules can be a difficult task.
13
+
14
+ This gem provides rake tasks to ease this job, by connecting to the Puppet Forge and GitHub and fetching the new versions or references for you.
15
+
16
+
17
+ ## Simple usage
18
+
19
+ In your Rakefile:
20
+
21
+ ```ruby
22
+ require 'puppetfile-updater/task'
23
+
24
+ # Update all modules, avoid major version updates
25
+ PuppetfileUpdater::RakeTask.new :sync_refs do |config|
26
+ # This is required to avoid hitting the GitHub connection rate
27
+ config.gh_login = 'github_robot'
28
+ config.gh_password = 'github_password'
29
+ end
30
+
31
+ # Only update Camptocamp modules, including major version updates
32
+ PuppetfileUpdater::RakeTask.new :sync_c2c_refs do |config|
33
+ config.user = 'camptocamp'
34
+ config.gh_login = 'github_robot'
35
+ config.gh_password = 'github_password'
36
+ config.major = true
37
+ end
38
+ ```
39
+
@@ -0,0 +1,102 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+
4
+ class PuppetfileUpdater
5
+ # Public: A Rake task that can be loaded and used with everything you need.
6
+ #
7
+ # Examples
8
+ #
9
+ # require 'librarian-sync-puppet'
10
+ # PuppetfileUpdater::RakeTask.new
11
+ class RakeTask < ::Rake::TaskLib
12
+ include ::Rake::DSL if defined?(::Rake::DSL)
13
+
14
+ attr_accessor :user
15
+ attr_accessor :module
16
+ attr_accessor :major
17
+ attr_accessor :gh_login
18
+ attr_accessor :gh_password
19
+
20
+ # Public: Initialise a new PuppetfileUpdater::RakeTask.
21
+ #
22
+ # Example
23
+ #
24
+ # PuppetfileUpdater::RakeTask.new
25
+ def initialize(*args, &task_block)
26
+ @name = args.shift || :lint
27
+
28
+ define(args, &task_block)
29
+ end
30
+
31
+ def define(args, &task_block)
32
+ desc 'Update module references in the Puppetfile'
33
+
34
+ task_block.call(*[self, args].slice(0, task_block.arity)) if task_block
35
+
36
+ # clear any (auto-)pre-existing task
37
+ Rake::Task[@name].clear if Rake::Task.task_defined?(@name)
38
+
39
+ task @name do
40
+ require 'augeas'
41
+ require 'octokit'
42
+ require 'puppet_forge'
43
+
44
+ @user ||= '.*'
45
+
46
+ gh_opts = @gh_login.nil? ? { } : {
47
+ :login => @gh_login,
48
+ :password => @gh_password,
49
+ }
50
+ github = Octokit::Client.new gh_opts
51
+
52
+ libdir = File.dirname(__FILE__)
53
+ lens_dir = File.expand_path(File.join(libdir, '..', '..', 'augeas', 'lenses'))
54
+ Augeas.open(Dir.pwd, lens_dir, Augeas::NO_MODL_AUTOLOAD) do |aug|
55
+ aug.transform(
56
+ :incl => '/Puppetfile',
57
+ :excl => [],
58
+ :lens => 'Puppetfile.lns',
59
+ :name => 'Puppetfile',
60
+ )
61
+ aug.load!
62
+
63
+ # Update from GitHub
64
+ aug.match("/files/Puppetfile/*[git=~regexp('.*/#{@user}/.*')]").each do |mpath|
65
+ m = aug.get(mpath)
66
+ next if !@module.nil? && @module != m.gsub(%r{.*[-/]}, '')
67
+
68
+ warn "W: #{m} is a fork!" unless m =~ /#{@user}/
69
+
70
+ git_url = aug.get("#{mpath}/git")
71
+ repo = Octokit::Repository.from_url(git_url.gsub(/\.git$/, ''))
72
+ commits = github.commits(repo)
73
+ aug.set("#{mpath}/ref", commits[0].sha[0...7])
74
+ end
75
+
76
+ # Update from Forge
77
+ PuppetForge.user_agent = 'Puppetfile-Updater/0.1.0'
78
+ aug.match("/files/Puppetfile/*[label()!='#comment' and .=~regexp('#{@user}/.*') and @version]").each do |mpath|
79
+ m = aug.get(mpath).gsub('/', '-')
80
+ next if !@module.nil? && @module != m.gsub(%r{.*[-/]}, '')
81
+ v = aug.get("#{mpath}/@version")
82
+ forge_m = PuppetForge::Module.find(m)
83
+ new_v = forge_m.releases[0].version
84
+ if new_v.split('.')[0] != v.split('.')[0]
85
+ if @major
86
+ warn "W: #{m} has incompatible changes between #{v} and #{new_v}"
87
+ aug.set("#{mpath}/@version", forge_m.releases[0].version)
88
+ else
89
+ warn "W: Not upgrading #{m} from #{v} to new major version #{new_v}"
90
+ end
91
+ else
92
+ warn "W: #{m} got new features between #{v} and #{new_v}" if new_v.split('.')[1] != v.split('.')[1]
93
+ aug.set("#{mpath}/@version", forge_m.releases[0].version)
94
+ end
95
+ end
96
+
97
+ aug.save!
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
File without changes
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppetfile-updater
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Camptocamp
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-24 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: ruby-augeas
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: octokit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: puppet_forge
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: ! ' Keep your Puppet file up-to-date with latest versions from the
70
+ Forge and GitHub.
71
+
72
+ '
73
+ email: raphael.pinson@camptocamp.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - README.md
79
+ - lib/puppetfile-updater.rb
80
+ - lib/puppetfile-updater/task.rb
81
+ homepage: https://github.com/camptocamp/puppetfile-updater
82
+ licenses:
83
+ - Apache-2.0
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.4.5
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Keep your Puppetfile up-to-date.
105
+ test_files: []