Skip to content

Commit db16f01

Browse files
Refactor from PUPPET_AUTH_TOKEN to PUPPET_FORGE_TOKEN
Signed-off-by: Gavin Didrichsen <[email protected]>
1 parent a4833cc commit db16f01

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed

.github/workflows/validate-puppetcore-gem-sources.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ jobs:
1414
name: Verify Gemfile Dependencies
1515

1616
env:
17-
PUPPET_AUTH_TOKEN: ${{ secrets.PUPPET_AUTH_TOKEN }}
18-
BUNDLE_RUBYGEMS___PUPPETCORE__PUPPET__COM: "forge-key:${{ secrets.PUPPET_AUTH_TOKEN }}"
17+
PUPPET_FORGE_TOKEN: ${{ secrets.PUPPET_FORGE_TOKEN }}
18+
BUNDLE_RUBYGEMS___PUPPETCORE__PUPPET__COM: "forge-key:${{ secrets.PUPPET_FORGE_TOKEN }}"
1919

2020
steps:
2121
- name: Checkout repository

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ puppet_version = ENV.fetch('PUPPET_GEM_VERSION', nil)
5454
facter_version = ENV.fetch('FACTER_GEM_VERSION', nil)
5555
hiera_version = ENV.fetch('HIERA_GEM_VERSION', nil)
5656

57-
# If PUPPET_AUTH_TOKEN is set then use authenticated source for both puppet and facter, since facter is a transitive dependency of puppet
57+
# If PUPPET_FORGE_TOKEN is set then use authenticated source for both puppet and facter, since facter is a transitive dependency of puppet
5858
# Otherwise, do as before and use location_for to fetch gems from the default source
59-
if !ENV['PUPPET_AUTH_TOKEN'].to_s.empty?
59+
if !ENV['PUPPET_FORGE_TOKEN'].to_s.empty?
6060
gems['puppet'] = [puppet_version || '~> 8.11', { require: false, source: 'https://rubygems-puppetcore.puppet.com' }]
6161
gems['facter'] = [facter_version || '~> 4.0', { require: false, source: 'https://rubygems-puppetcore.puppet.com' }]
6262
else

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)