Skip to content

Commit d3c964f

Browse files
gavindidrichsendavidmalloncares
authored andcommitted
Update to use puppetcore puppet and facter
This change * Introduces a change to the Gemfile that enables a "switch" on PUPPET_AUTH_TOKEN environment variable. In other words, when not-set, then all gem dependencies will be resolved from https://rubygems.org. If set, then puppet and facter will be resolved from the https://rubygems-puppetcore.puppet.com This commit enables the peadm development team to test its functionality using the puppetcore puppet and facter gems. the Signed-off-by: Gavin Didrichsen <[email protected]>
1 parent 4647764 commit d3c964f

File tree

4 files changed

+114
-11
lines changed

4 files changed

+114
-11
lines changed

.github/workflows/test-migration.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ jobs:
3333
BOLT_GEM: true
3434
BOLT_DISABLE_ANALYTICS: true
3535
LANG: en_US.UTF-8
36+
PUPPET_FORGE_TOKEN: ${{ secrets.PUPPET_FORGE_TOKEN }}
37+
BUNDLE_RUBYGEMS___PUPPETCORE__PUPPET__COM: forge-key:${{ secrets.PUPPET_FORGE_TOKEN }}
3638
strategy:
3739
fail-fast: false
3840
matrix:
@@ -55,10 +57,10 @@ jobs:
5557
uses: actions/checkout@v4
5658
with:
5759
ref: ${{ github.head_ref }}
58-
- name: Activate Ruby 2.7
60+
- name: Activate Ruby 3.2
5961
uses: ruby/setup-ruby@v1
6062
with:
61-
ruby-version: '2.7'
63+
ruby-version: '3.2'
6264
bundler-cache: true
6365
- name: Print bundle environment
6466
if: ${{ github.repository_owner == 'puppetlabs' }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
name: Validate Puppetcore Gem Sources
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
ref:
7+
description: Branch, tag or SHA to checkout
8+
required: true
9+
default: main
10+
jobs:
11+
verify-gemfile:
12+
runs-on: ubuntu-latest
13+
name: Verify Gemfile Dependencies
14+
env:
15+
PUPPET_FORGE_TOKEN: ${{ secrets.PUPPET_FORGE_TOKEN }}
16+
BUNDLE_RUBYGEMS___PUPPETCORE__PUPPET__COM: forge-key:${{ secrets.PUPPET_FORGE_TOKEN }}
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
with:
21+
ref: ${{ github.event.inputs.ref }}
22+
- name: Set up Ruby
23+
uses: ruby/setup-ruby@v1
24+
with:
25+
ruby-version: '3.2'
26+
bundler-cache: true
27+
cache-version: 0 # Helps manage cache versions explicitly
28+
working-directory: .
29+
- name: Install dependencies
30+
run: bundle install
31+
- name: Run Gemfile verification test
32+
run: bundle exec rspec spec/support/gemfile_spec.rb --format documentation

Gemfile

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,21 @@ group :release_prep do
4949
gem "puppetlabs_spec_helper", '~> 6.0', require: false
5050
end
5151

52-
puppet_version = ENV['PUPPET_GEM_VERSION']
53-
facter_version = ENV['FACTER_GEM_VERSION']
54-
hiera_version = ENV['HIERA_GEM_VERSION']
55-
5652
gems = {}
53+
puppet_version = ENV.fetch('PUPPET_GEM_VERSION', nil)
54+
facter_version = ENV.fetch('FACTER_GEM_VERSION', nil)
55+
hiera_version = ENV.fetch('HIERA_GEM_VERSION', nil)
5756

58-
gems['puppet'] = location_for(puppet_version)
59-
60-
# If facter or hiera versions have been specified via the environment
61-
# variables
57+
# If PUPPET_FORGE_TOKEN is set then use authenticated source for both puppet and facter, since facter is a transitive dependency of puppet
58+
# Otherwise, do as before and use location_for to fetch gems from the default source
59+
if !ENV['PUPPET_FORGE_TOKEN'].to_s.empty?
60+
gems['puppet'] = [puppet_version || '~> 8.11', { require: false, source: 'https://rubygems-puppetcore.puppet.com' }]
61+
gems['facter'] = [facter_version || '~> 4.0', { require: false, source: 'https://rubygems-puppetcore.puppet.com' }]
62+
else
63+
gems['puppet'] = location_for(puppet_version)
64+
gems['facter'] = location_for(facter_version) if facter_version
65+
end
6266

63-
gems['facter'] = location_for(facter_version) if facter_version
6467
gems['hiera'] = location_for(hiera_version) if hiera_version
6568

6669
gems.each do |gem_name, gem_params|

spec/support/gemfile_spec.rb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
require 'bundler'
5+
6+
RSpec.describe 'Gemfile.lock verification' do
7+
let(:parser) { Bundler::LockfileParser.new(Bundler.read_file(Bundler.default_lockfile)) }
8+
let(:private_source) { 'https://rubygems-puppetcore.puppet.com/' }
9+
let(:public_source) { 'https://rubygems.org/' }
10+
let(:auth_token_present?) { !ENV['PUPPET_FORGE_TOKEN'].nil? }
11+
12+
# Helper method to get source remotes for a specific gem
13+
def get_gem_source_remotes(gem_name)
14+
spec = parser.specs.find { |s| s.name == gem_name }
15+
return [] unless spec
16+
17+
source = spec.source
18+
return [] unless source.is_a?(Bundler::Source::Rubygems)
19+
20+
source.remotes.map(&:to_s)
21+
end
22+
23+
context 'when PUPPET_FORGE_TOKEN is present' do
24+
before(:each) do
25+
skip 'Skipping private source tests - PUPPET_FORGE_TOKEN not present' unless auth_token_present?
26+
end
27+
28+
it 'has puppet under private source' do
29+
remotes = get_gem_source_remotes('puppet')
30+
expect(remotes).to eq([private_source]),
31+
"Expected puppet to use private source #{private_source}, got: #{remotes.join(', ')}"
32+
expect(remotes).not_to eq([public_source]),
33+
"Expected puppet to not use public source #{public_source}, got: #{remotes.join(', ')}"
34+
end
35+
36+
it 'has facter under private source' do
37+
remotes = get_gem_source_remotes('facter')
38+
expect(remotes).to eq([private_source]),
39+
"Expected facter to use private source #{private_source}, got: #{remotes.join(', ')}"
40+
expect(remotes).not_to eq([public_source]),
41+
"Expected facter to not use public source #{public_source}, got: #{remotes.join(', ')}"
42+
end
43+
end
44+
45+
context 'when PUPPET_FORGE_TOKEN is not present' do
46+
before(:each) do
47+
skip 'Skipping public source tests - PUPPET_FORGE_TOKEN is present' if auth_token_present?
48+
end
49+
50+
it 'has puppet under public source' do
51+
remotes = get_gem_source_remotes('puppet')
52+
expect(remotes).to eq([public_source]),
53+
"Expected puppet to use public source #{public_source}, got: #{remotes.join(', ')}"
54+
expect(remotes).not_to eq([private_source]),
55+
"Expected puppet to not use private source #{private_source}, got: #{remotes.join(', ')}"
56+
end
57+
58+
it 'has facter under public source' do
59+
remotes = get_gem_source_remotes('facter')
60+
expect(remotes).to eq([public_source]),
61+
"Expected facter to use public source #{public_source}, got: #{remotes.join(', ')}"
62+
expect(remotes).not_to eq([private_source]),
63+
"Expected facter to not use private source #{private_source}, got: #{remotes.join(', ')}"
64+
end
65+
end
66+
end

0 commit comments

Comments
 (0)