ra10ke 0.6.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed7cf2819431d671a0b16c4437b8cdc5606be3b7f81660ca63b75b6498f33859
4
- data.tar.gz: 0ff570951916a4c267eb09b9f479c68c890cc121666ee1ae94a1f6cfa0b99575
3
+ metadata.gz: c18588b9b0b4eb792bfcc75c573a7d8107840baf321c20ca4d0ba26aabc03912
4
+ data.tar.gz: 1503a4fa9911f99ac01e12aebd8cbc7f8e3402aa385c411f0861fe082bcaacfd
5
5
  SHA512:
6
- metadata.gz: eea68a63d23b37b4e38a70c167837f84600a91c6d68080f04d288fd17a376e7d6e060f25e7d0d836a4136b8d42a4a7f0b905a135199b08d1468a888deba21a98
7
- data.tar.gz: c7446689752cbbd943d8ac4502e103ead5e8499116a43ee099402f24c1d088afc178bb4b3dccb0af6fd4a11d286871fec493fd10f9ea35fb5f030e0c81f1bd47
6
+ metadata.gz: '078235ff75fc9d159333ef7e2eff5424e01e801e91480778fe035cd9aaba19a4073c0f0b48a2792f08afab4d1e9ac597a8ad4262b3afa220749862bdfb5e11ca'
7
+ data.tar.gz: 3820689a48c0df80436ab56c3b0e27093f5951753ac6997fbfbb27cbccb3c13d2f8151ac01d65f1b8732aebe0b24b002be8fcc6caf5677b089ebdeb94b83f2d5
@@ -0,0 +1,11 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: "bundler" # See documentation for possible values
9
+ directory: "/" # Location of package manifests
10
+ schedule:
11
+ interval: "daily"
@@ -0,0 +1,32 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - '*'
7
+
8
+ jobs:
9
+ release:
10
+ runs-on: ubuntu-latest
11
+ if: github.repository_owner == 'voxpupuli'
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Install Ruby 3.0
15
+ uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: '3.0'
18
+ env:
19
+ BUNDLE_WITHOUT: release
20
+ - name: Build gem
21
+ run: gem build *.gemspec
22
+ - name: Publish gem to rubygems.org
23
+ run: gem push *.gem
24
+ env:
25
+ GEM_HOST_API_KEY: '${{ secrets.RUBYGEMS_AUTH_TOKEN }}'
26
+ - name: Setup GitHub packages access
27
+ run: |
28
+ mkdir -p ~/.gem
29
+ echo ":github: Bearer ${{ secrets.GITHUB_TOKEN }}" >> ~/.gem/credentials
30
+ chmod 0600 ~/.gem/credentials
31
+ - name: Publish gem to GitHub packages
32
+ run: gem push --key github --host https://rubygems.pkg.github.com/voxpupuli *.gem
@@ -0,0 +1,35 @@
1
+ name: Test
2
+
3
+ on:
4
+ - pull_request
5
+ - push
6
+
7
+ env:
8
+ BUNDLE_WITHOUT: release
9
+
10
+ jobs:
11
+ test:
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ include:
17
+ - ruby: "2.4"
18
+ - ruby: "2.5"
19
+ - ruby: "2.6"
20
+ - ruby: "2.7"
21
+ - ruby: "3.0"
22
+ coverage: "yes"
23
+ env:
24
+ COVERAGE: ${{ matrix.coverage }}
25
+ steps:
26
+ - uses: actions/checkout@v2
27
+ - name: Install Ruby ${{ matrix.ruby }}
28
+ uses: ruby/setup-ruby@v1
29
+ with:
30
+ ruby-version: ${{ matrix.ruby }}
31
+ bundler-cache: true
32
+ - name: Run tests
33
+ run: bundle exec rake
34
+ - name: Build gem
35
+ run: gem build *.gemspec
data/.gitignore CHANGED
@@ -1,3 +1,6 @@
1
1
  Gemfile.lock
2
+ coverage
2
3
  pkg
3
4
  .bundle
5
+ vendor
6
+ .vendor
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.3
1
+ 2.5.7
data/.travis.yml CHANGED
@@ -6,6 +6,7 @@ rvm:
6
6
  - '2.3'
7
7
  - '2.4'
8
8
  - '2.5'
9
+ - '2.6'
9
10
  deploy:
10
11
  provider: rubygems
11
12
  api_key:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,56 @@
1
- CHANGELOG
2
- =========
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [v1.2.0](https://github.com/voxpupuli/ra10ke/tree/v1.2.0) (2022-04-21)
6
+
7
+ [Full Changelog](https://github.com/voxpupuli/ra10ke/compare/v1.1.0...v1.2.0)
8
+
9
+ **Closed issues:**
10
+
11
+ - Add support for commit ref [\#67](https://github.com/voxpupuli/ra10ke/issues/67)
12
+
13
+ **Merged pull requests:**
14
+
15
+ - Fix \#67 - Add support for commit ref [\#68](https://github.com/voxpupuli/ra10ke/pull/68) ([logicminds](https://github.com/logicminds))
16
+
17
+ ## [v1.1.0](https://github.com/voxpupuli/ra10ke/tree/v1.1.0) (2021-10-26)
18
+
19
+ [Full Changelog](https://github.com/voxpupuli/ra10ke/compare/v1.0.0...v1.1.0)
20
+
21
+ **Implemented enhancements:**
22
+
23
+ - Support r10k:validate with control\_branch [\#58](https://github.com/voxpupuli/ra10ke/issues/58)
24
+ - Implement GitHub Actions and fix tests [\#62](https://github.com/voxpupuli/ra10ke/pull/62) ([bastelfreak](https://github.com/bastelfreak))
25
+ - Add handling for additional r10k args in validate for control\_branch [\#61](https://github.com/voxpupuli/ra10ke/pull/61) ([ananace](https://github.com/ananace))
26
+ - Add r10k:deprecation task [\#60](https://github.com/voxpupuli/ra10ke/pull/60) ([ananace](https://github.com/ananace))
27
+ - Support r10k:validate with control\_branch modules [\#59](https://github.com/voxpupuli/ra10ke/pull/59) ([ananace](https://github.com/ananace))
28
+ - allow to add other version formats in dependencies [\#56](https://github.com/voxpupuli/ra10ke/pull/56) ([jduepmeier](https://github.com/jduepmeier))
29
+ - Fixes \#52 - validate task fails when repo does not exist [\#53](https://github.com/voxpupuli/ra10ke/pull/53) ([logicminds](https://github.com/logicminds))
30
+
31
+ **Fixed bugs:**
32
+
33
+ - Fix source of control\_branch data [\#63](https://github.com/voxpupuli/ra10ke/pull/63) ([ananace](https://github.com/ananace))
34
+
35
+ **Closed issues:**
36
+
37
+ - validate task fails when repo does not exist [\#52](https://github.com/voxpupuli/ra10ke/issues/52)
38
+
39
+ **Merged pull requests:**
40
+
41
+ - Add Dependabot config [\#65](https://github.com/voxpupuli/ra10ke/pull/65) ([bastelfreak](https://github.com/bastelfreak))
42
+ - Set minimal Ruby version to 2.4.0 [\#64](https://github.com/voxpupuli/ra10ke/pull/64) ([bastelfreak](https://github.com/bastelfreak))
43
+ - Add coverage reports [\#54](https://github.com/voxpupuli/ra10ke/pull/54) ([logicminds](https://github.com/logicminds))
44
+
45
+ ## [v1.0.0](https://github.com/voxpupuli/ra10ke/tree/v1.0.0) (2020-02-08)
46
+
47
+ 2020-02-08
48
+
49
+ Closed Pull Requests:
50
+
51
+ * [#44](https://github.com/voxpupuli/ra10ke/pull/44) - Fix the faulty docs for Ra10ke::Validate#all_refs after [#42](https://github.com/voxpupuli/ra10ke/pull/42)
52
+ * [#45](https://github.com/voxpupuli/ra10ke/pull/45) - Add a duplicates check
53
+ * [#48](https://github.com/voxpupuli/ra10ke/pull/48) - Allow semverse 3.x
3
54
 
4
55
  0.6.2
5
56
  -----
@@ -109,3 +160,6 @@ Many thanks to [Alexander "Ace" Olofsson](https://github.com/ace13) and [James P
109
160
  2015-12-07
110
161
 
111
162
  * Initial release
163
+
164
+
165
+ \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
data/Gemfile CHANGED
@@ -2,3 +2,12 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in ra10ke.gemspec
4
4
  gemspec
5
+
6
+ group :release do
7
+ gem 'github_changelog_generator', :require => false
8
+ end
9
+
10
+ group :coverage, optional: ENV['COVERAGE']!='yes' do
11
+ gem 'simplecov-console', :require => false
12
+ gem 'codecov', :require => false
13
+ end
data/HISTORY.md ADDED
@@ -0,0 +1,118 @@
1
+ ## [v1.0.0](https://github.com/voxpupuli/ra10ke/tree/v1.0.0) (2020-02-08)
2
+
3
+ 2020-02-08
4
+
5
+ Closed Pull Requests:
6
+
7
+ * [#44](https://github.com/voxpupuli/ra10ke/pull/44) - Fix the faulty docs for Ra10ke::Validate#all_refs after [#42](https://github.com/voxpupuli/ra10ke/pull/42)
8
+ * [#45](https://github.com/voxpupuli/ra10ke/pull/45) - Add a duplicates check
9
+ * [#48](https://github.com/voxpupuli/ra10ke/pull/48) - Allow semverse 3.x
10
+
11
+ 0.6.2
12
+ -----
13
+
14
+ 2019-08-26
15
+
16
+ Closed Pull Requests:
17
+
18
+ * [#42](https://github.com/voxpupuli/ra10ke/pull/42) - Fix lost refs in validation
19
+
20
+ Again many thanks to the following contributors for submitting PRs:
21
+
22
+ * [Alexander Olofsson](https://github.com/ananace)
23
+
24
+ 0.6.1
25
+ -----
26
+
27
+ 2019-08-17
28
+
29
+ Closed Pull Requests:
30
+
31
+ * [#40](https://github.com/voxpupuli/ra10ke/pull/40) - Fix a fault in the mod handling behaviour
32
+
33
+ Closed Issues:
34
+
35
+ * [#25](https://github.com/voxpupuli/ra10ke/issues/25) - Consider making r10k:install have a default path of '.'
36
+
37
+ Many thanks to the following contributors for submitting PRs:
38
+
39
+ * [Alexander Olofsson](https://github.com/ananace)
40
+
41
+ 0.6.0
42
+ -----
43
+
44
+ 2019-07-30
45
+
46
+ Closed Pull Requests:
47
+
48
+ * [#35](https://github.com/voxpupuli/ra10ke/pull/35) Adds new validate task for verifying the integrity of all modules specified in the Puppetfile
49
+ * [#33](https://github.com/voxpupuli/ra10ke/pull/33) Refactor tasks, Version tag handling fix, purge option
50
+ * [#32](https://github.com/voxpupuli/ra10ke/pull/32) Make it possible to configure the tasks in the rakefile
51
+
52
+ Many thanks to the following contributors for submitting PRs:
53
+
54
+ * [Corey Osman](https://github.com/logicminds)
55
+ * [Andreas Zuber](https://github.com/ZeroPointEnergy)
56
+
57
+ 0.5.0
58
+ -----
59
+
60
+ 2018-12-26
61
+
62
+ Closed Pull Requests:
63
+
64
+ * [#22](https://github.com/voxpupuli/ra10ke/pull/22) Add rudimentary r10k:install task
65
+ * [#26](https://github.com/voxpupuli/ra10ke/pull/26) make use of the forge command in puppetfile
66
+ * [#29](https://github.com/voxpupuli/ra10ke/pull/29) Abort (exit 1) if Puppetfile syntax check fails
67
+ * [#30](https://github.com/voxpupuli/ra10ke/pull/30) enable travis deployment
68
+
69
+ 0.4.0
70
+ -----
71
+
72
+ 2018-06-17
73
+
74
+ * [#13](https://github.com/voxpupuli/ra10ke/pull/13) Avoid using `desired_ref` directly for Git
75
+ * [#14](https://github.com/voxpupuli/ra10ke/pull/14) Set required Ruby version as `>= 2.1.0`
76
+ * [#15](https://github.com/voxpupuli/ra10ke/pull/15) ignore invalid ref
77
+ * [#16](https://github.com/voxpupuli/ra10ke/pull/16) Use Semantic Versioning for Git tags
78
+ * [#17](https://github.com/voxpupuli/ra10ke/pull/17) Be careful around trimming Git tags
79
+ * [#19](https://github.com/voxpupuli/ra10ke/pull/19) Ensure Puppetfile gets parsed with absolute path
80
+
81
+ Many thanks to the following contributors for submitting the PRs:
82
+ * [Valter Jansons](https://github.com/sigv)
83
+ * [Martin Alfke](https://github.com/tuxmea)
84
+ * [Matthias Baur](https://github.com/baurmatt)
85
+
86
+ 0.3.0
87
+ -----
88
+
89
+ 2017-10-08
90
+
91
+ * [#6](https://github.com/voxpupuli/ra10ke/pull/6) Add a dependency solver based on the Ruby Solve library (thanks to [Jarkko Oranen](https://github.com/oranenj))
92
+ * [#8](https://github.com/voxpupuli/ra10ke/pull/8) Add numeric tag convention support (thanks to [Hervé MARTIN](https://github.com/HerveMARTIN))
93
+
94
+ 0.2.0
95
+ -----
96
+
97
+ 2017-01-03
98
+
99
+ * Moved to [Vox Pupuli](https://voxpupuli.org/)
100
+ * [#3](https://github.com/voxpupuli/ra10ke/pull/3) Update ra10ke with r10k 2.4.0 support
101
+ * [#4](https://github.com/voxpupuli/ra10ke/pull/4) Added git support
102
+
103
+ Many thanks to [Alexander "Ace" Olofsson](https://github.com/ace13) and [James Powis](https://github.com/james-powis) for their contributions!
104
+
105
+ 0.1.1
106
+ -----
107
+
108
+ 2016-08-22
109
+
110
+ * [#1](https://github.com/tampakrap/ra10ke/issues/1) update docs to mention Gemfile and Rakefile
111
+ * properly advertise the user agent
112
+
113
+ 0.1.0
114
+ -----
115
+
116
+ 2015-12-07
117
+
118
+ * Initial release
data/README.md CHANGED
@@ -1,7 +1,12 @@
1
1
  ra10ke
2
2
  ======
3
3
 
4
- [![Gem Version](https://badge.fury.io/rb/ra10ke.svg)](https://badge.fury.io/rb/ra10ke)
4
+ [![License](https://img.shields.io/github/license/voxpupuli/ra10ke.svg)](https://github.com/voxpupuli/ra10ke/blob/master/LICENSE.txt)
5
+ [![Test](https://github.com/voxpupuli/ra10ke/actions/workflows/test.yml/badge.svg)](https://github.com/voxpupuli/ra10ke/actions/workflows/test.yml)
6
+ [![codecov](https://codecov.io/gh/voxpupuli/ra10ke/branch/master/graph/badge.svg?token=Mypkl78hvK)](https://codecov.io/gh/voxpupuli/ra10ke)
7
+ [![Release](https://github.com/voxpupuli/ra10ke/actions/workflows/release.yml/badge.svg)](https://github.com/voxpupuli/ra10ke/actions/workflows/release.yml)
8
+ [![RubyGem Version](https://img.shields.io/gem/v/ra10ke.svg)](https://rubygems.org/gems/ra10ke)
9
+ [![RubyGem Downloads](https://img.shields.io/gem/dt/ra10ke.svg)](https://rubygems.org/gems/ra10ke)
5
10
 
6
11
  Rake tasks related to [R10K](https://github.com/puppetlabs/r10k) and
7
12
  [Puppetfile](https://github.com/puppetlabs/r10k/blob/master/doc/puppetfile.mkd).
@@ -111,7 +116,7 @@ Example
111
116
  ```
112
117
  NAME | URL | REF | STATUS
113
118
  ---------|-----------------------------------------------|--------------------------------|-------
114
- splunk | https://github.com/cudgel/splunk.git | prod | 👍
119
+ splunk | https://github.com/cudgel/splunk.git | dev | 👍
115
120
  r10k | https://github.com/acidprime/r10k | v3.1.1 | 👍
116
121
  gms | https://github.com/npwalker/abrader-gms | gitlab_disable_ssl_verify_s... | 👍
117
122
  rbac | https://github.com/puppetlabs/pltraining-rbac | 2f60e1789a721ce83f8df061e13... | 👍
@@ -123,3 +128,44 @@ gitlab | https://github.com/vshn/puppet-gitlab | 00397b86dfb3487d9df76
123
128
  👍👍 Puppetfile looks good.👍👍
124
129
  ```
125
130
 
131
+ ### r10k:duplicates
132
+
133
+ This rake task parses the Puppetfile and looks for modules with duplicate
134
+ declarations.
135
+
136
+ All found duplicates are reported along with their source and their version
137
+ (if taken from the Forge) or their ref/tag/branch. (if taken from git)
138
+
139
+ Example
140
+
141
+ ```
142
+ puppet:
143
+ - abstractit/puppet from the forge at version 2.4.1
144
+ - theforeman/puppet from the forge at version 12.0.1
145
+ - puppet from git on the branch master at https://github.com/voxpupuli/puppet-module.git
146
+
147
+ gitlab:
148
+ - puppet/gitlab from the forge at version 4.0.1
149
+ - gitlab from git on the ref 00397b86dfb3487d9df768cbd3698d362132b5bf at https://github.com/vshn/puppet-gitlab
150
+
151
+ Error: Duplicates exist in the Puppetfile
152
+ ```
153
+
154
+ ### r10k:deprecation
155
+
156
+ This rake task checks all the Forge modules listed in the Puppetfile, looking
157
+ for modules that are marked as deprecated on the Forge.
158
+
159
+ Example
160
+
161
+ ```
162
+ NAME | DEPRECATED_AT
163
+ ------------------------|--------------------------
164
+ kemra102-auditd | 2021-07-22 12:11:46
165
+ puppet-staging | 2018-12-18 11:11:29
166
+ puppetlabs-resource_api | 2021-03-31 12:53:24
167
+ puppetlabs-ruby | 2021-04-22 10:29:42
168
+ puppetlabs-translate | 2021-03-19 10:11:51
169
+
170
+ Error: Puppetfile contains deprecated modules.
171
+ ```
data/Rakefile CHANGED
@@ -14,3 +14,16 @@ task :default => [:spec]
14
14
  RSpec::Core::RakeTask.new(:spec) do |spec|
15
15
  spec.pattern = FileList['spec/**/*_spec.rb']
16
16
  end
17
+
18
+ begin
19
+ require 'github_changelog_generator/task'
20
+ GitHubChangelogGenerator::RakeTask.new :changelog do |config|
21
+ version = Ra10ke::VERSION
22
+ config.future_release = "v#{version}" if version =~ /^\d+\.\d+.\d+$/
23
+ config.header = "# Changelog\n\nAll notable changes to this project will be documented in this file."
24
+ config.exclude_labels = %w{duplicate question invalid wontfix wont-fix skip-changelog}
25
+ config.user = 'voxpupuli'
26
+ config.project = 'ra10ke'
27
+ end
28
+ rescue LoadError
29
+ end
@@ -1,4 +1,34 @@
1
1
  module Ra10ke::Dependencies
2
+ @@version_formats = {}
3
+
4
+ # Registers a block that finds the latest version.
5
+ # The block will be called with a list of tags.
6
+ # If the block returns nil the next format will be tried.
7
+ def self.register_version_format(name, &block)
8
+ @@version_formats[name] = block
9
+ end
10
+
11
+ # semver is the default version format.
12
+ register_version_format(:semver) do |tags|
13
+ latest_tag = tags.map do |tag|
14
+ begin
15
+ Semverse::Version.new tag[/\Av?(.*)\Z/, 1]
16
+ rescue Semverse::InvalidVersionFormat
17
+ # ignore tags that do not comply to semver
18
+ nil
19
+ end
20
+ end.select { |tag| !tag.nil? }.sort.last.to_s.downcase
21
+ latest_ref = tags.detect { |tag| tag[/\Av?(.*)\Z/, 1] == latest_tag }
22
+ end
23
+
24
+ def get_latest_ref(remote_refs)
25
+ tags = remote_refs['tags'].keys
26
+ latest_ref = nil
27
+ @@version_formats.detect { |_, block| latest_ref = block.call(tags) }
28
+ latest_ref = 'undef (tags do not follow any known pattern)' if latest_ref.nil?
29
+ latest_ref
30
+ end
31
+
2
32
  def define_task_dependencies(*_args)
3
33
  desc "Print outdated forge modules"
4
34
  task :dependencies do
@@ -44,17 +74,10 @@ module Ra10ke::Dependencies
44
74
  # we have to be be opinionated here
45
75
  # so semantic versioning (vX.Y.Z) it is for us
46
76
  # as well as support for skipping the leading v letter
47
- tags = remote_refs['tags'].keys
48
- latest_tag = tags.map do |tag|
49
- begin
50
- Semverse::Version.new tag[/\Av?(.*)\Z/, 1]
51
- rescue Semverse::InvalidVersionFormat
52
- # ignore tags that do not comply to semver
53
- nil
54
- end
55
- end.select { |tag| !tag.nil? }.sort.last.to_s.downcase
56
- latest_ref = tags.detect { |tag| tag[/\Av?(.*)\Z/, 1] == latest_tag }
57
- latest_ref = 'undef (tags do not match semantic versioning)' if latest_ref.nil?
77
+ #
78
+ # register own version formats with
79
+ # Ra10ke::Dependencies.register_version_format(:name, &block)
80
+ latest_ref = get_latest_ref(remote_refs)
58
81
  elsif ref.match(/^[a-z0-9]{40}$/)
59
82
  # for sha just assume head should be tracked
60
83
  latest_ref = remote_refs['head'][:sha]
@@ -66,6 +89,5 @@ module Ra10ke::Dependencies
66
89
  end
67
90
  end
68
91
  end
69
-
70
92
  end
71
93
  end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ra10ke/puppetfile_parser'
4
+ require 'English'
5
+ require 'puppet_forge'
6
+ require 'table_print'
7
+ require 'time'
8
+
9
+ module Ra10ke::Deprecation
10
+ # Validate the git urls and refs
11
+ def define_task_deprecation(*)
12
+ desc 'Validate that no forge modules are deprecated'
13
+ task :deprecation do
14
+ valid = Ra10ke::Deprecation::Validation.new(get_puppetfile.puppetfile_path)
15
+ exit_code = 0
16
+ if valid.bad_mods?
17
+ exit_code = 1
18
+ message = "\nError: Puppetfile contains deprecated modules."
19
+ tp valid.sorted_mods, :name, :deprecated_at
20
+ else
21
+ message = 'Puppetfile contains no deprecated Forge modules.'
22
+ end
23
+ abort(message) if exit_code.positive?
24
+
25
+ puts message
26
+ end
27
+ end
28
+
29
+ class Validation
30
+ include Ra10ke::PuppetfileParser
31
+
32
+ attr_reader :puppetfile
33
+
34
+ def initialize(file)
35
+ file ||= './Puppetfile'
36
+ @puppetfile = File.expand_path(file)
37
+ abort("Puppetfile does not exist at #{puppetfile}") unless File.readable?(puppetfile)
38
+ end
39
+
40
+ # @return [Array[Hash]] array of module information and git status
41
+ def deprecated_modules
42
+ @deprecated_modules ||= begin
43
+ deprecated = forge_modules(puppetfile).map do |mod|
44
+ # For Ruby 2.4 support
45
+ begin # rubocop:disable Style/RedundantBegin
46
+ module_name = "#{mod[:namespace] || mod[:name]}-#{mod[:name]}"
47
+ forge_data = PuppetForge::Module.find(module_name)
48
+
49
+ next forge_data if forge_data.deprecated_at
50
+
51
+ nil
52
+ rescue Faraday::ResourceNotFound
53
+ nil
54
+ end
55
+ end
56
+ deprecated.compact.map do |mod|
57
+ { name: mod.slug, deprecated_at: Time.parse(mod.deprecated_at) }
58
+ end
59
+ end
60
+ end
61
+
62
+ # @return [Boolean] - true if there are any bad mods
63
+ def bad_mods?
64
+ deprecated_modules.any?
65
+ end
66
+
67
+ # @return [Hash] - sorts the mods based on good/bad
68
+ def sorted_mods
69
+ deprecated_modules.sort_by { |a| a[:name] }
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ra10ke/monkey_patches'
4
+ require 'ra10ke/puppetfile_parser'
5
+
6
+ module Ra10ke::Duplicates
7
+ def define_task_duplicates(*_args)
8
+ desc "Check Puppetfile for duplicates"
9
+ task :duplicates do
10
+ duplicates = Ra10ke::Duplicates::Verification.new(get_puppetfile.puppetfile_path).duplicates
11
+ exit_code = 0
12
+ if duplicates.any?
13
+ exit_code = 1
14
+ message = 'Error: Duplicates exist in the Puppetfile'
15
+
16
+ duplicates.map do |name, sources|
17
+ puts "#{name}:"
18
+ sources.each do |source|
19
+ puts "- #{source}"
20
+ end
21
+
22
+ puts
23
+ end
24
+ else
25
+ message = 'Puppetfile is free of duplicates'
26
+ end
27
+
28
+ abort(message) if exit_code.positive?
29
+ puts message
30
+ end
31
+ end
32
+
33
+ class Verification
34
+ include Ra10ke::PuppetfileParser
35
+ Module = Struct.new(:namespace, :name, :args) do
36
+ def git?
37
+ args.key? :git
38
+ end
39
+
40
+ def forge?
41
+ !git?
42
+ end
43
+
44
+ def type
45
+ git? ? 'git' : 'forge'
46
+ end
47
+
48
+ def to_s
49
+ str = "#{[namespace, name].compact.join '/'}"
50
+
51
+ if git?
52
+ ref = args[:ref] || args[:tag] || args[:branch]
53
+ ref_type = (args[:ref] && 'ref') || (args[:tag] && 'tag') || (args[:branch] && 'branch')
54
+ str += " from git on the #{ref_type} #{ref} at #{args[:git]}"
55
+ elsif args.key? :version
56
+ str += " from the forge at version #{args[:version]}"
57
+ end
58
+
59
+ str
60
+ end
61
+ end
62
+
63
+ attr_reader :puppetfile
64
+
65
+ def initialize(file)
66
+ file ||= './Puppetfile'
67
+ @puppetfile = File.expand_path(file)
68
+ abort("Puppetfile does not exist at #{puppetfile}") unless File.readable?(puppetfile)
69
+ end
70
+
71
+ def duplicates
72
+ to_ret = {}
73
+ modules(puppetfile).each do |mod|
74
+ (to_ret[mod[:name]] ||= []) << Module.new(mod[:namespace], mod[:name], mod[:args])
75
+ end
76
+ to_ret.select { |_k, v| v.count > 1 }
77
+ end
78
+ end
79
+ end