ra10ke 0.6.0 → 1.1.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: 244a7664e31597a415668faaeb3cf43b3c0243cf6aed478183f91317230e68eb
4
- data.tar.gz: d241ae0aafcb1031dc1d6ef86a69796f79bcfefefe39622b22d5b165be34c696
3
+ metadata.gz: 64e7e73cfb508697efd25e4aec36655c126a168a81fca44345f6564929be6bcd
4
+ data.tar.gz: 2139cb8c668b255a04d975121014006bd94cc4a4b45d71008e37e9e1341c74d6
5
5
  SHA512:
6
- metadata.gz: a889ad1d1f59c4781b895e7abc1f05b0b24776f7976f6c01bb6e45f258239908413f39d5e95def2cc032475243cb27aa39087b937fe6dd3e0a35147b28a6c0bb
7
- data.tar.gz: e4ee4b06d70659f4fc836b90eb73ce22b1fc28076076704da334db5e52ddcd5fe138a0cf95edf80a86afea4885d1fd7fe883621ee04c0fc975a3ac32047711f9
6
+ metadata.gz: d05765b4c95390301ec8c6e0917f251ee60333b09810174c643d1d6a5608824ee96c46d334f60232beb026ea28caa4c4c5ea0e1e6b72b0f12ff7c7fdda6783b4
7
+ data.tar.gz: dc0317d3c47ce2e18e9c8818d7dd468f0acdd8e5a8047dad637938f40745196c66369ac4741293e092f8ab28e6a115aec70e936ea8845cb133c6f1f9108a0cd0
@@ -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,74 @@
1
- CHANGELOG
2
- =========
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [v1.1.0](https://github.com/voxpupuli/ra10ke/tree/v1.1.0) (2021-10-26)
6
+
7
+ [Full Changelog](https://github.com/voxpupuli/ra10ke/compare/v1.0.0...v1.1.0)
8
+
9
+ **Implemented enhancements:**
10
+
11
+ - Support r10k:validate with control\_branch [\#58](https://github.com/voxpupuli/ra10ke/issues/58)
12
+ - Implement GitHub Actions and fix tests [\#62](https://github.com/voxpupuli/ra10ke/pull/62) ([bastelfreak](https://github.com/bastelfreak))
13
+ - Add handling for additional r10k args in validate for control\_branch [\#61](https://github.com/voxpupuli/ra10ke/pull/61) ([ananace](https://github.com/ananace))
14
+ - Add r10k:deprecation task [\#60](https://github.com/voxpupuli/ra10ke/pull/60) ([ananace](https://github.com/ananace))
15
+ - Support r10k:validate with control\_branch modules [\#59](https://github.com/voxpupuli/ra10ke/pull/59) ([ananace](https://github.com/ananace))
16
+ - allow to add other version formats in dependencies [\#56](https://github.com/voxpupuli/ra10ke/pull/56) ([jduepmeier](https://github.com/jduepmeier))
17
+ - Fixes \#52 - validate task fails when repo does not exist [\#53](https://github.com/voxpupuli/ra10ke/pull/53) ([logicminds](https://github.com/logicminds))
18
+
19
+ **Fixed bugs:**
20
+
21
+ - Fix source of control\_branch data [\#63](https://github.com/voxpupuli/ra10ke/pull/63) ([ananace](https://github.com/ananace))
22
+
23
+ **Closed issues:**
24
+
25
+ - validate task fails when repo does not exist [\#52](https://github.com/voxpupuli/ra10ke/issues/52)
26
+
27
+ **Merged pull requests:**
28
+
29
+ - Add Dependabot config [\#65](https://github.com/voxpupuli/ra10ke/pull/65) ([bastelfreak](https://github.com/bastelfreak))
30
+ - Set minimal Ruby version to 2.4.0 [\#64](https://github.com/voxpupuli/ra10ke/pull/64) ([bastelfreak](https://github.com/bastelfreak))
31
+ - Add coverage reports [\#54](https://github.com/voxpupuli/ra10ke/pull/54) ([logicminds](https://github.com/logicminds))
32
+
33
+ ## [v1.0.0](https://github.com/voxpupuli/ra10ke/tree/v1.0.0) (2020-02-08)
34
+
35
+ 2020-02-08
36
+
37
+ Closed Pull Requests:
38
+
39
+ * [#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)
40
+ * [#45](https://github.com/voxpupuli/ra10ke/pull/45) - Add a duplicates check
41
+ * [#48](https://github.com/voxpupuli/ra10ke/pull/48) - Allow semverse 3.x
42
+
43
+ 0.6.2
44
+ -----
45
+
46
+ 2019-08-26
47
+
48
+ Closed Pull Requests:
49
+
50
+ * [#42](https://github.com/voxpupuli/ra10ke/pull/42) - Fix lost refs in validation
51
+
52
+ Again many thanks to the following contributors for submitting PRs:
53
+
54
+ * [Alexander Olofsson](https://github.com/ananace)
55
+
56
+ 0.6.1
57
+ -----
58
+
59
+ 2019-08-17
60
+
61
+ Closed Pull Requests:
62
+
63
+ * [#40](https://github.com/voxpupuli/ra10ke/pull/40) - Fix a fault in the mod handling behaviour
64
+
65
+ Closed Issues:
66
+
67
+ * [#25](https://github.com/voxpupuli/ra10ke/issues/25) - Consider making r10k:install have a default path of '.'
68
+
69
+ Many thanks to the following contributors for submitting PRs:
70
+
71
+ * [Alexander Olofsson](https://github.com/ananace)
3
72
 
4
73
  0.6.0
5
74
  -----
@@ -79,3 +148,6 @@ Many thanks to [Alexander "Ace" Olofsson](https://github.com/ace13) and [James P
79
148
  2015-12-07
80
149
 
81
150
  * Initial release
151
+
152
+
153
+ \* *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).
@@ -79,6 +84,15 @@ runs faster.
79
84
 
80
85
  Reads the Puppetfile in the current directory and installs them under the `path` provided as an argument.
81
86
 
87
+ #### Limitations
88
+
89
+ * It works only with modules from the [Forge](https://forge.puppetlabs.com), and Git.
90
+ SVN modules will be ignored.
91
+ * Git support is explicitly SHA Ref and Tag supported. If tag is used it must follow
92
+ `v0.0.0` convention, other wise it will be ignored.
93
+ * The version has to be specified explicitly. If it is omitted, or it is
94
+ `:latest`, the module will be ignored.
95
+
82
96
  ### r10k:validate[path]
83
97
  The validate rake task will determine if the url is a valid url by connecting
84
98
  to the repository and verififying it actually exists and can be accessed.
@@ -102,7 +116,7 @@ Example
102
116
  ```
103
117
  NAME | URL | REF | STATUS
104
118
  ---------|-----------------------------------------------|--------------------------------|-------
105
- splunk | https://github.com/cudgel/splunk.git | prod | 👍
119
+ splunk | https://github.com/cudgel/splunk.git | dev | 👍
106
120
  r10k | https://github.com/acidprime/r10k | v3.1.1 | 👍
107
121
  gms | https://github.com/npwalker/abrader-gms | gitlab_disable_ssl_verify_s... | 👍
108
122
  rbac | https://github.com/puppetlabs/pltraining-rbac | 2f60e1789a721ce83f8df061e13... | 👍
@@ -114,11 +128,44 @@ gitlab | https://github.com/vshn/puppet-gitlab | 00397b86dfb3487d9df76
114
128
  👍👍 Puppetfile looks good.👍👍
115
129
  ```
116
130
 
117
- #### Limitations
131
+ ### r10k:duplicates
118
132
 
119
- * It works only with modules from the [Forge](https://forge.puppetlabs.com), and Git.
120
- SVN modules will be ignored.
121
- * Git support is explicitly SHA Ref and Tag supported. If tag is used it must follow
122
- `v0.0.0` convention, other wise it will be ignored.
123
- * The version has to be specified explicitly. If it is omitted, or it is
124
- `:latest`, the module will be ignored.
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