From 4115437cce3cecd4c1a0f16441c19f87aafea2dc Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 15:43:47 -0600 Subject: [PATCH 01/60] lyraphase_workstation::bashrc: Update ChefSpec tests to check homebrew_no_cleanup_formulae and homebrew_github_api_token edge cases --- spec/unit/recipes/bashrc_spec.rb | 118 ++++++++++++++++++++++--------- 1 file changed, 85 insertions(+), 33 deletions(-) diff --git a/spec/unit/recipes/bashrc_spec.rb b/spec/unit/recipes/bashrc_spec.rb index ba13b25..21c5d61 100644 --- a/spec/unit/recipes/bashrc_spec.rb +++ b/spec/unit/recipes/bashrc_spec.rb @@ -23,46 +23,98 @@ require 'spec_helper' describe_recipe 'lyraphase_workstation::bashrc' do - # Override ChefSpec attributes from spec_shared_contexts - let(:chefspec_options) { - require 'securerandom' - { - default_attributes: {}, - normal_attributes: { 'lyraphase_workstation': { - 'bashrc': { - 'homebrew_github_api_token': "gh_#{SecureRandom.hex(20)}", - 'user_fullname': 'Barney Rubble', - 'user_email': 'barney.rubble@lyraphase.com', - 'user_gpg_keyid': "0x#{SecureRandom.hex(8)}" + context 'when given all bashrc attributes' do + # Override ChefSpec attributes from spec_shared_contexts + let(:chefspec_options) { + require 'securerandom' + { + default_attributes: {}, + normal_attributes: { 'lyraphase_workstation': { + 'bashrc': { + 'homebrew_github_api_token': "gh_#{SecureRandom.hex(20)}", + 'user_fullname': 'Barney Rubble', + 'user_email': 'barney.rubble@lyraphase.com', + 'user_gpg_keyid': "0x#{SecureRandom.hex(8)}", + 'homebrew_no_cleanup_formulae': ['argocd','eksctl','kustomize','rancher-cli','kubernetes-cli'] + } } - } - }, - automatic_attributes: {} + }, + automatic_attributes: {} + } } - } - let(:bashrc_path) { '/Users/brubble/.bashrc' } - let(:bash_logout_path) { '/Users/brubble/.bash_logout' } + let(:bashrc_path) { '/Users/brubble/.bashrc' } + let(:bash_logout_path) { '/Users/brubble/.bash_logout' } - it 'installs custom .bashrc into user homedir' do - expect(chef_run).to create_template(bashrc_path).with( - user: 'brubble', - mode: '0644' - ) + it 'installs custom .bashrc into user homedir' do + expect(chef_run).to create_template(bashrc_path).with( + user: 'brubble', + mode: '0644' + ) - [ "export HOMEBREW_GITHUB_API_TOKEN='#{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token']}'", - "export DEBFULLNAME='#{chef_run.node['lyraphase_workstation']['bashrc']['user_fullname']}'", - "export DEBEMAIL='#{chef_run.node['lyraphase_workstation']['bashrc']['user_email']}'", - "export DEBSIGN_KEYID='#{chef_run.node['lyraphase_workstation']['bashrc']['user_gpg_keyid']}'", - ].each do |expected_regex| - expect(chef_run).to render_file(bashrc_path).with_content(Regexp.new("^\s*#{expected_regex}\s*(#.*)?$")) + [ "export HOMEBREW_GITHUB_API_TOKEN='#{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token']}'", + "export DEBFULLNAME='#{chef_run.node['lyraphase_workstation']['bashrc']['user_fullname']}'", + "export DEBEMAIL='#{chef_run.node['lyraphase_workstation']['bashrc']['user_email']}'", + "export DEBSIGN_KEYID='#{chef_run.node['lyraphase_workstation']['bashrc']['user_gpg_keyid']}'", + "export HOMEBREW_NO_CLEANUP_FORMULAE=#{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_no_cleanup_formulae'].join(',')}" + ].each do |expected_regex| + expect(chef_run).to render_file(bashrc_path).with_content(Regexp.new("^\s*#{expected_regex}\s*(#.*)?$")) + end + end + + it 'installs custom .bash_logout into user homedir' do + expect(chef_run).to create_template(bash_logout_path).with( + user: 'brubble', + mode: '0644' + ) end end - it 'installs custom .bash_logout into user homedir' do - expect(chef_run).to create_template(bash_logout_path).with( - user: 'brubble', - mode: '0644' - ) + context 'when given no (default) bashrc attributes' do + # Use ChefSpec attributes from spec_shared_contexts + let(:expected_attributes) { + { + lyraphase_workstation: { + bashrc: { + user_fullname: 'James Cuzella', + user_email: 'james.cuzella@lyraphase.com', + user_gpg_keyid: '0x2689A459B1568D09' + } + } + } + } + + let(:bashrc_path) { '/Users/brubble/.bashrc' } + let(:bash_logout_path) { '/Users/brubble/.bash_logout' } + + it 'installs custom .bashrc into user homedir' do + expect(chef_run).to create_template(bashrc_path).with( + user: 'brubble', + mode: '0644' + ) + + [ "export DEBFULLNAME='#{chef_run.node['lyraphase_workstation']['bashrc']['user_fullname']}'", + "export DEBEMAIL='#{chef_run.node['lyraphase_workstation']['bashrc']['user_email']}'", + "export DEBSIGN_KEYID='#{chef_run.node['lyraphase_workstation']['bashrc']['user_gpg_keyid']}'" + ].each do |expected_regex| + expect(chef_run).to render_file(bashrc_path).with_content(Regexp.new("^\s*#{expected_regex}\s*(#.*)?$")) + end + + # Default is no / empty attributes: + # - homebrew_github_api_token + # - homebrew_no_cleanup_formulae + [ "export HOMEBREW_GITHUB_API_TOKEN='#{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token']}'", + "export HOMEBREW_NO_CLEANUP_FORMULAE=.*" + ].each do |expected_regex| + expect(chef_run).to_not render_file(bashrc_path).with_content(/^\s*export HOMEBREW_NO_CLEANUP_FORMULAE=.*$/) + end + end + + it 'installs custom .bash_logout into user homedir' do + expect(chef_run).to create_template(bash_logout_path).with( + user: 'brubble', + mode: '0644' + ) + end end end From feefc9db1e40aacc358fb07dde156b8f891969f6 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 16:27:08 -0600 Subject: [PATCH 02/60] lyraphase_workstation::bashrc: Fix negated with_content matching (Ref: chefspec/chefspec#865 ) --- spec/unit/recipes/bashrc_spec.rb | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/spec/unit/recipes/bashrc_spec.rb b/spec/unit/recipes/bashrc_spec.rb index 21c5d61..2ec40ac 100644 --- a/spec/unit/recipes/bashrc_spec.rb +++ b/spec/unit/recipes/bashrc_spec.rb @@ -46,7 +46,7 @@ let(:bashrc_path) { '/Users/brubble/.bashrc' } let(:bash_logout_path) { '/Users/brubble/.bash_logout' } - it 'installs custom .bashrc into user homedir' do + it 'installs custom .bashrc into user homedir with given settings' do expect(chef_run).to create_template(bashrc_path).with( user: 'brubble', mode: '0644' @@ -72,22 +72,10 @@ context 'when given no (default) bashrc attributes' do # Use ChefSpec attributes from spec_shared_contexts - let(:expected_attributes) { - { - lyraphase_workstation: { - bashrc: { - user_fullname: 'James Cuzella', - user_email: 'james.cuzella@lyraphase.com', - user_gpg_keyid: '0x2689A459B1568D09' - } - } - } - } - let(:bashrc_path) { '/Users/brubble/.bashrc' } let(:bash_logout_path) { '/Users/brubble/.bash_logout' } - it 'installs custom .bashrc into user homedir' do + it 'installs custom .bashrc into user homedir with expected settings' do expect(chef_run).to create_template(bashrc_path).with( user: 'brubble', mode: '0644' @@ -106,7 +94,11 @@ [ "export HOMEBREW_GITHUB_API_TOKEN='#{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token']}'", "export HOMEBREW_NO_CLEANUP_FORMULAE=.*" ].each do |expected_regex| - expect(chef_run).to_not render_file(bashrc_path).with_content(/^\s*export HOMEBREW_NO_CLEANUP_FORMULAE=.*$/) + # Note: Negated with_content requires passing a Proc / Block! + # Reference: https://github.com/chefspec/chefspec/issues/865 + expect(chef_run).to(render_file(bashrc_path).with_content do |content| + expect(content).not_to match(Regexp.new("^\s*#{expected_regex}\s*(#.*)?$")) + end) end end From 5ac0ee00a9ed8f28d4e80e8f01801a4a47ff893a Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 16:30:50 -0600 Subject: [PATCH 03/60] lyraphase_workstation::bashrc: Add ChefSpec test for homebrew_github_api_token_comment --- spec/unit/recipes/bashrc_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/unit/recipes/bashrc_spec.rb b/spec/unit/recipes/bashrc_spec.rb index 2ec40ac..b323226 100644 --- a/spec/unit/recipes/bashrc_spec.rb +++ b/spec/unit/recipes/bashrc_spec.rb @@ -27,11 +27,13 @@ # Override ChefSpec attributes from spec_shared_contexts let(:chefspec_options) { require 'securerandom' + require 'date' { default_attributes: {}, normal_attributes: { 'lyraphase_workstation': { 'bashrc': { 'homebrew_github_api_token': "gh_#{SecureRandom.hex(20)}", + 'homebrew_github_api_token_comment': "rotgut butanol - (#{DateTime.now.strftime('%Y-%m-%d %H:%M:%S %z')}) - lyra.37om.com - public_repo RO", 'user_fullname': 'Barney Rubble', 'user_email': 'barney.rubble@lyraphase.com', 'user_gpg_keyid': "0x#{SecureRandom.hex(8)}", @@ -53,6 +55,7 @@ ) [ "export HOMEBREW_GITHUB_API_TOKEN='#{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token']}'", + "export HOMEBREW_GITHUB_API_TOKEN='.*?' # #{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token_comment']}", "export DEBFULLNAME='#{chef_run.node['lyraphase_workstation']['bashrc']['user_fullname']}'", "export DEBEMAIL='#{chef_run.node['lyraphase_workstation']['bashrc']['user_email']}'", "export DEBSIGN_KEYID='#{chef_run.node['lyraphase_workstation']['bashrc']['user_gpg_keyid']}'", @@ -92,6 +95,7 @@ # - homebrew_github_api_token # - homebrew_no_cleanup_formulae [ "export HOMEBREW_GITHUB_API_TOKEN='#{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token']}'", + "export HOMEBREW_GITHUB_API_TOKEN='.*?' # #{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token_comment']}", "export HOMEBREW_NO_CLEANUP_FORMULAE=.*" ].each do |expected_regex| # Note: Negated with_content requires passing a Proc / Block! From 646b6455c4735fe56fa9ee62bd48b3b713b7a957 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 16:58:56 -0600 Subject: [PATCH 04/60] lyraphase_workstation::bashrc: Fix Regexp <=> string incompatible chars in token comment --- spec/unit/recipes/bashrc_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/recipes/bashrc_spec.rb b/spec/unit/recipes/bashrc_spec.rb index b323226..fc1fd3a 100644 --- a/spec/unit/recipes/bashrc_spec.rb +++ b/spec/unit/recipes/bashrc_spec.rb @@ -33,7 +33,7 @@ normal_attributes: { 'lyraphase_workstation': { 'bashrc': { 'homebrew_github_api_token': "gh_#{SecureRandom.hex(20)}", - 'homebrew_github_api_token_comment': "rotgut butanol - (#{DateTime.now.strftime('%Y-%m-%d %H:%M:%S %z')}) - lyra.37om.com - public_repo RO", + 'homebrew_github_api_token_comment': "rotgut butanol - #{DateTime.now.strftime('%Y-%m-%d %H:%M:%S %z')} - lyra.37om.com - public_repo RO", 'user_fullname': 'Barney Rubble', 'user_email': 'barney.rubble@lyraphase.com', 'user_gpg_keyid': "0x#{SecureRandom.hex(8)}", From 8e01b6e507e38e013e75e59e73f05bcf0271d3b4 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 17:01:00 -0600 Subject: [PATCH 05/60] lyraphase_workstation::bashrc: Implement homebrew_github_api_token{,_comment} and homebrew_no_cleanup_formulae --- recipes/bashrc.rb | 34 ++++++++++++++++++++++++++-------- templates/default/bashrc.erb | 8 +++++++- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/recipes/bashrc.rb b/recipes/bashrc.rb index 7d9bf0c..75e14df 100644 --- a/recipes/bashrc.rb +++ b/recipes/bashrc.rb @@ -24,14 +24,30 @@ bashrc_path = Pathname.new(File.join(node['lyraphase_workstation']['home'], '.bashrc')) bash_logout_path = Pathname.new(File.join(node['lyraphase_workstation']['home'], '.bash_logout')) -homebrew_github_api_token = begin - data_bag_item('lyraphase_workstation', 'bashrc')['homebrew_github_api_token'] - rescue - nil - end +# Gather Homebrew GitHub token from encrypted data bag +homebrew_github_api_token_data = begin + data_bag_item('lyraphase_workstation', 'bashrc') + rescue + nil + end -if homebrew_github_api_token.nil? && !node['lyraphase_workstation']['bashrc']['homebrew_github_api_token'].nil? && !node['lyraphase_workstation']['bashrc']['homebrew_github_api_token'].nil? - homebrew_github_api_token = node['lyraphase_workstation']['bashrc']['homebrew_github_api_token'] +homebrew_github_api_token_hash = Hash.new() +['homebrew_github_api_token', 'homebrew_github_api_token_comment'].each do |data_bag_key| + if !homebrew_github_api_token_data.nil? && homebrew_github_api_token_data.has_key?(data_bag_key) + homebrew_github_api_token_hash[data_bag_key] = begin + homebrew_github_api_token_data[data_bag_key] + rescue + nil + end + end + + if homebrew_github_api_token_hash[data_bag_key].nil? && !node['lyraphase_workstation']['bashrc'][data_bag_key].nil? + homebrew_github_api_token_hash[data_bag_key] = node['lyraphase_workstation']['bashrc'][data_bag_key] + end +end + +if !node['lyraphase_workstation']['bashrc']['homebrew_no_cleanup_formulae'].nil? + homebrew_no_cleanup_formulae = node['lyraphase_workstation']['bashrc']['homebrew_no_cleanup_formulae'] end template bashrc_path do @@ -42,7 +58,9 @@ user_fullname: node['lyraphase_workstation']['bashrc']['user_fullname'], user_email: node['lyraphase_workstation']['bashrc']['user_email'], user_gpg_keyid: node['lyraphase_workstation']['bashrc']['user_gpg_keyid'], - homebrew_github_api_token: homebrew_github_api_token + homebrew_github_api_token: homebrew_github_api_token_hash['homebrew_github_api_token'], + homebrew_github_api_token_comment: homebrew_github_api_token_hash['homebrew_github_api_token_comment'], + homebrew_no_cleanup_formulae: homebrew_no_cleanup_formulae ) end diff --git a/templates/default/bashrc.erb b/templates/default/bashrc.erb index d4b3fb6..c351583 100644 --- a/templates/default/bashrc.erb +++ b/templates/default/bashrc.erb @@ -176,8 +176,14 @@ then # Use General Colorizer source "`brew --prefix`/etc/grc.sh" +<% if @homebrew_github_api_token %> # Set homebrew OAuth token - export HOMEBREW_GITHUB_API_TOKEN='<%= @homebrew_github_api_token -%>' # lyra.37om.com + export HOMEBREW_GITHUB_API_TOKEN='<%= @homebrew_github_api_token -%>' # <%= @homebrew_github_api_token_comment %> +<% end %> +<% if @homebrew_no_cleanup_formulae %> + # Keep old versions for specific formulae + export HOMEBREW_NO_CLEANUP_FORMULAE=<%= @homebrew_no_cleanup_formulae.join(',') %> +<% end %> # Alias defunkt/hub as git eval "$(hub alias -s)" From b5a8be3e137ff50d39b21a8eb9f444f2f59fc5db Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 17:02:28 -0600 Subject: [PATCH 06/60] .vscode: Add Extension recommendations & default Code Workspace files --- .vscode/extensions.json | 5 +++++ .vscode/lyraphase_workstation.code-workspace | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 .vscode/extensions.json create mode 100644 .vscode/lyraphase_workstation.code-workspace diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..7f1fc95 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "chef-software.Chef" + ] +} \ No newline at end of file diff --git a/.vscode/lyraphase_workstation.code-workspace b/.vscode/lyraphase_workstation.code-workspace new file mode 100644 index 0000000..bab1b7f --- /dev/null +++ b/.vscode/lyraphase_workstation.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": ".." + } + ], + "settings": {} +} \ No newline at end of file From 919c05e4272180970fd31a232fb7f11a3dc4ab3d Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 20:28:09 -0600 Subject: [PATCH 07/60] lyraphase_workstation::bashrc: Add shared_examples & shared_context for testing Chef Log levels & functions --- recipes/bashrc.rb | 15 ++- spec/spec_helper.rb | 7 ++ spec/spec_shared_contexts.rb | 202 +++++++++++++++++++++++++++++++ spec/unit/recipes/bashrc_spec.rb | 73 +++++++++++ 4 files changed, 296 insertions(+), 1 deletion(-) diff --git a/recipes/bashrc.rb b/recipes/bashrc.rb index 75e14df..e6bc616 100644 --- a/recipes/bashrc.rb +++ b/recipes/bashrc.rb @@ -31,9 +31,11 @@ nil end +puts("homebrew_github_api_token_data = #{homebrew_github_api_token_data}") homebrew_github_api_token_hash = Hash.new() ['homebrew_github_api_token', 'homebrew_github_api_token_comment'].each do |data_bag_key| - if !homebrew_github_api_token_data.nil? && homebrew_github_api_token_data.has_key?(data_bag_key) + if !homebrew_github_api_token_data.nil? && homebrew_github_api_token_data.has_key?(node['name']) && homebrew_github_api_token_data.has_key?(data_bag_key) + Chef::Log.info("Loading Homebrew GitHub API token for Node Name: #{node['name']}") homebrew_github_api_token_hash[data_bag_key] = begin homebrew_github_api_token_data[data_bag_key] rescue @@ -44,8 +46,19 @@ if homebrew_github_api_token_hash[data_bag_key].nil? && !node['lyraphase_workstation']['bashrc'][data_bag_key].nil? homebrew_github_api_token_hash[data_bag_key] = node['lyraphase_workstation']['bashrc'][data_bag_key] end + + if homebrew_github_api_token_hash[data_bag_key].nil? && !homebrew_github_api_token_data.nil? + Chef::Log.warn("Could not find Homebrew GitHub API token attribute #{data_bag_key} in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}") + Chef::Log.warn("Expected Data Bag Item Schema: {\"id\": \"bashrc\", \"#{node['name']}\": {\"homebrew_github_api_token\": \"gh_f00dcafevagrant\", \"homebrew_github_api_token_comment\": \"some optional comment\"}}") + end end +Chef::Log.info('INFO TEST') +Chef::Log.trace('TRACE TEST') +Chef::Log.fatal('FATAL TEST') +Chef::Log.error('ERROR TEST') +Chef::Log.debug('DEBUG TEST') + if !node['lyraphase_workstation']['bashrc']['homebrew_no_cleanup_formulae'].nil? homebrew_no_cleanup_formulae = node['lyraphase_workstation']['bashrc']['homebrew_no_cleanup_formulae'] end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 43aefe2..f68040a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -33,9 +33,16 @@ config.alias_example_group_to :describe_recipe, type: :recipe config.alias_example_group_to :describe_helpers, type: :helpers config.alias_example_group_to :describe_resource, type: :resource + config.alias_example_group_to :describe_recipe_with_expected_logs, type: :recipe_with_expected_logs + config.alias_it_behaves_like_to :it_outputs, 'outputs' + config.alias_example_to :it_logs config.before { stub_const('ENV', ENV.to_hash.merge('SUDO_USER' => 'brubble')) } config.filter_run_when_matching :focus + + config.before :each do |x| + puts("RUNNING EXAMPLE: #{x.metadata[:example_group][:full_description]}") + end end at_exit { ChefSpec::Coverage.report! } diff --git a/spec/spec_shared_contexts.rb b/spec/spec_shared_contexts.rb index 2bf9c88..b8cb4b0 100644 --- a/spec/spec_shared_contexts.rb +++ b/spec/spec_shared_contexts.rb @@ -180,6 +180,208 @@ def recipe_name end end +# Shared examples for checking for Chef::Log output +shared_examples 'Chef TRACE Logs' do + it_logs 'with messages' do + skip('No chef_log_trace_msgs expected') if chef_log_trace_msgs.empty? + chef_log_trace_msgs.each do |trace_msg| + expect(Chef::Log).to receive(:trace).with(trace_msg) + end + # remember that you actually have to call `chef_run` after setting the expect + bare_chef_run.converge(described_recipe) + end +end + +shared_examples 'Chef INFO Logs' do + it_logs 'with messages' do + skip('No chef_log_info_msgs expected') if chef_log_info_msgs.empty? + chef_log_info_msgs.each do |info_msg| + expect(Chef::Log).to receive(:info).with(info_msg) + end + # remember that you actually have to call `chef_run` after setting the expect + bare_chef_run.converge(described_recipe) + end +end + +shared_examples 'Chef WARN Logs' do + it_logs 'with messages' do + skip('No chef_log_warnings expected') if chef_log_warnings.empty? + puts("DESCRIBED RECIPE: #{described_recipe}") + chef_log_warnings.each do |warn_msg| + expect(Chef::Log).to receive(:warn).with(warn_msg) + end + # remember that you actually have to call `chef_run` after setting the expect + bare_chef_run.converge(described_recipe) + end +end + +shared_examples 'Chef FATAL Logs' do + it_logs 'with messages' do + skip('No chef_log_fatal_msgs expected') if chef_log_fatal_msgs.empty? + chef_log_fatal_msgs.each do |fatal_msg| + expect(Chef::Log).to receive(:fatal).with(fatal_msg) + end + # remember that you actually have to call `chef_run` after setting the expect + bare_chef_run.converge(described_recipe) + end +end + +shared_examples 'Chef ERROR Logs' do + it_logs 'with messages' do + skip('No chef_log_error_msgs expected') if chef_log_error_msgs.empty? + chef_log_error_msgs.each do |error_msg| + expect(Chef::Log).to receive(:error).with(error_msg) + end + # remember that you actually have to call `chef_run` after setting the expect + bare_chef_run.converge(described_recipe) + end +end + +shared_examples 'Chef DEBUG Logs' do + it_logs 'with messages' do + skip('No chef_log_debug_msgs expected') if chef_log_debug_msgs.empty? + chef_log_debug_msgs.each do |debug_msg| + expect(Chef::Log).to receive(:debug).with(debug_msg) + end + # remember that you actually have to call `chef_run` after setting the expect + bare_chef_run.converge(described_recipe) + end +end + +shared_context 'when expected to output Chef Log messages', type: :recipe_with_expected_logs do + # Individual spec Example Groups can override this to inject node attributes + let(:chefspec_options) do + { + default_attributes: {}, + normal_attributes: {}, + automatic_attributes: {}, + } + end + + let(:bare_chef_run) do + ## Note: We do NOT run chef_run.converge here so Chef::Log shared_examples will work + ## bare_chef_run.converge must be called inside the example block to output anything + puts("INSIDE chef_run #{described_recipe}") + klass = ChefSpec.constants.include?(:SoloRunner) ? ChefSpec::SoloRunner : ChefSpec::ServerRunner + klass.new(chefspec_options) do |node| + node.normal.merge!(node_attributes) + end + end + + let(:chef_run) do + ## Note: We run chef_run.converge here to raise exceptions for RSpec to check + puts("INSIDE chef_run #{described_recipe}") + klass = ChefSpec.constants.include?(:SoloRunner) ? ChefSpec::SoloRunner : ChefSpec::ServerRunner + klass.new(chefspec_options) do |node| + node.normal.merge!(node_attributes) + end.converge(described_recipe) + end + + let(:node) { chef_run.node } + + def lyraphase_workstation_user + create_singleton_struct 'EtcPasswd', [ :name, :passwd, :uid, :gid, :gecos, :dir, :shell, :change, :uclass, :expire ] + Struct::EtcPasswd.new('brubble', '********', 501, 20, 'Barney Rubble', '/Users/brubble', '/bin/bash', 0, '', 0) + end + + # Global ChefSpec attributes for all Example Groups + def node_attributes + attributes = { + 'platform': 'mac_os_x', + 'version': '10.15', + 'etc': { + 'passwd': { + 'brubble': lyraphase_workstation_user, + }, + }, + 'sprout': { + 'home': '/Users/brubble', + 'user': 'brubble', + }, + 'lyraphase_workstation': { + 'user': 'brubble', + 'home': '/Users/brubble', + }, + } + stringify_keys(attributes) + end + + def cookbook_recipe_names + described_recipe.split('::', 2) + end + + def cookbook_name + cookbook_recipe_names.first + end + + def recipe_name + cookbook_recipe_names.last + end + + def default_cookbook_attribute(attribute_name) + node[cookbook_name][attribute_name] + end + + # Override this inside the context block, to expect trace messages + let(:chef_log_trace_msgs) do + [] + end + + # Override this inside the context block, to expect info messages + let(:chef_log_info_msgs) do + [] + end + + # Override this inside the context block, to expect warnings + let(:chef_log_warnings) do + [] + end + + # Override this inside the context block, to expect fatal messages + let(:chef_log_fatal_msgs) do + [] + end + + # Override this inside the context block, to expect error messages + let(:chef_log_error_msgs) do + [] + end + + # Override this inside the context block, to expect debug messages + let(:chef_log_debug_msgs) do + [] + end + + before(:each) do + # Stub log levels: debug, error, fatal, info, trace + chef_log_trace_msgs.each do |trace_msg| + allow(Chef::Log).to receive(:trace).with(trace_msg).and_return(nil) + allow(Chef::Log).to receive(:trace).and_return(nil) + end + chef_log_info_msgs.each do |info_msg| + allow(Chef::Log).to receive(:info).with(info_msg).and_return(nil) + allow(Chef::Log).to receive(:info).and_return(nil) + end + chef_log_warnings.each do |warning_msg| + allow(Chef::Log).to receive(:warn).with(warning_msg).and_return(nil) + allow(Chef::Log).to receive(:warn).and_return(nil) + end + chef_log_fatal_msgs.each do |fatal_msg| + allow(Chef::Log).to receive(:fatal).with(fatal_msg).and_return(nil) + allow(Chef::Log).to receive(:fatal).and_return(nil) + end + chef_log_error_msgs.each do |error_msg| + allow(Chef::Log).to receive(:error).with(error_msg).and_return(nil) + allow(Chef::Log).to receive(:error).and_return(nil) + end + chef_log_debug_msgs.each do |debug_msg| + allow(Chef::Log).to receive(:debug).with(debug_msg).and_return(nil) + allow(Chef::Log).to receive(:debug).and_return(nil) + end + end + +end + shared_context 'Chef 14.x no EtcPasswd' do let(:chef_run) do ## Note: We run chef_run.converge here to raise exceptions for RSpec to check diff --git a/spec/unit/recipes/bashrc_spec.rb b/spec/unit/recipes/bashrc_spec.rb index fc1fd3a..720d852 100644 --- a/spec/unit/recipes/bashrc_spec.rb +++ b/spec/unit/recipes/bashrc_spec.rb @@ -114,3 +114,76 @@ end end end + +describe_recipe_with_expected_logs 'lyraphase_workstation::bashrc' do + # Use ChefSpec attributes from spec_shared_contexts + # Override ChefSpec attributes from spec_shared_contexts + let(:chefspec_options) { + require 'securerandom' + require 'date' + { + default_attributes: {}, + normal_attributes: { 'lyraphase_workstation': { + 'bashrc': { + 'homebrew_github_api_token': nil, + 'homebrew_github_api_token_comment': nil, + 'user_fullname': 'Barney Rubble', + 'user_email': 'barney.rubble@lyraphase.com', + 'user_gpg_keyid': "0x#{SecureRandom.hex(8)}" + } + } + }, + automatic_attributes: {} + } + } + let(:invalid_data_bag_item) { + { id: 'bashrc', comment: 'wrong schema', + homebrew_github_api_token: "gh_#{SecureRandom.hex(20)}", + homebrew_github_api_token_comment: 'This should be under node name hash key' + } + } + # Expect Chef::Log.warn messages + let(:chef_log_warnings) { + [ + "Could not find Homebrew GitHub API token attribute homebrew_github_api_token in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}", + "Could not find Homebrew GitHub API token attribute homebrew_github_api_token_comment in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}", + "Expected Data Bag Item Schema: {\"id\": \"bashrc\", \"#{node['name']}\": {\"homebrew_github_api_token\": \"gh_f00dcafevagrant\", \"homebrew_github_api_token_comment\": \"some optional comment\"}}" + ] + } + + let(:chef_log_trace_msgs) { + ['TRACE TEST'] + } + + let(:chef_log_info_msgs) { + ['INFO TEST'] + } + + let(:chef_log_fatal_msgs) do + ['FATAL TEST'] + end + + # Override this inside the context block, to expect error messages + let(:chef_log_error_msgs) do + ['ERROR TEST'] + end + + # Override this inside the context block, to expect debug messages + let(:chef_log_debug_msgs) do + ['DEBUG TEST'] + end + + before(:each) do + stub_data_bag_item('lyraphase_workstation', 'bashrc').and_return(invalid_data_bag_item) + end + + it_outputs 'Chef WARN Logs' + it_outputs 'Chef TRACE Logs' + it_outputs 'Chef INFO Logs' + it_outputs 'Chef FATAL Logs' + it_outputs 'Chef ERROR Logs' + it_outputs 'Chef DEBUG Logs' + it 'does not raise error' do + expect { chef_run }.to_not raise_error + end +end \ No newline at end of file From 3c759cd9aaf312767d83d104bb3ecc60132aa9e0 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 21:11:57 -0600 Subject: [PATCH 08/60] lyraphase_workstation::bashrc: Simplify/Refactor "outputs Chef * Logs" & remove debug messages --- recipes/bashrc.rb | 7 ------ spec/spec_helper.rb | 4 ---- spec/spec_shared_contexts.rb | 41 +++++++++++++++++++++----------- spec/unit/recipes/bashrc_spec.rb | 35 +++------------------------ 4 files changed, 30 insertions(+), 57 deletions(-) diff --git a/recipes/bashrc.rb b/recipes/bashrc.rb index e6bc616..da84321 100644 --- a/recipes/bashrc.rb +++ b/recipes/bashrc.rb @@ -31,7 +31,6 @@ nil end -puts("homebrew_github_api_token_data = #{homebrew_github_api_token_data}") homebrew_github_api_token_hash = Hash.new() ['homebrew_github_api_token', 'homebrew_github_api_token_comment'].each do |data_bag_key| if !homebrew_github_api_token_data.nil? && homebrew_github_api_token_data.has_key?(node['name']) && homebrew_github_api_token_data.has_key?(data_bag_key) @@ -53,12 +52,6 @@ end end -Chef::Log.info('INFO TEST') -Chef::Log.trace('TRACE TEST') -Chef::Log.fatal('FATAL TEST') -Chef::Log.error('ERROR TEST') -Chef::Log.debug('DEBUG TEST') - if !node['lyraphase_workstation']['bashrc']['homebrew_no_cleanup_formulae'].nil? homebrew_no_cleanup_formulae = node['lyraphase_workstation']['bashrc']['homebrew_no_cleanup_formulae'] end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f68040a..cfc5dc3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -39,10 +39,6 @@ config.before { stub_const('ENV', ENV.to_hash.merge('SUDO_USER' => 'brubble')) } config.filter_run_when_matching :focus - - config.before :each do |x| - puts("RUNNING EXAMPLE: #{x.metadata[:example_group][:full_description]}") - end end at_exit { ChefSpec::Coverage.report! } diff --git a/spec/spec_shared_contexts.rb b/spec/spec_shared_contexts.rb index b8cb4b0..5d404d3 100644 --- a/spec/spec_shared_contexts.rb +++ b/spec/spec_shared_contexts.rb @@ -182,7 +182,7 @@ def recipe_name # Shared examples for checking for Chef::Log output shared_examples 'Chef TRACE Logs' do - it_logs 'with messages' do + it_logs 'with expected messages' do skip('No chef_log_trace_msgs expected') if chef_log_trace_msgs.empty? chef_log_trace_msgs.each do |trace_msg| expect(Chef::Log).to receive(:trace).with(trace_msg) @@ -193,7 +193,7 @@ def recipe_name end shared_examples 'Chef INFO Logs' do - it_logs 'with messages' do + it_logs 'with expected messages' do skip('No chef_log_info_msgs expected') if chef_log_info_msgs.empty? chef_log_info_msgs.each do |info_msg| expect(Chef::Log).to receive(:info).with(info_msg) @@ -204,10 +204,9 @@ def recipe_name end shared_examples 'Chef WARN Logs' do - it_logs 'with messages' do - skip('No chef_log_warnings expected') if chef_log_warnings.empty? - puts("DESCRIBED RECIPE: #{described_recipe}") - chef_log_warnings.each do |warn_msg| + it_logs 'with expected messages' do + skip('No chef_log_warn_msgs expected') if chef_log_warn_msgs.empty? + chef_log_warn_msgs.each do |warn_msg| expect(Chef::Log).to receive(:warn).with(warn_msg) end # remember that you actually have to call `chef_run` after setting the expect @@ -216,7 +215,7 @@ def recipe_name end shared_examples 'Chef FATAL Logs' do - it_logs 'with messages' do + it_logs 'with expected messages' do skip('No chef_log_fatal_msgs expected') if chef_log_fatal_msgs.empty? chef_log_fatal_msgs.each do |fatal_msg| expect(Chef::Log).to receive(:fatal).with(fatal_msg) @@ -227,7 +226,7 @@ def recipe_name end shared_examples 'Chef ERROR Logs' do - it_logs 'with messages' do + it_logs 'with expected messages' do skip('No chef_log_error_msgs expected') if chef_log_error_msgs.empty? chef_log_error_msgs.each do |error_msg| expect(Chef::Log).to receive(:error).with(error_msg) @@ -238,7 +237,7 @@ def recipe_name end shared_examples 'Chef DEBUG Logs' do - it_logs 'with messages' do + it_logs 'with expected messages' do skip('No chef_log_debug_msgs expected') if chef_log_debug_msgs.empty? chef_log_debug_msgs.each do |debug_msg| expect(Chef::Log).to receive(:debug).with(debug_msg) @@ -261,7 +260,6 @@ def recipe_name let(:bare_chef_run) do ## Note: We do NOT run chef_run.converge here so Chef::Log shared_examples will work ## bare_chef_run.converge must be called inside the example block to output anything - puts("INSIDE chef_run #{described_recipe}") klass = ChefSpec.constants.include?(:SoloRunner) ? ChefSpec::SoloRunner : ChefSpec::ServerRunner klass.new(chefspec_options) do |node| node.normal.merge!(node_attributes) @@ -270,7 +268,6 @@ def recipe_name let(:chef_run) do ## Note: We run chef_run.converge here to raise exceptions for RSpec to check - puts("INSIDE chef_run #{described_recipe}") klass = ChefSpec.constants.include?(:SoloRunner) ? ChefSpec::SoloRunner : ChefSpec::ServerRunner klass.new(chefspec_options) do |node| node.normal.merge!(node_attributes) @@ -322,6 +319,8 @@ def default_cookbook_attribute(attribute_name) node[cookbook_name][attribute_name] end + let(:chef_log) { class_double(Chef::Log) } + # Override this inside the context block, to expect trace messages let(:chef_log_trace_msgs) do [] @@ -333,7 +332,7 @@ def default_cookbook_attribute(attribute_name) end # Override this inside the context block, to expect warnings - let(:chef_log_warnings) do + let(:chef_log_warn_msgs) do [] end @@ -353,30 +352,44 @@ def default_cookbook_attribute(attribute_name) end before(:each) do + allow(chef_log).to receive(:new).and_return(chef_log) + allow(Chef::Log).to receive(:new).and_return(chef_log) # Stub log levels: debug, error, fatal, info, trace chef_log_trace_msgs.each do |trace_msg| allow(Chef::Log).to receive(:trace).with(trace_msg).and_return(nil) allow(Chef::Log).to receive(:trace).and_return(nil) + allow(chef_log).to receive(:trace).and_return(nil) end chef_log_info_msgs.each do |info_msg| allow(Chef::Log).to receive(:info).with(info_msg).and_return(nil) allow(Chef::Log).to receive(:info).and_return(nil) end - chef_log_warnings.each do |warning_msg| - allow(Chef::Log).to receive(:warn).with(warning_msg).and_return(nil) + chef_log_warn_msgs.each do |warn_msg| + allow(Chef::Log).to receive(:warn).with(warn_msg).and_return(nil) + allow(Chef::Log).to receive(:warn).with(anything).and_return(nil) allow(Chef::Log).to receive(:warn).and_return(nil) + allow(chef_log).to receive(:warn).and_return(nil) + allow(chef_log).to receive(:warn).with(anything).and_return(nil) end chef_log_fatal_msgs.each do |fatal_msg| allow(Chef::Log).to receive(:fatal).with(fatal_msg).and_return(nil) + allow(Chef::Log).to receive(:fatal).with(anything).and_return(nil) allow(Chef::Log).to receive(:fatal).and_return(nil) + allow(chef_log).to receive(:fatal).and_return(nil) + allow(chef_log).to receive(:fatal).with(anything).and_return(nil) end chef_log_error_msgs.each do |error_msg| allow(Chef::Log).to receive(:error).with(error_msg).and_return(nil) + allow(Chef::Log).to receive(:error).with(anything).and_return(nil) allow(Chef::Log).to receive(:error).and_return(nil) + allow(chef_log).to receive(:error).and_return(nil) + allow(chef_log).to receive(:error).with(anything).and_return(nil) end chef_log_debug_msgs.each do |debug_msg| allow(Chef::Log).to receive(:debug).with(debug_msg).and_return(nil) allow(Chef::Log).to receive(:debug).and_return(nil) + allow(chef_log).to receive(:debug).and_return(nil) + allow(chef_log).to receive(:debug).with(anything).and_return(nil) end end diff --git a/spec/unit/recipes/bashrc_spec.rb b/spec/unit/recipes/bashrc_spec.rb index 720d852..8514562 100644 --- a/spec/unit/recipes/bashrc_spec.rb +++ b/spec/unit/recipes/bashrc_spec.rb @@ -126,10 +126,7 @@ normal_attributes: { 'lyraphase_workstation': { 'bashrc': { 'homebrew_github_api_token': nil, - 'homebrew_github_api_token_comment': nil, - 'user_fullname': 'Barney Rubble', - 'user_email': 'barney.rubble@lyraphase.com', - 'user_gpg_keyid': "0x#{SecureRandom.hex(8)}" + 'homebrew_github_api_token_comment': nil } } }, @@ -143,7 +140,7 @@ } } # Expect Chef::Log.warn messages - let(:chef_log_warnings) { + let(:chef_log_warn_msgs) { [ "Could not find Homebrew GitHub API token attribute homebrew_github_api_token in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}", "Could not find Homebrew GitHub API token attribute homebrew_github_api_token_comment in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}", @@ -151,38 +148,12 @@ ] } - let(:chef_log_trace_msgs) { - ['TRACE TEST'] - } - - let(:chef_log_info_msgs) { - ['INFO TEST'] - } - - let(:chef_log_fatal_msgs) do - ['FATAL TEST'] - end - - # Override this inside the context block, to expect error messages - let(:chef_log_error_msgs) do - ['ERROR TEST'] - end - - # Override this inside the context block, to expect debug messages - let(:chef_log_debug_msgs) do - ['DEBUG TEST'] - end - before(:each) do stub_data_bag_item('lyraphase_workstation', 'bashrc').and_return(invalid_data_bag_item) end it_outputs 'Chef WARN Logs' - it_outputs 'Chef TRACE Logs' - it_outputs 'Chef INFO Logs' - it_outputs 'Chef FATAL Logs' - it_outputs 'Chef ERROR Logs' - it_outputs 'Chef DEBUG Logs' + it 'does not raise error' do expect { chef_run }.to_not raise_error end From beb65c5a4fb4ced86617f8fbd6a92ff42f3eaa0b Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 22:58:04 -0600 Subject: [PATCH 09/60] lyraphase_workstation::bashrc: Refactor & D.R.Y. ChefSpec tests --- spec/spec_shared_contexts.rb | 7 ++ spec/unit/recipes/bashrc_spec.rb | 168 ++++++++++++++++++++----------- 2 files changed, 115 insertions(+), 60 deletions(-) diff --git a/spec/spec_shared_contexts.rb b/spec/spec_shared_contexts.rb index 5d404d3..8e5c021 100644 --- a/spec/spec_shared_contexts.rb +++ b/spec/spec_shared_contexts.rb @@ -351,7 +351,14 @@ def default_cookbook_attribute(attribute_name) [] end + # Override this method to add before(:each) hooks at this shared_context level + def before_each_shared_example + end + before(:each) do + # Provide method hook for adding top-level shared_context before steps (e.g. stubs) + before_each_shared_example + allow(chef_log).to receive(:new).and_return(chef_log) allow(Chef::Log).to receive(:new).and_return(chef_log) # Stub log levels: debug, error, fatal, info, trace diff --git a/spec/unit/recipes/bashrc_spec.rb b/spec/unit/recipes/bashrc_spec.rb index 8514562..7dcecff 100644 --- a/spec/unit/recipes/bashrc_spec.rb +++ b/spec/unit/recipes/bashrc_spec.rb @@ -22,6 +22,53 @@ require 'spec_helper' +shared_examples 'bash_logout' do + let(:bash_logout_path) { '/Users/brubble/.bash_logout' } + it 'installs custom .bash_logout into user homedir' do + expect(chef_run).to create_template(bash_logout_path).with( + user: 'brubble', + mode: '0644' + ) + end +end + +shared_examples 'it does not raise error' do + it 'does not raise error' do + expect { chef_run }.to_not raise_error + end +end + +shared_examples 'default .bashrc' do + let(:bashrc_path) { '/Users/brubble/.bashrc' } + it 'installs custom .bashrc into user homedir with expected settings' do + expect(chef_run).to create_template(bashrc_path).with( + user: 'brubble', + mode: '0644' + ) + + [ "export DEBFULLNAME='#{chef_run.node['lyraphase_workstation']['bashrc']['user_fullname']}'", + "export DEBEMAIL='#{chef_run.node['lyraphase_workstation']['bashrc']['user_email']}'", + "export DEBSIGN_KEYID='#{chef_run.node['lyraphase_workstation']['bashrc']['user_gpg_keyid']}'" + ].each do |expected_regex| + expect(chef_run).to render_file(bashrc_path).with_content(Regexp.new("^\s*#{expected_regex}\s*(#.*)?$")) + end + + # Default is no / empty attributes: + # - homebrew_github_api_token + # - homebrew_no_cleanup_formulae + [ "export HOMEBREW_GITHUB_API_TOKEN='#{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token']}'", + "export HOMEBREW_GITHUB_API_TOKEN='.*?' # #{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token_comment']}", + "export HOMEBREW_NO_CLEANUP_FORMULAE=.*" + ].each do |expected_regex| + # Note: Negated with_content requires passing a Proc / Block! + # Reference: https://github.com/chefspec/chefspec/issues/865 + expect(chef_run).to(render_file(bashrc_path).with_content do |content| + expect(content).not_to match(Regexp.new("^\s*#{expected_regex}\s*(#.*)?$")) + end) + end + end +end + describe_recipe 'lyraphase_workstation::bashrc' do context 'when given all bashrc attributes' do # Override ChefSpec attributes from spec_shared_contexts @@ -46,7 +93,11 @@ } let(:bashrc_path) { '/Users/brubble/.bashrc' } - let(:bash_logout_path) { '/Users/brubble/.bash_logout' } + + # Normal stub works for describe_recipe shared context b/c it has no before blocks defined + before(:each) do + stub_data_bag_item("lyraphase_workstation", "bashrc").and_return(nil) + end it 'installs custom .bashrc into user homedir with given settings' do expect(chef_run).to create_template(bashrc_path).with( @@ -65,53 +116,18 @@ end end - it 'installs custom .bash_logout into user homedir' do - expect(chef_run).to create_template(bash_logout_path).with( - user: 'brubble', - mode: '0644' - ) - end + include_examples 'bash_logout' end context 'when given no (default) bashrc attributes' do # Use ChefSpec attributes from spec_shared_contexts - let(:bashrc_path) { '/Users/brubble/.bashrc' } - let(:bash_logout_path) { '/Users/brubble/.bash_logout' } - - it 'installs custom .bashrc into user homedir with expected settings' do - expect(chef_run).to create_template(bashrc_path).with( - user: 'brubble', - mode: '0644' - ) - - [ "export DEBFULLNAME='#{chef_run.node['lyraphase_workstation']['bashrc']['user_fullname']}'", - "export DEBEMAIL='#{chef_run.node['lyraphase_workstation']['bashrc']['user_email']}'", - "export DEBSIGN_KEYID='#{chef_run.node['lyraphase_workstation']['bashrc']['user_gpg_keyid']}'" - ].each do |expected_regex| - expect(chef_run).to render_file(bashrc_path).with_content(Regexp.new("^\s*#{expected_regex}\s*(#.*)?$")) - end - # Default is no / empty attributes: - # - homebrew_github_api_token - # - homebrew_no_cleanup_formulae - [ "export HOMEBREW_GITHUB_API_TOKEN='#{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token']}'", - "export HOMEBREW_GITHUB_API_TOKEN='.*?' # #{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token_comment']}", - "export HOMEBREW_NO_CLEANUP_FORMULAE=.*" - ].each do |expected_regex| - # Note: Negated with_content requires passing a Proc / Block! - # Reference: https://github.com/chefspec/chefspec/issues/865 - expect(chef_run).to(render_file(bashrc_path).with_content do |content| - expect(content).not_to match(Regexp.new("^\s*#{expected_regex}\s*(#.*)?$")) - end) - end + before(:each) do + stub_data_bag_item("lyraphase_workstation", "bashrc").and_return(nil) end - it 'installs custom .bash_logout into user homedir' do - expect(chef_run).to create_template(bash_logout_path).with( - user: 'brubble', - mode: '0644' - ) - end + include_examples 'default .bashrc' + include_examples 'bash_logout' end end @@ -133,28 +149,60 @@ automatic_attributes: {} } } - let(:invalid_data_bag_item) { - { id: 'bashrc', comment: 'wrong schema', - homebrew_github_api_token: "gh_#{SecureRandom.hex(20)}", - homebrew_github_api_token_comment: 'This should be under node name hash key' + + context 'when given a valid data_bag_item' do + # Override method to stub at the shared_context level + # Needed here b/c describe_recipe_with_expected_logs defines before(:each) already, + # and we need to hook into it at that top-level context + def before_each_shared_example + valid_data_bag_item = { "id": "bashrc", "fauxhai.local": { "homebrew_github_api_token": "gh_f00dcafefauxhai", "homebrew_github_api_token_comment": "This is a valid data bag item" } } + stub_data_bag_item("lyraphase_workstation", "bashrc").and_return(valid_data_bag_item) + end + + # Expect Chef::Log.info message + let(:chef_log_info_msgs) { + ["Loading Homebrew GitHub API token for Node Name: #{node['name']}"] } - } - # Expect Chef::Log.warn messages - let(:chef_log_warn_msgs) { - [ - "Could not find Homebrew GitHub API token attribute homebrew_github_api_token in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}", - "Could not find Homebrew GitHub API token attribute homebrew_github_api_token_comment in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}", - "Expected Data Bag Item Schema: {\"id\": \"bashrc\", \"#{node['name']}\": {\"homebrew_github_api_token\": \"gh_f00dcafevagrant\", \"homebrew_github_api_token_comment\": \"some optional comment\"}}" - ] - } + let(:bashrc_path) { '/Users/brubble/.bashrc' } - before(:each) do - stub_data_bag_item('lyraphase_workstation', 'bashrc').and_return(invalid_data_bag_item) + it_outputs 'Chef INFO Logs' + + it 'installs custom .bashrc into user homedir with given settings' do + expect(chef_run).to create_template(bashrc_path).with( + user: 'brubble', + mode: '0644' + ) + + [ "export HOMEBREW_GITHUB_API_TOKEN='gh_f00dcafefauxhai'", + "export HOMEBREW_GITHUB_API_TOKEN='.*?' # This is a valid data bag item" + ].each do |expected_regex| + expect(chef_run).to render_file(bashrc_path).with_content(Regexp.new("^\s*#{expected_regex}\s*(#.*)?$")) + end + end + + include_examples 'it does not raise error' + include_examples 'bash_logout' end - it_outputs 'Chef WARN Logs' + context 'when given invalid data_bag_item Schema' do + def before_each_shared_example + invalid_data_bag_item = { id: 'bashrc', comment: 'wrong schema', + homebrew_github_api_token: "gh_#{SecureRandom.hex(20)}", + homebrew_github_api_token_comment: 'This should be under node name hash key' + } + stub_data_bag_item('lyraphase_workstation', 'bashrc').and_return(invalid_data_bag_item) + end + # Expect Chef::Log.warn messages + let(:chef_log_warn_msgs) { + [ + "Could not find Homebrew GitHub API token attribute homebrew_github_api_token in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}", + "Could not find Homebrew GitHub API token attribute homebrew_github_api_token_comment in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}", + "Expected Data Bag Item Schema: {\"id\": \"bashrc\", \"#{node['name']}\": {\"homebrew_github_api_token\": \"gh_f00dcafevagrant\", \"homebrew_github_api_token_comment\": \"some optional comment\"}}" + ] + } - it 'does not raise error' do - expect { chef_run }.to_not raise_error + it_outputs 'Chef WARN Logs' + include_examples 'it does not raise error' + include_examples 'default .bashrc' end -end \ No newline at end of file +end From 89b93112f416cecf71b3032438831ffc9f8485c3 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 23:02:53 -0600 Subject: [PATCH 10/60] lyraphase_workstation::bashrc: Change to use per-node Encrypted Data Bag item Schema (GH per-node PATs) --- recipes/bashrc.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/recipes/bashrc.rb b/recipes/bashrc.rb index da84321..35c6ee6 100644 --- a/recipes/bashrc.rb +++ b/recipes/bashrc.rb @@ -27,16 +27,16 @@ # Gather Homebrew GitHub token from encrypted data bag homebrew_github_api_token_data = begin data_bag_item('lyraphase_workstation', 'bashrc') - rescue + rescue => e nil end homebrew_github_api_token_hash = Hash.new() ['homebrew_github_api_token', 'homebrew_github_api_token_comment'].each do |data_bag_key| - if !homebrew_github_api_token_data.nil? && homebrew_github_api_token_data.has_key?(node['name']) && homebrew_github_api_token_data.has_key?(data_bag_key) + if !homebrew_github_api_token_data.nil? && homebrew_github_api_token_data.has_key?(node['name']) && homebrew_github_api_token_data[node['name']].has_key?(data_bag_key) Chef::Log.info("Loading Homebrew GitHub API token for Node Name: #{node['name']}") homebrew_github_api_token_hash[data_bag_key] = begin - homebrew_github_api_token_data[data_bag_key] + homebrew_github_api_token_data[node['name']][data_bag_key] rescue nil end From 70baa9606dadfb23f773fc7f6a5a56e21daff4b3 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 23:12:55 -0600 Subject: [PATCH 11/60] lyraphase_workstation::gpg21: Fix ChefSpec tests on Apple Silicon arm64 with /opt/homebrew path --- spec/unit/recipes/gpg21_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/unit/recipes/gpg21_spec.rb b/spec/unit/recipes/gpg21_spec.rb index 12245ea..ee6d82d 100644 --- a/spec/unit/recipes/gpg21_spec.rb +++ b/spec/unit/recipes/gpg21_spec.rb @@ -34,9 +34,12 @@ node.normal['lyraphase_workstation']['gpg21']['gpgtools_plist_file'] = gpgtools_plist_file_test stub_command("which git").and_return('/usr/local/bin/git') stub_command("/usr/local/bin/brew analytics state").and_return('Analytics is disabled') + stub_command("/opt/homebrew/bin/brew analytics state").and_return('Analytics is disabled') stubs_for_resource("execute[set analytics]") do |resource| allow(resource).to receive_shell_out("/usr/local/bin/brew analytics state", {:user=>"brubble"}) allow(resource).to receive_shell_out("/usr/local/bin/brew analytics state") + allow(resource).to receive_shell_out("/opt/homebrew/bin/brew analytics state", {:user=>"brubble"}) + allow(resource).to receive_shell_out("/opt/homebrew/bin/brew analytics state") end node.normal['lyraphase_workstation']['gpg21']['binary_paths'] = [] @@ -120,9 +123,12 @@ node.normal['lyraphase_workstation']['gpg21']['gpgtools_plist_file'] = gpgtools_plist_file_test stub_command("which git").and_return('/usr/local/bin/git') stub_command("/usr/local/bin/brew analytics state").and_return('Analytics is disabled') + stub_command("/opt/homebrew/bin/brew analytics state").and_return('Analytics is disabled') stubs_for_resource("execute[set analytics]") do |resource| allow(resource).to receive_shell_out("/usr/local/bin/brew analytics state", {:user=>"brubble"}) allow(resource).to receive_shell_out("/usr/local/bin/brew analytics state") + allow(resource).to receive_shell_out("/opt/homebrew/bin/brew analytics state", {:user=>"brubble"}) + allow(resource).to receive_shell_out("/opt/homebrew/bin/brew analytics state") end node.normal['lyraphase_workstation']['gpg21']['binary_paths'] = gpg_binary_paths @@ -176,9 +182,12 @@ node.normal['lyraphase_workstation']['gpg21']['gpgtools_plist_file'] = gpgtools_plist_file_test stub_command("which git").and_return('/usr/local/bin/git') stub_command("/usr/local/bin/brew analytics state").and_return('Analytics is disabled') + stub_command("/opt/homebrew/bin/brew analytics state").and_return('Analytics is disabled') stubs_for_resource("execute[set analytics]") do |resource| allow(resource).to receive_shell_out("/usr/local/bin/brew analytics state", {:user=>"brubble"}) allow(resource).to receive_shell_out("/usr/local/bin/brew analytics state") + allow(resource).to receive_shell_out("/opt/homebrew/bin/brew analytics state", {:user=>"brubble"}) + allow(resource).to receive_shell_out("/opt/homebrew/bin/brew analytics state") end node.normal['lyraphase_workstation']['gpg21']['binary_paths'] = gpg_binary_paths From 801b751b0d27d03a253d743509b63d733a0f1dd5 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 23:26:41 -0600 Subject: [PATCH 12/60] lyraphase_workstation::bashrc: Add .bash_profile template installation --- recipes/bashrc.rb | 8 +++++ spec/unit/recipes/bashrc_spec.rb | 15 +++++++++ templates/default/bash_profile.erb | 50 ++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100755 templates/default/bash_profile.erb diff --git a/recipes/bashrc.rb b/recipes/bashrc.rb index 35c6ee6..5d5982d 100644 --- a/recipes/bashrc.rb +++ b/recipes/bashrc.rb @@ -23,6 +23,7 @@ bashrc_path = Pathname.new(File.join(node['lyraphase_workstation']['home'], '.bashrc')) bash_logout_path = Pathname.new(File.join(node['lyraphase_workstation']['home'], '.bash_logout')) +bash_profile_path = Pathname.new(File.join(node['lyraphase_workstation']['home'], '.bash_profile')) # Gather Homebrew GitHub token from encrypted data bag homebrew_github_api_token_data = begin @@ -76,3 +77,10 @@ mode '0644' # No vars needed for now end + +template bash_profile_path do + source 'bash_profile.erb' + user node['lyraphase_workstation']['user'] + mode '0644' + variables(user_home: node['lyraphase_workstation']['home']) +end \ No newline at end of file diff --git a/spec/unit/recipes/bashrc_spec.rb b/spec/unit/recipes/bashrc_spec.rb index 7dcecff..423585f 100644 --- a/spec/unit/recipes/bashrc_spec.rb +++ b/spec/unit/recipes/bashrc_spec.rb @@ -32,6 +32,19 @@ end end +shared_examples 'bash_profile' do + let(:bash_profile_path) { '/Users/brubble/.bash_profile' } + it 'installs custom .bash_profile into user homedir' do + expect(chef_run).to create_template(bash_profile_path).with( + user: 'brubble', + mode: '0644' + ) + expect(chef_run).to render_file(bash_profile_path).with_content(/^export BASH_IT="\/Users\/brubble\/.bash_it"$/) + expect(chef_run).to render_file(bash_profile_path).with_content(/^source \${HOME}\/.bashrc$/) + expect(chef_run).to render_file(bash_profile_path).with_content(/^source \$BASH_IT\/bash_it.sh$/) + end +end + shared_examples 'it does not raise error' do it 'does not raise error' do expect { chef_run }.to_not raise_error @@ -116,6 +129,7 @@ end end + include_examples 'bash_profile' include_examples 'bash_logout' end @@ -127,6 +141,7 @@ end include_examples 'default .bashrc' + include_examples 'bash_profile' include_examples 'bash_logout' end end diff --git a/templates/default/bash_profile.erb b/templates/default/bash_profile.erb new file mode 100755 index 0000000..d9c951c --- /dev/null +++ b/templates/default/bash_profile.erb @@ -0,0 +1,50 @@ +export PATH="/usr/local/bin:$PATH" + +# Path to the bash it configuration +export BASH_IT="<%= @user_home -%>/.bash_it" + +# Lock and Load a custom theme file +export BASH_IT_THEME="bobby" + +# powerline-plain # nice, but special chars could mess up tty sometimes, no timestamps +# radek # nice for python, but bright & no ruby, no timestamp +# ramses # very nice clean multiline, has python & ruby, no timestamp +# doubletime_multiline # nice clean multiline, has python & ruby + timestamp, but dimmer +# iterate # minimal unless changing directory.. also no timestamps +# luan # Bright nice multiline w/arrows, has ruby + timestamp, no python +# mairan # Nice autumn Halloween theme, has ruby & python + timestamp, and vim shell support! +# mbriggs # Red & Green Xmas theme, has ruby, no python, no timestamp +# metal # Rockin' theme, has python, no ruby, no timestamp +# minimal +# modern # Clean teal theme, has python, no ruby, no timestamp, but vim shell support! +# modern-t # same as modern, but with minimal 't' python TODO integration, breaks bash-it todo plugin +# modern-time # same as modern, no python, no ruby, but with timestamp + vim shell +# n0qorg # super-minimal blue, nothing except git scm +# newin # minimal yellow teal, nothing except git scm + timestamp +# norbu # very minimal green, python + git scm only +# nwinkler # blue green yellow, timestamp +# nwinkler_random_colors # same as above, with randomize_nwinkler function to get random colors + +## This must be done first before we load .bashrc, as PS1 will not be set appropriately otherwise +if [[ $OSTYPE = *darwin* ]] +then + ## Enable iTerm2 Shell Integration + test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash" + export BASH_SILENCE_DEPRECATION_WARNING=1 +fi + +## Always load .bashrc +source ${HOME}/.bashrc + +# Load Bash It +source $BASH_IT/bash_it.sh + +## Currently breaks bash-it: +## Error was: +## bash: trap: __bp_install: invalid signal specification +## /Users/jcuzella/.bash_it/vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh +#test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash" + +export PYENV_ROOT="$HOME/.pyenv" +command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH" +eval "$(pyenv init -)" From eaf2d413fff90ec7a44cc60762a5b803ac13acb7 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 23:57:50 -0600 Subject: [PATCH 13/60] lyraphase_workstation::bashrc: Add InSpec tests for GitHub token comment & .bash_profile --- test/integration/default/bashrc_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/integration/default/bashrc_test.rb b/test/integration/default/bashrc_test.rb index 601fb90..3b58af8 100644 --- a/test/integration/default/bashrc_test.rb +++ b/test/integration/default/bashrc_test.rb @@ -26,6 +26,7 @@ bashrc_path = "/Users/#{test_kitchen_user}/.bashrc" bash_logout_path = "/Users/#{test_kitchen_user}/.bash_logout" homebrew_github_api_token = 'gh_f00dcafevagrant' +homebrew_github_api_token_comment = 'homebrew - 2022-05-23 23:56:02 -0600 - vagrant.example.com - public_repo RO' describe file(bashrc_path) do it { should exist } @@ -34,6 +35,7 @@ its('owner') { should eq test_kitchen_user } its('content') { should match Regexp.new("^\s*export HOMEBREW_GITHUB_API_TOKEN='#{homebrew_github_api_token}'") } + its('content') { should match Regexp.new("^\s*export HOMEBREW_GITHUB_API_TOKEN='.*?' # #{homebrew_github_api_token_comment}") } its('content') { should match /^\s*export DEBFULLNAME='vagrant'$/ } its('content') { should match /^\s*export DEBEMAIL='vagrant@vagrant.com'$/ } its('content') { should match /^\s*export DEBSIGN_KEYID='0xBADC0DE00FEED000'$/ } @@ -46,3 +48,14 @@ its('owner') { should eq test_kitchen_user } its('mode') { should cmp '0644' } end + +describe file(bash_profile_path) do + it { should exist } + it { should be_file } + its('owner') { should eq test_kitchen_user } + its('mode') { should cmp '0644' } + + its('content') { should match /^export BASH_IT="\/Users\/brubble\/.bash_it"$/ } + its('content') { should match /^source \${HOME}\/.bashrc$/ } + its('content') { should match /^source \$BASH_IT\/bash_it.sh$/ } +end \ No newline at end of file From 207d07ad97b4b8f7cfd6adaa36f562387e9478e0 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Tue, 24 May 2022 00:53:36 -0600 Subject: [PATCH 14/60] lyraphase_workstation::bashrc: Update test fixture Encrypted Data Bag & fix InSpec tests --- recipes/bashrc.rb | 5 +++-- .../data_bags/lyraphase_workstation/bashrc.json | 10 +++++----- test/integration/default/bashrc_test.rb | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/recipes/bashrc.rb b/recipes/bashrc.rb index 5d5982d..cfef559 100644 --- a/recipes/bashrc.rb +++ b/recipes/bashrc.rb @@ -28,13 +28,14 @@ # Gather Homebrew GitHub token from encrypted data bag homebrew_github_api_token_data = begin data_bag_item('lyraphase_workstation', 'bashrc') - rescue => e + rescue nil end +loaded_data = !homebrew_github_api_token_data.nil? ? homebrew_github_api_token_data.to_hash : Hash.new() homebrew_github_api_token_hash = Hash.new() ['homebrew_github_api_token', 'homebrew_github_api_token_comment'].each do |data_bag_key| - if !homebrew_github_api_token_data.nil? && homebrew_github_api_token_data.has_key?(node['name']) && homebrew_github_api_token_data[node['name']].has_key?(data_bag_key) + if !homebrew_github_api_token_data.nil? && loaded_data.has_key?(node['name']) && loaded_data[node['name']].has_key?(data_bag_key) Chef::Log.info("Loading Homebrew GitHub API token for Node Name: #{node['name']}") homebrew_github_api_token_hash[data_bag_key] = begin homebrew_github_api_token_data[node['name']][data_bag_key] diff --git a/test/fixtures/data_bags/lyraphase_workstation/bashrc.json b/test/fixtures/data_bags/lyraphase_workstation/bashrc.json index 7eb432e..f0c052b 100644 --- a/test/fixtures/data_bags/lyraphase_workstation/bashrc.json +++ b/test/fixtures/data_bags/lyraphase_workstation/bashrc.json @@ -1,10 +1,10 @@ { "id": "bashrc", - "homebrew_github_api_token": { - "encrypted_data": "G7B4aiL6U+BK5pGe27kA8M/Ndsw5QiS2cSzxypHYTMzvYsxgXw==\n", - "iv": "VocLxRLb9PrqK/nE\n", - "auth_tag": "1A8JfCMmcOwsAiUK34jaUw==\n", + "default-macos-121": { + "encrypted_data": "ipkLDYhRMPGfq7qvx7mKfXn1EYtJvp2spJC2GGdmutCJ1Ks9pBt3ucNwJ3Zs\nK89x+V+RcxGVUFQ/F6m66VUGDDwaNOpUxERMSPf+wTFjcx4wLnyAe6q+Ptzh\n687KelQZvJPjDkK4hcyRr/Th5Zcoj6oo+MRSAd+q5abqRAEYXw+KvwZTSJKH\nom2qlpm4ApFMuixHvxaQFPO+o3C3Tx/ATK0B5Lzgs6cRvGMt27WBy2LAie+A\nrQ==\n", + "iv": "SKMYSZn48/qNrZpC\n", + "auth_tag": "AgJyQRxU11P2dglGaATXww==\n", "version": 3, "cipher": "aes-256-gcm" } -} +} \ No newline at end of file diff --git a/test/integration/default/bashrc_test.rb b/test/integration/default/bashrc_test.rb index 3b58af8..73f5082 100644 --- a/test/integration/default/bashrc_test.rb +++ b/test/integration/default/bashrc_test.rb @@ -25,6 +25,7 @@ test_kitchen_user = input('test_kitchen_user', value: 'kitchen') bashrc_path = "/Users/#{test_kitchen_user}/.bashrc" bash_logout_path = "/Users/#{test_kitchen_user}/.bash_logout" +bash_profile_path = "/Users/#{test_kitchen_user}/.bash_profile" homebrew_github_api_token = 'gh_f00dcafevagrant' homebrew_github_api_token_comment = 'homebrew - 2022-05-23 23:56:02 -0600 - vagrant.example.com - public_repo RO' @@ -55,7 +56,7 @@ its('owner') { should eq test_kitchen_user } its('mode') { should cmp '0644' } - its('content') { should match /^export BASH_IT="\/Users\/brubble\/.bash_it"$/ } + its('content') { should match Regexp.new("^export BASH_IT=\"\/Users\/#{test_kitchen_user}\/.bash_it\"$") } its('content') { should match /^source \${HOME}\/.bashrc$/ } its('content') { should match /^source \$BASH_IT\/bash_it.sh$/ } end \ No newline at end of file From f98472d8c8d93f5f2a4356c3c55ec97ab77d1b9c Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Tue, 24 May 2022 01:39:26 -0600 Subject: [PATCH 15/60] Run end-of-file-fixer on files --- .vscode/extensions.json | 2 +- .vscode/lyraphase_workstation.code-workspace | 2 +- recipes/bashrc.rb | 2 +- test/fixtures/data_bags/lyraphase_workstation/bashrc.json | 2 +- test/integration/default/bashrc_test.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 7f1fc95..c57987b 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -2,4 +2,4 @@ "recommendations": [ "chef-software.Chef" ] -} \ No newline at end of file +} diff --git a/.vscode/lyraphase_workstation.code-workspace b/.vscode/lyraphase_workstation.code-workspace index bab1b7f..64bfb87 100644 --- a/.vscode/lyraphase_workstation.code-workspace +++ b/.vscode/lyraphase_workstation.code-workspace @@ -5,4 +5,4 @@ } ], "settings": {} -} \ No newline at end of file +} diff --git a/recipes/bashrc.rb b/recipes/bashrc.rb index cfef559..f88001c 100644 --- a/recipes/bashrc.rb +++ b/recipes/bashrc.rb @@ -84,4 +84,4 @@ user node['lyraphase_workstation']['user'] mode '0644' variables(user_home: node['lyraphase_workstation']['home']) -end \ No newline at end of file +end diff --git a/test/fixtures/data_bags/lyraphase_workstation/bashrc.json b/test/fixtures/data_bags/lyraphase_workstation/bashrc.json index f0c052b..94d92d7 100644 --- a/test/fixtures/data_bags/lyraphase_workstation/bashrc.json +++ b/test/fixtures/data_bags/lyraphase_workstation/bashrc.json @@ -7,4 +7,4 @@ "version": 3, "cipher": "aes-256-gcm" } -} \ No newline at end of file +} diff --git a/test/integration/default/bashrc_test.rb b/test/integration/default/bashrc_test.rb index 73f5082..a8fac25 100644 --- a/test/integration/default/bashrc_test.rb +++ b/test/integration/default/bashrc_test.rb @@ -59,4 +59,4 @@ its('content') { should match Regexp.new("^export BASH_IT=\"\/Users\/#{test_kitchen_user}\/.bash_it\"$") } its('content') { should match /^source \${HOME}\/.bashrc$/ } its('content') { should match /^source \$BASH_IT\/bash_it.sh$/ } -end \ No newline at end of file +end From 996b03658f29890cc2ff4dea5795053e85d77740 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 15:43:47 -0600 Subject: [PATCH 16/60] lyraphase_workstation::bashrc: Update ChefSpec tests to check homebrew_no_cleanup_formulae and homebrew_github_api_token edge cases --- spec/unit/recipes/bashrc_spec.rb | 118 ++++++++++++++++++++++--------- 1 file changed, 85 insertions(+), 33 deletions(-) diff --git a/spec/unit/recipes/bashrc_spec.rb b/spec/unit/recipes/bashrc_spec.rb index ba13b25..21c5d61 100644 --- a/spec/unit/recipes/bashrc_spec.rb +++ b/spec/unit/recipes/bashrc_spec.rb @@ -23,46 +23,98 @@ require 'spec_helper' describe_recipe 'lyraphase_workstation::bashrc' do - # Override ChefSpec attributes from spec_shared_contexts - let(:chefspec_options) { - require 'securerandom' - { - default_attributes: {}, - normal_attributes: { 'lyraphase_workstation': { - 'bashrc': { - 'homebrew_github_api_token': "gh_#{SecureRandom.hex(20)}", - 'user_fullname': 'Barney Rubble', - 'user_email': 'barney.rubble@lyraphase.com', - 'user_gpg_keyid': "0x#{SecureRandom.hex(8)}" + context 'when given all bashrc attributes' do + # Override ChefSpec attributes from spec_shared_contexts + let(:chefspec_options) { + require 'securerandom' + { + default_attributes: {}, + normal_attributes: { 'lyraphase_workstation': { + 'bashrc': { + 'homebrew_github_api_token': "gh_#{SecureRandom.hex(20)}", + 'user_fullname': 'Barney Rubble', + 'user_email': 'barney.rubble@lyraphase.com', + 'user_gpg_keyid': "0x#{SecureRandom.hex(8)}", + 'homebrew_no_cleanup_formulae': ['argocd','eksctl','kustomize','rancher-cli','kubernetes-cli'] + } } - } - }, - automatic_attributes: {} + }, + automatic_attributes: {} + } } - } - let(:bashrc_path) { '/Users/brubble/.bashrc' } - let(:bash_logout_path) { '/Users/brubble/.bash_logout' } + let(:bashrc_path) { '/Users/brubble/.bashrc' } + let(:bash_logout_path) { '/Users/brubble/.bash_logout' } - it 'installs custom .bashrc into user homedir' do - expect(chef_run).to create_template(bashrc_path).with( - user: 'brubble', - mode: '0644' - ) + it 'installs custom .bashrc into user homedir' do + expect(chef_run).to create_template(bashrc_path).with( + user: 'brubble', + mode: '0644' + ) - [ "export HOMEBREW_GITHUB_API_TOKEN='#{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token']}'", - "export DEBFULLNAME='#{chef_run.node['lyraphase_workstation']['bashrc']['user_fullname']}'", - "export DEBEMAIL='#{chef_run.node['lyraphase_workstation']['bashrc']['user_email']}'", - "export DEBSIGN_KEYID='#{chef_run.node['lyraphase_workstation']['bashrc']['user_gpg_keyid']}'", - ].each do |expected_regex| - expect(chef_run).to render_file(bashrc_path).with_content(Regexp.new("^\s*#{expected_regex}\s*(#.*)?$")) + [ "export HOMEBREW_GITHUB_API_TOKEN='#{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token']}'", + "export DEBFULLNAME='#{chef_run.node['lyraphase_workstation']['bashrc']['user_fullname']}'", + "export DEBEMAIL='#{chef_run.node['lyraphase_workstation']['bashrc']['user_email']}'", + "export DEBSIGN_KEYID='#{chef_run.node['lyraphase_workstation']['bashrc']['user_gpg_keyid']}'", + "export HOMEBREW_NO_CLEANUP_FORMULAE=#{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_no_cleanup_formulae'].join(',')}" + ].each do |expected_regex| + expect(chef_run).to render_file(bashrc_path).with_content(Regexp.new("^\s*#{expected_regex}\s*(#.*)?$")) + end + end + + it 'installs custom .bash_logout into user homedir' do + expect(chef_run).to create_template(bash_logout_path).with( + user: 'brubble', + mode: '0644' + ) end end - it 'installs custom .bash_logout into user homedir' do - expect(chef_run).to create_template(bash_logout_path).with( - user: 'brubble', - mode: '0644' - ) + context 'when given no (default) bashrc attributes' do + # Use ChefSpec attributes from spec_shared_contexts + let(:expected_attributes) { + { + lyraphase_workstation: { + bashrc: { + user_fullname: 'James Cuzella', + user_email: 'james.cuzella@lyraphase.com', + user_gpg_keyid: '0x2689A459B1568D09' + } + } + } + } + + let(:bashrc_path) { '/Users/brubble/.bashrc' } + let(:bash_logout_path) { '/Users/brubble/.bash_logout' } + + it 'installs custom .bashrc into user homedir' do + expect(chef_run).to create_template(bashrc_path).with( + user: 'brubble', + mode: '0644' + ) + + [ "export DEBFULLNAME='#{chef_run.node['lyraphase_workstation']['bashrc']['user_fullname']}'", + "export DEBEMAIL='#{chef_run.node['lyraphase_workstation']['bashrc']['user_email']}'", + "export DEBSIGN_KEYID='#{chef_run.node['lyraphase_workstation']['bashrc']['user_gpg_keyid']}'" + ].each do |expected_regex| + expect(chef_run).to render_file(bashrc_path).with_content(Regexp.new("^\s*#{expected_regex}\s*(#.*)?$")) + end + + # Default is no / empty attributes: + # - homebrew_github_api_token + # - homebrew_no_cleanup_formulae + [ "export HOMEBREW_GITHUB_API_TOKEN='#{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token']}'", + "export HOMEBREW_NO_CLEANUP_FORMULAE=.*" + ].each do |expected_regex| + expect(chef_run).to_not render_file(bashrc_path).with_content(/^\s*export HOMEBREW_NO_CLEANUP_FORMULAE=.*$/) + end + end + + it 'installs custom .bash_logout into user homedir' do + expect(chef_run).to create_template(bash_logout_path).with( + user: 'brubble', + mode: '0644' + ) + end end end From 7069d0585435372510fdc9f5bd80576f7c913c00 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 16:27:08 -0600 Subject: [PATCH 17/60] lyraphase_workstation::bashrc: Fix negated with_content matching (Ref: chefspec/chefspec#865 ) --- spec/unit/recipes/bashrc_spec.rb | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/spec/unit/recipes/bashrc_spec.rb b/spec/unit/recipes/bashrc_spec.rb index 21c5d61..2ec40ac 100644 --- a/spec/unit/recipes/bashrc_spec.rb +++ b/spec/unit/recipes/bashrc_spec.rb @@ -46,7 +46,7 @@ let(:bashrc_path) { '/Users/brubble/.bashrc' } let(:bash_logout_path) { '/Users/brubble/.bash_logout' } - it 'installs custom .bashrc into user homedir' do + it 'installs custom .bashrc into user homedir with given settings' do expect(chef_run).to create_template(bashrc_path).with( user: 'brubble', mode: '0644' @@ -72,22 +72,10 @@ context 'when given no (default) bashrc attributes' do # Use ChefSpec attributes from spec_shared_contexts - let(:expected_attributes) { - { - lyraphase_workstation: { - bashrc: { - user_fullname: 'James Cuzella', - user_email: 'james.cuzella@lyraphase.com', - user_gpg_keyid: '0x2689A459B1568D09' - } - } - } - } - let(:bashrc_path) { '/Users/brubble/.bashrc' } let(:bash_logout_path) { '/Users/brubble/.bash_logout' } - it 'installs custom .bashrc into user homedir' do + it 'installs custom .bashrc into user homedir with expected settings' do expect(chef_run).to create_template(bashrc_path).with( user: 'brubble', mode: '0644' @@ -106,7 +94,11 @@ [ "export HOMEBREW_GITHUB_API_TOKEN='#{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token']}'", "export HOMEBREW_NO_CLEANUP_FORMULAE=.*" ].each do |expected_regex| - expect(chef_run).to_not render_file(bashrc_path).with_content(/^\s*export HOMEBREW_NO_CLEANUP_FORMULAE=.*$/) + # Note: Negated with_content requires passing a Proc / Block! + # Reference: https://github.com/chefspec/chefspec/issues/865 + expect(chef_run).to(render_file(bashrc_path).with_content do |content| + expect(content).not_to match(Regexp.new("^\s*#{expected_regex}\s*(#.*)?$")) + end) end end From f15a81f81b79e4979e96e609250f2ef9466d1afe Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 16:30:50 -0600 Subject: [PATCH 18/60] lyraphase_workstation::bashrc: Add ChefSpec test for homebrew_github_api_token_comment --- spec/unit/recipes/bashrc_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/unit/recipes/bashrc_spec.rb b/spec/unit/recipes/bashrc_spec.rb index 2ec40ac..b323226 100644 --- a/spec/unit/recipes/bashrc_spec.rb +++ b/spec/unit/recipes/bashrc_spec.rb @@ -27,11 +27,13 @@ # Override ChefSpec attributes from spec_shared_contexts let(:chefspec_options) { require 'securerandom' + require 'date' { default_attributes: {}, normal_attributes: { 'lyraphase_workstation': { 'bashrc': { 'homebrew_github_api_token': "gh_#{SecureRandom.hex(20)}", + 'homebrew_github_api_token_comment': "rotgut butanol - (#{DateTime.now.strftime('%Y-%m-%d %H:%M:%S %z')}) - lyra.37om.com - public_repo RO", 'user_fullname': 'Barney Rubble', 'user_email': 'barney.rubble@lyraphase.com', 'user_gpg_keyid': "0x#{SecureRandom.hex(8)}", @@ -53,6 +55,7 @@ ) [ "export HOMEBREW_GITHUB_API_TOKEN='#{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token']}'", + "export HOMEBREW_GITHUB_API_TOKEN='.*?' # #{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token_comment']}", "export DEBFULLNAME='#{chef_run.node['lyraphase_workstation']['bashrc']['user_fullname']}'", "export DEBEMAIL='#{chef_run.node['lyraphase_workstation']['bashrc']['user_email']}'", "export DEBSIGN_KEYID='#{chef_run.node['lyraphase_workstation']['bashrc']['user_gpg_keyid']}'", @@ -92,6 +95,7 @@ # - homebrew_github_api_token # - homebrew_no_cleanup_formulae [ "export HOMEBREW_GITHUB_API_TOKEN='#{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token']}'", + "export HOMEBREW_GITHUB_API_TOKEN='.*?' # #{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token_comment']}", "export HOMEBREW_NO_CLEANUP_FORMULAE=.*" ].each do |expected_regex| # Note: Negated with_content requires passing a Proc / Block! From 5e14fcd2b7e939dee3943a9d2accb9b2e4ee4516 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 16:58:56 -0600 Subject: [PATCH 19/60] lyraphase_workstation::bashrc: Fix Regexp <=> string incompatible chars in token comment --- spec/unit/recipes/bashrc_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/recipes/bashrc_spec.rb b/spec/unit/recipes/bashrc_spec.rb index b323226..fc1fd3a 100644 --- a/spec/unit/recipes/bashrc_spec.rb +++ b/spec/unit/recipes/bashrc_spec.rb @@ -33,7 +33,7 @@ normal_attributes: { 'lyraphase_workstation': { 'bashrc': { 'homebrew_github_api_token': "gh_#{SecureRandom.hex(20)}", - 'homebrew_github_api_token_comment': "rotgut butanol - (#{DateTime.now.strftime('%Y-%m-%d %H:%M:%S %z')}) - lyra.37om.com - public_repo RO", + 'homebrew_github_api_token_comment': "rotgut butanol - #{DateTime.now.strftime('%Y-%m-%d %H:%M:%S %z')} - lyra.37om.com - public_repo RO", 'user_fullname': 'Barney Rubble', 'user_email': 'barney.rubble@lyraphase.com', 'user_gpg_keyid': "0x#{SecureRandom.hex(8)}", From a1e8dc7172a393d91efe2d88de93dee8d3dcc55e Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 17:01:00 -0600 Subject: [PATCH 20/60] lyraphase_workstation::bashrc: Implement homebrew_github_api_token{,_comment} and homebrew_no_cleanup_formulae --- recipes/bashrc.rb | 34 ++++++++++++++++++++++++++-------- templates/default/bashrc.erb | 8 +++++++- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/recipes/bashrc.rb b/recipes/bashrc.rb index 7d9bf0c..75e14df 100644 --- a/recipes/bashrc.rb +++ b/recipes/bashrc.rb @@ -24,14 +24,30 @@ bashrc_path = Pathname.new(File.join(node['lyraphase_workstation']['home'], '.bashrc')) bash_logout_path = Pathname.new(File.join(node['lyraphase_workstation']['home'], '.bash_logout')) -homebrew_github_api_token = begin - data_bag_item('lyraphase_workstation', 'bashrc')['homebrew_github_api_token'] - rescue - nil - end +# Gather Homebrew GitHub token from encrypted data bag +homebrew_github_api_token_data = begin + data_bag_item('lyraphase_workstation', 'bashrc') + rescue + nil + end -if homebrew_github_api_token.nil? && !node['lyraphase_workstation']['bashrc']['homebrew_github_api_token'].nil? && !node['lyraphase_workstation']['bashrc']['homebrew_github_api_token'].nil? - homebrew_github_api_token = node['lyraphase_workstation']['bashrc']['homebrew_github_api_token'] +homebrew_github_api_token_hash = Hash.new() +['homebrew_github_api_token', 'homebrew_github_api_token_comment'].each do |data_bag_key| + if !homebrew_github_api_token_data.nil? && homebrew_github_api_token_data.has_key?(data_bag_key) + homebrew_github_api_token_hash[data_bag_key] = begin + homebrew_github_api_token_data[data_bag_key] + rescue + nil + end + end + + if homebrew_github_api_token_hash[data_bag_key].nil? && !node['lyraphase_workstation']['bashrc'][data_bag_key].nil? + homebrew_github_api_token_hash[data_bag_key] = node['lyraphase_workstation']['bashrc'][data_bag_key] + end +end + +if !node['lyraphase_workstation']['bashrc']['homebrew_no_cleanup_formulae'].nil? + homebrew_no_cleanup_formulae = node['lyraphase_workstation']['bashrc']['homebrew_no_cleanup_formulae'] end template bashrc_path do @@ -42,7 +58,9 @@ user_fullname: node['lyraphase_workstation']['bashrc']['user_fullname'], user_email: node['lyraphase_workstation']['bashrc']['user_email'], user_gpg_keyid: node['lyraphase_workstation']['bashrc']['user_gpg_keyid'], - homebrew_github_api_token: homebrew_github_api_token + homebrew_github_api_token: homebrew_github_api_token_hash['homebrew_github_api_token'], + homebrew_github_api_token_comment: homebrew_github_api_token_hash['homebrew_github_api_token_comment'], + homebrew_no_cleanup_formulae: homebrew_no_cleanup_formulae ) end diff --git a/templates/default/bashrc.erb b/templates/default/bashrc.erb index d4b3fb6..c351583 100644 --- a/templates/default/bashrc.erb +++ b/templates/default/bashrc.erb @@ -176,8 +176,14 @@ then # Use General Colorizer source "`brew --prefix`/etc/grc.sh" +<% if @homebrew_github_api_token %> # Set homebrew OAuth token - export HOMEBREW_GITHUB_API_TOKEN='<%= @homebrew_github_api_token -%>' # lyra.37om.com + export HOMEBREW_GITHUB_API_TOKEN='<%= @homebrew_github_api_token -%>' # <%= @homebrew_github_api_token_comment %> +<% end %> +<% if @homebrew_no_cleanup_formulae %> + # Keep old versions for specific formulae + export HOMEBREW_NO_CLEANUP_FORMULAE=<%= @homebrew_no_cleanup_formulae.join(',') %> +<% end %> # Alias defunkt/hub as git eval "$(hub alias -s)" From 656162e30b359c00e21cec7998ab44b664c51e94 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 17:02:28 -0600 Subject: [PATCH 21/60] .vscode: Add Extension recommendations & default Code Workspace files --- .vscode/extensions.json | 5 +++++ .vscode/lyraphase_workstation.code-workspace | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 .vscode/extensions.json create mode 100644 .vscode/lyraphase_workstation.code-workspace diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..7f1fc95 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "chef-software.Chef" + ] +} \ No newline at end of file diff --git a/.vscode/lyraphase_workstation.code-workspace b/.vscode/lyraphase_workstation.code-workspace new file mode 100644 index 0000000..bab1b7f --- /dev/null +++ b/.vscode/lyraphase_workstation.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": ".." + } + ], + "settings": {} +} \ No newline at end of file From 9fbf9562af95710c100d8fdb306af200b071fc1d Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 20:28:09 -0600 Subject: [PATCH 22/60] lyraphase_workstation::bashrc: Add shared_examples & shared_context for testing Chef Log levels & functions --- recipes/bashrc.rb | 15 ++- spec/spec_helper.rb | 7 ++ spec/spec_shared_contexts.rb | 202 +++++++++++++++++++++++++++++++ spec/unit/recipes/bashrc_spec.rb | 73 +++++++++++ 4 files changed, 296 insertions(+), 1 deletion(-) diff --git a/recipes/bashrc.rb b/recipes/bashrc.rb index 75e14df..e6bc616 100644 --- a/recipes/bashrc.rb +++ b/recipes/bashrc.rb @@ -31,9 +31,11 @@ nil end +puts("homebrew_github_api_token_data = #{homebrew_github_api_token_data}") homebrew_github_api_token_hash = Hash.new() ['homebrew_github_api_token', 'homebrew_github_api_token_comment'].each do |data_bag_key| - if !homebrew_github_api_token_data.nil? && homebrew_github_api_token_data.has_key?(data_bag_key) + if !homebrew_github_api_token_data.nil? && homebrew_github_api_token_data.has_key?(node['name']) && homebrew_github_api_token_data.has_key?(data_bag_key) + Chef::Log.info("Loading Homebrew GitHub API token for Node Name: #{node['name']}") homebrew_github_api_token_hash[data_bag_key] = begin homebrew_github_api_token_data[data_bag_key] rescue @@ -44,8 +46,19 @@ if homebrew_github_api_token_hash[data_bag_key].nil? && !node['lyraphase_workstation']['bashrc'][data_bag_key].nil? homebrew_github_api_token_hash[data_bag_key] = node['lyraphase_workstation']['bashrc'][data_bag_key] end + + if homebrew_github_api_token_hash[data_bag_key].nil? && !homebrew_github_api_token_data.nil? + Chef::Log.warn("Could not find Homebrew GitHub API token attribute #{data_bag_key} in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}") + Chef::Log.warn("Expected Data Bag Item Schema: {\"id\": \"bashrc\", \"#{node['name']}\": {\"homebrew_github_api_token\": \"gh_f00dcafevagrant\", \"homebrew_github_api_token_comment\": \"some optional comment\"}}") + end end +Chef::Log.info('INFO TEST') +Chef::Log.trace('TRACE TEST') +Chef::Log.fatal('FATAL TEST') +Chef::Log.error('ERROR TEST') +Chef::Log.debug('DEBUG TEST') + if !node['lyraphase_workstation']['bashrc']['homebrew_no_cleanup_formulae'].nil? homebrew_no_cleanup_formulae = node['lyraphase_workstation']['bashrc']['homebrew_no_cleanup_formulae'] end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 43aefe2..f68040a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -33,9 +33,16 @@ config.alias_example_group_to :describe_recipe, type: :recipe config.alias_example_group_to :describe_helpers, type: :helpers config.alias_example_group_to :describe_resource, type: :resource + config.alias_example_group_to :describe_recipe_with_expected_logs, type: :recipe_with_expected_logs + config.alias_it_behaves_like_to :it_outputs, 'outputs' + config.alias_example_to :it_logs config.before { stub_const('ENV', ENV.to_hash.merge('SUDO_USER' => 'brubble')) } config.filter_run_when_matching :focus + + config.before :each do |x| + puts("RUNNING EXAMPLE: #{x.metadata[:example_group][:full_description]}") + end end at_exit { ChefSpec::Coverage.report! } diff --git a/spec/spec_shared_contexts.rb b/spec/spec_shared_contexts.rb index 2bf9c88..b8cb4b0 100644 --- a/spec/spec_shared_contexts.rb +++ b/spec/spec_shared_contexts.rb @@ -180,6 +180,208 @@ def recipe_name end end +# Shared examples for checking for Chef::Log output +shared_examples 'Chef TRACE Logs' do + it_logs 'with messages' do + skip('No chef_log_trace_msgs expected') if chef_log_trace_msgs.empty? + chef_log_trace_msgs.each do |trace_msg| + expect(Chef::Log).to receive(:trace).with(trace_msg) + end + # remember that you actually have to call `chef_run` after setting the expect + bare_chef_run.converge(described_recipe) + end +end + +shared_examples 'Chef INFO Logs' do + it_logs 'with messages' do + skip('No chef_log_info_msgs expected') if chef_log_info_msgs.empty? + chef_log_info_msgs.each do |info_msg| + expect(Chef::Log).to receive(:info).with(info_msg) + end + # remember that you actually have to call `chef_run` after setting the expect + bare_chef_run.converge(described_recipe) + end +end + +shared_examples 'Chef WARN Logs' do + it_logs 'with messages' do + skip('No chef_log_warnings expected') if chef_log_warnings.empty? + puts("DESCRIBED RECIPE: #{described_recipe}") + chef_log_warnings.each do |warn_msg| + expect(Chef::Log).to receive(:warn).with(warn_msg) + end + # remember that you actually have to call `chef_run` after setting the expect + bare_chef_run.converge(described_recipe) + end +end + +shared_examples 'Chef FATAL Logs' do + it_logs 'with messages' do + skip('No chef_log_fatal_msgs expected') if chef_log_fatal_msgs.empty? + chef_log_fatal_msgs.each do |fatal_msg| + expect(Chef::Log).to receive(:fatal).with(fatal_msg) + end + # remember that you actually have to call `chef_run` after setting the expect + bare_chef_run.converge(described_recipe) + end +end + +shared_examples 'Chef ERROR Logs' do + it_logs 'with messages' do + skip('No chef_log_error_msgs expected') if chef_log_error_msgs.empty? + chef_log_error_msgs.each do |error_msg| + expect(Chef::Log).to receive(:error).with(error_msg) + end + # remember that you actually have to call `chef_run` after setting the expect + bare_chef_run.converge(described_recipe) + end +end + +shared_examples 'Chef DEBUG Logs' do + it_logs 'with messages' do + skip('No chef_log_debug_msgs expected') if chef_log_debug_msgs.empty? + chef_log_debug_msgs.each do |debug_msg| + expect(Chef::Log).to receive(:debug).with(debug_msg) + end + # remember that you actually have to call `chef_run` after setting the expect + bare_chef_run.converge(described_recipe) + end +end + +shared_context 'when expected to output Chef Log messages', type: :recipe_with_expected_logs do + # Individual spec Example Groups can override this to inject node attributes + let(:chefspec_options) do + { + default_attributes: {}, + normal_attributes: {}, + automatic_attributes: {}, + } + end + + let(:bare_chef_run) do + ## Note: We do NOT run chef_run.converge here so Chef::Log shared_examples will work + ## bare_chef_run.converge must be called inside the example block to output anything + puts("INSIDE chef_run #{described_recipe}") + klass = ChefSpec.constants.include?(:SoloRunner) ? ChefSpec::SoloRunner : ChefSpec::ServerRunner + klass.new(chefspec_options) do |node| + node.normal.merge!(node_attributes) + end + end + + let(:chef_run) do + ## Note: We run chef_run.converge here to raise exceptions for RSpec to check + puts("INSIDE chef_run #{described_recipe}") + klass = ChefSpec.constants.include?(:SoloRunner) ? ChefSpec::SoloRunner : ChefSpec::ServerRunner + klass.new(chefspec_options) do |node| + node.normal.merge!(node_attributes) + end.converge(described_recipe) + end + + let(:node) { chef_run.node } + + def lyraphase_workstation_user + create_singleton_struct 'EtcPasswd', [ :name, :passwd, :uid, :gid, :gecos, :dir, :shell, :change, :uclass, :expire ] + Struct::EtcPasswd.new('brubble', '********', 501, 20, 'Barney Rubble', '/Users/brubble', '/bin/bash', 0, '', 0) + end + + # Global ChefSpec attributes for all Example Groups + def node_attributes + attributes = { + 'platform': 'mac_os_x', + 'version': '10.15', + 'etc': { + 'passwd': { + 'brubble': lyraphase_workstation_user, + }, + }, + 'sprout': { + 'home': '/Users/brubble', + 'user': 'brubble', + }, + 'lyraphase_workstation': { + 'user': 'brubble', + 'home': '/Users/brubble', + }, + } + stringify_keys(attributes) + end + + def cookbook_recipe_names + described_recipe.split('::', 2) + end + + def cookbook_name + cookbook_recipe_names.first + end + + def recipe_name + cookbook_recipe_names.last + end + + def default_cookbook_attribute(attribute_name) + node[cookbook_name][attribute_name] + end + + # Override this inside the context block, to expect trace messages + let(:chef_log_trace_msgs) do + [] + end + + # Override this inside the context block, to expect info messages + let(:chef_log_info_msgs) do + [] + end + + # Override this inside the context block, to expect warnings + let(:chef_log_warnings) do + [] + end + + # Override this inside the context block, to expect fatal messages + let(:chef_log_fatal_msgs) do + [] + end + + # Override this inside the context block, to expect error messages + let(:chef_log_error_msgs) do + [] + end + + # Override this inside the context block, to expect debug messages + let(:chef_log_debug_msgs) do + [] + end + + before(:each) do + # Stub log levels: debug, error, fatal, info, trace + chef_log_trace_msgs.each do |trace_msg| + allow(Chef::Log).to receive(:trace).with(trace_msg).and_return(nil) + allow(Chef::Log).to receive(:trace).and_return(nil) + end + chef_log_info_msgs.each do |info_msg| + allow(Chef::Log).to receive(:info).with(info_msg).and_return(nil) + allow(Chef::Log).to receive(:info).and_return(nil) + end + chef_log_warnings.each do |warning_msg| + allow(Chef::Log).to receive(:warn).with(warning_msg).and_return(nil) + allow(Chef::Log).to receive(:warn).and_return(nil) + end + chef_log_fatal_msgs.each do |fatal_msg| + allow(Chef::Log).to receive(:fatal).with(fatal_msg).and_return(nil) + allow(Chef::Log).to receive(:fatal).and_return(nil) + end + chef_log_error_msgs.each do |error_msg| + allow(Chef::Log).to receive(:error).with(error_msg).and_return(nil) + allow(Chef::Log).to receive(:error).and_return(nil) + end + chef_log_debug_msgs.each do |debug_msg| + allow(Chef::Log).to receive(:debug).with(debug_msg).and_return(nil) + allow(Chef::Log).to receive(:debug).and_return(nil) + end + end + +end + shared_context 'Chef 14.x no EtcPasswd' do let(:chef_run) do ## Note: We run chef_run.converge here to raise exceptions for RSpec to check diff --git a/spec/unit/recipes/bashrc_spec.rb b/spec/unit/recipes/bashrc_spec.rb index fc1fd3a..720d852 100644 --- a/spec/unit/recipes/bashrc_spec.rb +++ b/spec/unit/recipes/bashrc_spec.rb @@ -114,3 +114,76 @@ end end end + +describe_recipe_with_expected_logs 'lyraphase_workstation::bashrc' do + # Use ChefSpec attributes from spec_shared_contexts + # Override ChefSpec attributes from spec_shared_contexts + let(:chefspec_options) { + require 'securerandom' + require 'date' + { + default_attributes: {}, + normal_attributes: { 'lyraphase_workstation': { + 'bashrc': { + 'homebrew_github_api_token': nil, + 'homebrew_github_api_token_comment': nil, + 'user_fullname': 'Barney Rubble', + 'user_email': 'barney.rubble@lyraphase.com', + 'user_gpg_keyid': "0x#{SecureRandom.hex(8)}" + } + } + }, + automatic_attributes: {} + } + } + let(:invalid_data_bag_item) { + { id: 'bashrc', comment: 'wrong schema', + homebrew_github_api_token: "gh_#{SecureRandom.hex(20)}", + homebrew_github_api_token_comment: 'This should be under node name hash key' + } + } + # Expect Chef::Log.warn messages + let(:chef_log_warnings) { + [ + "Could not find Homebrew GitHub API token attribute homebrew_github_api_token in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}", + "Could not find Homebrew GitHub API token attribute homebrew_github_api_token_comment in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}", + "Expected Data Bag Item Schema: {\"id\": \"bashrc\", \"#{node['name']}\": {\"homebrew_github_api_token\": \"gh_f00dcafevagrant\", \"homebrew_github_api_token_comment\": \"some optional comment\"}}" + ] + } + + let(:chef_log_trace_msgs) { + ['TRACE TEST'] + } + + let(:chef_log_info_msgs) { + ['INFO TEST'] + } + + let(:chef_log_fatal_msgs) do + ['FATAL TEST'] + end + + # Override this inside the context block, to expect error messages + let(:chef_log_error_msgs) do + ['ERROR TEST'] + end + + # Override this inside the context block, to expect debug messages + let(:chef_log_debug_msgs) do + ['DEBUG TEST'] + end + + before(:each) do + stub_data_bag_item('lyraphase_workstation', 'bashrc').and_return(invalid_data_bag_item) + end + + it_outputs 'Chef WARN Logs' + it_outputs 'Chef TRACE Logs' + it_outputs 'Chef INFO Logs' + it_outputs 'Chef FATAL Logs' + it_outputs 'Chef ERROR Logs' + it_outputs 'Chef DEBUG Logs' + it 'does not raise error' do + expect { chef_run }.to_not raise_error + end +end \ No newline at end of file From c0bfa53b8d9231324ee433331919a314480ab85a Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 21:11:57 -0600 Subject: [PATCH 23/60] lyraphase_workstation::bashrc: Simplify/Refactor "outputs Chef * Logs" & remove debug messages --- recipes/bashrc.rb | 7 ------ spec/spec_helper.rb | 4 ---- spec/spec_shared_contexts.rb | 41 +++++++++++++++++++++----------- spec/unit/recipes/bashrc_spec.rb | 35 +++------------------------ 4 files changed, 30 insertions(+), 57 deletions(-) diff --git a/recipes/bashrc.rb b/recipes/bashrc.rb index e6bc616..da84321 100644 --- a/recipes/bashrc.rb +++ b/recipes/bashrc.rb @@ -31,7 +31,6 @@ nil end -puts("homebrew_github_api_token_data = #{homebrew_github_api_token_data}") homebrew_github_api_token_hash = Hash.new() ['homebrew_github_api_token', 'homebrew_github_api_token_comment'].each do |data_bag_key| if !homebrew_github_api_token_data.nil? && homebrew_github_api_token_data.has_key?(node['name']) && homebrew_github_api_token_data.has_key?(data_bag_key) @@ -53,12 +52,6 @@ end end -Chef::Log.info('INFO TEST') -Chef::Log.trace('TRACE TEST') -Chef::Log.fatal('FATAL TEST') -Chef::Log.error('ERROR TEST') -Chef::Log.debug('DEBUG TEST') - if !node['lyraphase_workstation']['bashrc']['homebrew_no_cleanup_formulae'].nil? homebrew_no_cleanup_formulae = node['lyraphase_workstation']['bashrc']['homebrew_no_cleanup_formulae'] end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f68040a..cfc5dc3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -39,10 +39,6 @@ config.before { stub_const('ENV', ENV.to_hash.merge('SUDO_USER' => 'brubble')) } config.filter_run_when_matching :focus - - config.before :each do |x| - puts("RUNNING EXAMPLE: #{x.metadata[:example_group][:full_description]}") - end end at_exit { ChefSpec::Coverage.report! } diff --git a/spec/spec_shared_contexts.rb b/spec/spec_shared_contexts.rb index b8cb4b0..5d404d3 100644 --- a/spec/spec_shared_contexts.rb +++ b/spec/spec_shared_contexts.rb @@ -182,7 +182,7 @@ def recipe_name # Shared examples for checking for Chef::Log output shared_examples 'Chef TRACE Logs' do - it_logs 'with messages' do + it_logs 'with expected messages' do skip('No chef_log_trace_msgs expected') if chef_log_trace_msgs.empty? chef_log_trace_msgs.each do |trace_msg| expect(Chef::Log).to receive(:trace).with(trace_msg) @@ -193,7 +193,7 @@ def recipe_name end shared_examples 'Chef INFO Logs' do - it_logs 'with messages' do + it_logs 'with expected messages' do skip('No chef_log_info_msgs expected') if chef_log_info_msgs.empty? chef_log_info_msgs.each do |info_msg| expect(Chef::Log).to receive(:info).with(info_msg) @@ -204,10 +204,9 @@ def recipe_name end shared_examples 'Chef WARN Logs' do - it_logs 'with messages' do - skip('No chef_log_warnings expected') if chef_log_warnings.empty? - puts("DESCRIBED RECIPE: #{described_recipe}") - chef_log_warnings.each do |warn_msg| + it_logs 'with expected messages' do + skip('No chef_log_warn_msgs expected') if chef_log_warn_msgs.empty? + chef_log_warn_msgs.each do |warn_msg| expect(Chef::Log).to receive(:warn).with(warn_msg) end # remember that you actually have to call `chef_run` after setting the expect @@ -216,7 +215,7 @@ def recipe_name end shared_examples 'Chef FATAL Logs' do - it_logs 'with messages' do + it_logs 'with expected messages' do skip('No chef_log_fatal_msgs expected') if chef_log_fatal_msgs.empty? chef_log_fatal_msgs.each do |fatal_msg| expect(Chef::Log).to receive(:fatal).with(fatal_msg) @@ -227,7 +226,7 @@ def recipe_name end shared_examples 'Chef ERROR Logs' do - it_logs 'with messages' do + it_logs 'with expected messages' do skip('No chef_log_error_msgs expected') if chef_log_error_msgs.empty? chef_log_error_msgs.each do |error_msg| expect(Chef::Log).to receive(:error).with(error_msg) @@ -238,7 +237,7 @@ def recipe_name end shared_examples 'Chef DEBUG Logs' do - it_logs 'with messages' do + it_logs 'with expected messages' do skip('No chef_log_debug_msgs expected') if chef_log_debug_msgs.empty? chef_log_debug_msgs.each do |debug_msg| expect(Chef::Log).to receive(:debug).with(debug_msg) @@ -261,7 +260,6 @@ def recipe_name let(:bare_chef_run) do ## Note: We do NOT run chef_run.converge here so Chef::Log shared_examples will work ## bare_chef_run.converge must be called inside the example block to output anything - puts("INSIDE chef_run #{described_recipe}") klass = ChefSpec.constants.include?(:SoloRunner) ? ChefSpec::SoloRunner : ChefSpec::ServerRunner klass.new(chefspec_options) do |node| node.normal.merge!(node_attributes) @@ -270,7 +268,6 @@ def recipe_name let(:chef_run) do ## Note: We run chef_run.converge here to raise exceptions for RSpec to check - puts("INSIDE chef_run #{described_recipe}") klass = ChefSpec.constants.include?(:SoloRunner) ? ChefSpec::SoloRunner : ChefSpec::ServerRunner klass.new(chefspec_options) do |node| node.normal.merge!(node_attributes) @@ -322,6 +319,8 @@ def default_cookbook_attribute(attribute_name) node[cookbook_name][attribute_name] end + let(:chef_log) { class_double(Chef::Log) } + # Override this inside the context block, to expect trace messages let(:chef_log_trace_msgs) do [] @@ -333,7 +332,7 @@ def default_cookbook_attribute(attribute_name) end # Override this inside the context block, to expect warnings - let(:chef_log_warnings) do + let(:chef_log_warn_msgs) do [] end @@ -353,30 +352,44 @@ def default_cookbook_attribute(attribute_name) end before(:each) do + allow(chef_log).to receive(:new).and_return(chef_log) + allow(Chef::Log).to receive(:new).and_return(chef_log) # Stub log levels: debug, error, fatal, info, trace chef_log_trace_msgs.each do |trace_msg| allow(Chef::Log).to receive(:trace).with(trace_msg).and_return(nil) allow(Chef::Log).to receive(:trace).and_return(nil) + allow(chef_log).to receive(:trace).and_return(nil) end chef_log_info_msgs.each do |info_msg| allow(Chef::Log).to receive(:info).with(info_msg).and_return(nil) allow(Chef::Log).to receive(:info).and_return(nil) end - chef_log_warnings.each do |warning_msg| - allow(Chef::Log).to receive(:warn).with(warning_msg).and_return(nil) + chef_log_warn_msgs.each do |warn_msg| + allow(Chef::Log).to receive(:warn).with(warn_msg).and_return(nil) + allow(Chef::Log).to receive(:warn).with(anything).and_return(nil) allow(Chef::Log).to receive(:warn).and_return(nil) + allow(chef_log).to receive(:warn).and_return(nil) + allow(chef_log).to receive(:warn).with(anything).and_return(nil) end chef_log_fatal_msgs.each do |fatal_msg| allow(Chef::Log).to receive(:fatal).with(fatal_msg).and_return(nil) + allow(Chef::Log).to receive(:fatal).with(anything).and_return(nil) allow(Chef::Log).to receive(:fatal).and_return(nil) + allow(chef_log).to receive(:fatal).and_return(nil) + allow(chef_log).to receive(:fatal).with(anything).and_return(nil) end chef_log_error_msgs.each do |error_msg| allow(Chef::Log).to receive(:error).with(error_msg).and_return(nil) + allow(Chef::Log).to receive(:error).with(anything).and_return(nil) allow(Chef::Log).to receive(:error).and_return(nil) + allow(chef_log).to receive(:error).and_return(nil) + allow(chef_log).to receive(:error).with(anything).and_return(nil) end chef_log_debug_msgs.each do |debug_msg| allow(Chef::Log).to receive(:debug).with(debug_msg).and_return(nil) allow(Chef::Log).to receive(:debug).and_return(nil) + allow(chef_log).to receive(:debug).and_return(nil) + allow(chef_log).to receive(:debug).with(anything).and_return(nil) end end diff --git a/spec/unit/recipes/bashrc_spec.rb b/spec/unit/recipes/bashrc_spec.rb index 720d852..8514562 100644 --- a/spec/unit/recipes/bashrc_spec.rb +++ b/spec/unit/recipes/bashrc_spec.rb @@ -126,10 +126,7 @@ normal_attributes: { 'lyraphase_workstation': { 'bashrc': { 'homebrew_github_api_token': nil, - 'homebrew_github_api_token_comment': nil, - 'user_fullname': 'Barney Rubble', - 'user_email': 'barney.rubble@lyraphase.com', - 'user_gpg_keyid': "0x#{SecureRandom.hex(8)}" + 'homebrew_github_api_token_comment': nil } } }, @@ -143,7 +140,7 @@ } } # Expect Chef::Log.warn messages - let(:chef_log_warnings) { + let(:chef_log_warn_msgs) { [ "Could not find Homebrew GitHub API token attribute homebrew_github_api_token in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}", "Could not find Homebrew GitHub API token attribute homebrew_github_api_token_comment in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}", @@ -151,38 +148,12 @@ ] } - let(:chef_log_trace_msgs) { - ['TRACE TEST'] - } - - let(:chef_log_info_msgs) { - ['INFO TEST'] - } - - let(:chef_log_fatal_msgs) do - ['FATAL TEST'] - end - - # Override this inside the context block, to expect error messages - let(:chef_log_error_msgs) do - ['ERROR TEST'] - end - - # Override this inside the context block, to expect debug messages - let(:chef_log_debug_msgs) do - ['DEBUG TEST'] - end - before(:each) do stub_data_bag_item('lyraphase_workstation', 'bashrc').and_return(invalid_data_bag_item) end it_outputs 'Chef WARN Logs' - it_outputs 'Chef TRACE Logs' - it_outputs 'Chef INFO Logs' - it_outputs 'Chef FATAL Logs' - it_outputs 'Chef ERROR Logs' - it_outputs 'Chef DEBUG Logs' + it 'does not raise error' do expect { chef_run }.to_not raise_error end From 990ec1a2823a834c6974dffde70a236db1a93227 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 22:58:04 -0600 Subject: [PATCH 24/60] lyraphase_workstation::bashrc: Refactor & D.R.Y. ChefSpec tests --- spec/spec_shared_contexts.rb | 7 ++ spec/unit/recipes/bashrc_spec.rb | 168 ++++++++++++++++++++----------- 2 files changed, 115 insertions(+), 60 deletions(-) diff --git a/spec/spec_shared_contexts.rb b/spec/spec_shared_contexts.rb index 5d404d3..8e5c021 100644 --- a/spec/spec_shared_contexts.rb +++ b/spec/spec_shared_contexts.rb @@ -351,7 +351,14 @@ def default_cookbook_attribute(attribute_name) [] end + # Override this method to add before(:each) hooks at this shared_context level + def before_each_shared_example + end + before(:each) do + # Provide method hook for adding top-level shared_context before steps (e.g. stubs) + before_each_shared_example + allow(chef_log).to receive(:new).and_return(chef_log) allow(Chef::Log).to receive(:new).and_return(chef_log) # Stub log levels: debug, error, fatal, info, trace diff --git a/spec/unit/recipes/bashrc_spec.rb b/spec/unit/recipes/bashrc_spec.rb index 8514562..7dcecff 100644 --- a/spec/unit/recipes/bashrc_spec.rb +++ b/spec/unit/recipes/bashrc_spec.rb @@ -22,6 +22,53 @@ require 'spec_helper' +shared_examples 'bash_logout' do + let(:bash_logout_path) { '/Users/brubble/.bash_logout' } + it 'installs custom .bash_logout into user homedir' do + expect(chef_run).to create_template(bash_logout_path).with( + user: 'brubble', + mode: '0644' + ) + end +end + +shared_examples 'it does not raise error' do + it 'does not raise error' do + expect { chef_run }.to_not raise_error + end +end + +shared_examples 'default .bashrc' do + let(:bashrc_path) { '/Users/brubble/.bashrc' } + it 'installs custom .bashrc into user homedir with expected settings' do + expect(chef_run).to create_template(bashrc_path).with( + user: 'brubble', + mode: '0644' + ) + + [ "export DEBFULLNAME='#{chef_run.node['lyraphase_workstation']['bashrc']['user_fullname']}'", + "export DEBEMAIL='#{chef_run.node['lyraphase_workstation']['bashrc']['user_email']}'", + "export DEBSIGN_KEYID='#{chef_run.node['lyraphase_workstation']['bashrc']['user_gpg_keyid']}'" + ].each do |expected_regex| + expect(chef_run).to render_file(bashrc_path).with_content(Regexp.new("^\s*#{expected_regex}\s*(#.*)?$")) + end + + # Default is no / empty attributes: + # - homebrew_github_api_token + # - homebrew_no_cleanup_formulae + [ "export HOMEBREW_GITHUB_API_TOKEN='#{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token']}'", + "export HOMEBREW_GITHUB_API_TOKEN='.*?' # #{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token_comment']}", + "export HOMEBREW_NO_CLEANUP_FORMULAE=.*" + ].each do |expected_regex| + # Note: Negated with_content requires passing a Proc / Block! + # Reference: https://github.com/chefspec/chefspec/issues/865 + expect(chef_run).to(render_file(bashrc_path).with_content do |content| + expect(content).not_to match(Regexp.new("^\s*#{expected_regex}\s*(#.*)?$")) + end) + end + end +end + describe_recipe 'lyraphase_workstation::bashrc' do context 'when given all bashrc attributes' do # Override ChefSpec attributes from spec_shared_contexts @@ -46,7 +93,11 @@ } let(:bashrc_path) { '/Users/brubble/.bashrc' } - let(:bash_logout_path) { '/Users/brubble/.bash_logout' } + + # Normal stub works for describe_recipe shared context b/c it has no before blocks defined + before(:each) do + stub_data_bag_item("lyraphase_workstation", "bashrc").and_return(nil) + end it 'installs custom .bashrc into user homedir with given settings' do expect(chef_run).to create_template(bashrc_path).with( @@ -65,53 +116,18 @@ end end - it 'installs custom .bash_logout into user homedir' do - expect(chef_run).to create_template(bash_logout_path).with( - user: 'brubble', - mode: '0644' - ) - end + include_examples 'bash_logout' end context 'when given no (default) bashrc attributes' do # Use ChefSpec attributes from spec_shared_contexts - let(:bashrc_path) { '/Users/brubble/.bashrc' } - let(:bash_logout_path) { '/Users/brubble/.bash_logout' } - - it 'installs custom .bashrc into user homedir with expected settings' do - expect(chef_run).to create_template(bashrc_path).with( - user: 'brubble', - mode: '0644' - ) - - [ "export DEBFULLNAME='#{chef_run.node['lyraphase_workstation']['bashrc']['user_fullname']}'", - "export DEBEMAIL='#{chef_run.node['lyraphase_workstation']['bashrc']['user_email']}'", - "export DEBSIGN_KEYID='#{chef_run.node['lyraphase_workstation']['bashrc']['user_gpg_keyid']}'" - ].each do |expected_regex| - expect(chef_run).to render_file(bashrc_path).with_content(Regexp.new("^\s*#{expected_regex}\s*(#.*)?$")) - end - # Default is no / empty attributes: - # - homebrew_github_api_token - # - homebrew_no_cleanup_formulae - [ "export HOMEBREW_GITHUB_API_TOKEN='#{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token']}'", - "export HOMEBREW_GITHUB_API_TOKEN='.*?' # #{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token_comment']}", - "export HOMEBREW_NO_CLEANUP_FORMULAE=.*" - ].each do |expected_regex| - # Note: Negated with_content requires passing a Proc / Block! - # Reference: https://github.com/chefspec/chefspec/issues/865 - expect(chef_run).to(render_file(bashrc_path).with_content do |content| - expect(content).not_to match(Regexp.new("^\s*#{expected_regex}\s*(#.*)?$")) - end) - end + before(:each) do + stub_data_bag_item("lyraphase_workstation", "bashrc").and_return(nil) end - it 'installs custom .bash_logout into user homedir' do - expect(chef_run).to create_template(bash_logout_path).with( - user: 'brubble', - mode: '0644' - ) - end + include_examples 'default .bashrc' + include_examples 'bash_logout' end end @@ -133,28 +149,60 @@ automatic_attributes: {} } } - let(:invalid_data_bag_item) { - { id: 'bashrc', comment: 'wrong schema', - homebrew_github_api_token: "gh_#{SecureRandom.hex(20)}", - homebrew_github_api_token_comment: 'This should be under node name hash key' + + context 'when given a valid data_bag_item' do + # Override method to stub at the shared_context level + # Needed here b/c describe_recipe_with_expected_logs defines before(:each) already, + # and we need to hook into it at that top-level context + def before_each_shared_example + valid_data_bag_item = { "id": "bashrc", "fauxhai.local": { "homebrew_github_api_token": "gh_f00dcafefauxhai", "homebrew_github_api_token_comment": "This is a valid data bag item" } } + stub_data_bag_item("lyraphase_workstation", "bashrc").and_return(valid_data_bag_item) + end + + # Expect Chef::Log.info message + let(:chef_log_info_msgs) { + ["Loading Homebrew GitHub API token for Node Name: #{node['name']}"] } - } - # Expect Chef::Log.warn messages - let(:chef_log_warn_msgs) { - [ - "Could not find Homebrew GitHub API token attribute homebrew_github_api_token in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}", - "Could not find Homebrew GitHub API token attribute homebrew_github_api_token_comment in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}", - "Expected Data Bag Item Schema: {\"id\": \"bashrc\", \"#{node['name']}\": {\"homebrew_github_api_token\": \"gh_f00dcafevagrant\", \"homebrew_github_api_token_comment\": \"some optional comment\"}}" - ] - } + let(:bashrc_path) { '/Users/brubble/.bashrc' } - before(:each) do - stub_data_bag_item('lyraphase_workstation', 'bashrc').and_return(invalid_data_bag_item) + it_outputs 'Chef INFO Logs' + + it 'installs custom .bashrc into user homedir with given settings' do + expect(chef_run).to create_template(bashrc_path).with( + user: 'brubble', + mode: '0644' + ) + + [ "export HOMEBREW_GITHUB_API_TOKEN='gh_f00dcafefauxhai'", + "export HOMEBREW_GITHUB_API_TOKEN='.*?' # This is a valid data bag item" + ].each do |expected_regex| + expect(chef_run).to render_file(bashrc_path).with_content(Regexp.new("^\s*#{expected_regex}\s*(#.*)?$")) + end + end + + include_examples 'it does not raise error' + include_examples 'bash_logout' end - it_outputs 'Chef WARN Logs' + context 'when given invalid data_bag_item Schema' do + def before_each_shared_example + invalid_data_bag_item = { id: 'bashrc', comment: 'wrong schema', + homebrew_github_api_token: "gh_#{SecureRandom.hex(20)}", + homebrew_github_api_token_comment: 'This should be under node name hash key' + } + stub_data_bag_item('lyraphase_workstation', 'bashrc').and_return(invalid_data_bag_item) + end + # Expect Chef::Log.warn messages + let(:chef_log_warn_msgs) { + [ + "Could not find Homebrew GitHub API token attribute homebrew_github_api_token in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}", + "Could not find Homebrew GitHub API token attribute homebrew_github_api_token_comment in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}", + "Expected Data Bag Item Schema: {\"id\": \"bashrc\", \"#{node['name']}\": {\"homebrew_github_api_token\": \"gh_f00dcafevagrant\", \"homebrew_github_api_token_comment\": \"some optional comment\"}}" + ] + } - it 'does not raise error' do - expect { chef_run }.to_not raise_error + it_outputs 'Chef WARN Logs' + include_examples 'it does not raise error' + include_examples 'default .bashrc' end -end \ No newline at end of file +end From cc61a4c0149c1427a91be2a4d7daa6de021c8803 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 23:02:53 -0600 Subject: [PATCH 25/60] lyraphase_workstation::bashrc: Change to use per-node Encrypted Data Bag item Schema (GH per-node PATs) --- recipes/bashrc.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/recipes/bashrc.rb b/recipes/bashrc.rb index da84321..35c6ee6 100644 --- a/recipes/bashrc.rb +++ b/recipes/bashrc.rb @@ -27,16 +27,16 @@ # Gather Homebrew GitHub token from encrypted data bag homebrew_github_api_token_data = begin data_bag_item('lyraphase_workstation', 'bashrc') - rescue + rescue => e nil end homebrew_github_api_token_hash = Hash.new() ['homebrew_github_api_token', 'homebrew_github_api_token_comment'].each do |data_bag_key| - if !homebrew_github_api_token_data.nil? && homebrew_github_api_token_data.has_key?(node['name']) && homebrew_github_api_token_data.has_key?(data_bag_key) + if !homebrew_github_api_token_data.nil? && homebrew_github_api_token_data.has_key?(node['name']) && homebrew_github_api_token_data[node['name']].has_key?(data_bag_key) Chef::Log.info("Loading Homebrew GitHub API token for Node Name: #{node['name']}") homebrew_github_api_token_hash[data_bag_key] = begin - homebrew_github_api_token_data[data_bag_key] + homebrew_github_api_token_data[node['name']][data_bag_key] rescue nil end From 845b3106c1a2e6d0b3ee5a3276b50c364f7ae863 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 23:12:55 -0600 Subject: [PATCH 26/60] lyraphase_workstation::gpg21: Fix ChefSpec tests on Apple Silicon arm64 with /opt/homebrew path --- spec/unit/recipes/gpg21_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/unit/recipes/gpg21_spec.rb b/spec/unit/recipes/gpg21_spec.rb index 12245ea..ee6d82d 100644 --- a/spec/unit/recipes/gpg21_spec.rb +++ b/spec/unit/recipes/gpg21_spec.rb @@ -34,9 +34,12 @@ node.normal['lyraphase_workstation']['gpg21']['gpgtools_plist_file'] = gpgtools_plist_file_test stub_command("which git").and_return('/usr/local/bin/git') stub_command("/usr/local/bin/brew analytics state").and_return('Analytics is disabled') + stub_command("/opt/homebrew/bin/brew analytics state").and_return('Analytics is disabled') stubs_for_resource("execute[set analytics]") do |resource| allow(resource).to receive_shell_out("/usr/local/bin/brew analytics state", {:user=>"brubble"}) allow(resource).to receive_shell_out("/usr/local/bin/brew analytics state") + allow(resource).to receive_shell_out("/opt/homebrew/bin/brew analytics state", {:user=>"brubble"}) + allow(resource).to receive_shell_out("/opt/homebrew/bin/brew analytics state") end node.normal['lyraphase_workstation']['gpg21']['binary_paths'] = [] @@ -120,9 +123,12 @@ node.normal['lyraphase_workstation']['gpg21']['gpgtools_plist_file'] = gpgtools_plist_file_test stub_command("which git").and_return('/usr/local/bin/git') stub_command("/usr/local/bin/brew analytics state").and_return('Analytics is disabled') + stub_command("/opt/homebrew/bin/brew analytics state").and_return('Analytics is disabled') stubs_for_resource("execute[set analytics]") do |resource| allow(resource).to receive_shell_out("/usr/local/bin/brew analytics state", {:user=>"brubble"}) allow(resource).to receive_shell_out("/usr/local/bin/brew analytics state") + allow(resource).to receive_shell_out("/opt/homebrew/bin/brew analytics state", {:user=>"brubble"}) + allow(resource).to receive_shell_out("/opt/homebrew/bin/brew analytics state") end node.normal['lyraphase_workstation']['gpg21']['binary_paths'] = gpg_binary_paths @@ -176,9 +182,12 @@ node.normal['lyraphase_workstation']['gpg21']['gpgtools_plist_file'] = gpgtools_plist_file_test stub_command("which git").and_return('/usr/local/bin/git') stub_command("/usr/local/bin/brew analytics state").and_return('Analytics is disabled') + stub_command("/opt/homebrew/bin/brew analytics state").and_return('Analytics is disabled') stubs_for_resource("execute[set analytics]") do |resource| allow(resource).to receive_shell_out("/usr/local/bin/brew analytics state", {:user=>"brubble"}) allow(resource).to receive_shell_out("/usr/local/bin/brew analytics state") + allow(resource).to receive_shell_out("/opt/homebrew/bin/brew analytics state", {:user=>"brubble"}) + allow(resource).to receive_shell_out("/opt/homebrew/bin/brew analytics state") end node.normal['lyraphase_workstation']['gpg21']['binary_paths'] = gpg_binary_paths From ce7fad2563a7a7bf249c888adb410c9ce006ff19 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 23:26:41 -0600 Subject: [PATCH 27/60] lyraphase_workstation::bashrc: Add .bash_profile template installation --- recipes/bashrc.rb | 8 +++++ spec/unit/recipes/bashrc_spec.rb | 15 +++++++++ templates/default/bash_profile.erb | 50 ++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100755 templates/default/bash_profile.erb diff --git a/recipes/bashrc.rb b/recipes/bashrc.rb index 35c6ee6..5d5982d 100644 --- a/recipes/bashrc.rb +++ b/recipes/bashrc.rb @@ -23,6 +23,7 @@ bashrc_path = Pathname.new(File.join(node['lyraphase_workstation']['home'], '.bashrc')) bash_logout_path = Pathname.new(File.join(node['lyraphase_workstation']['home'], '.bash_logout')) +bash_profile_path = Pathname.new(File.join(node['lyraphase_workstation']['home'], '.bash_profile')) # Gather Homebrew GitHub token from encrypted data bag homebrew_github_api_token_data = begin @@ -76,3 +77,10 @@ mode '0644' # No vars needed for now end + +template bash_profile_path do + source 'bash_profile.erb' + user node['lyraphase_workstation']['user'] + mode '0644' + variables(user_home: node['lyraphase_workstation']['home']) +end \ No newline at end of file diff --git a/spec/unit/recipes/bashrc_spec.rb b/spec/unit/recipes/bashrc_spec.rb index 7dcecff..423585f 100644 --- a/spec/unit/recipes/bashrc_spec.rb +++ b/spec/unit/recipes/bashrc_spec.rb @@ -32,6 +32,19 @@ end end +shared_examples 'bash_profile' do + let(:bash_profile_path) { '/Users/brubble/.bash_profile' } + it 'installs custom .bash_profile into user homedir' do + expect(chef_run).to create_template(bash_profile_path).with( + user: 'brubble', + mode: '0644' + ) + expect(chef_run).to render_file(bash_profile_path).with_content(/^export BASH_IT="\/Users\/brubble\/.bash_it"$/) + expect(chef_run).to render_file(bash_profile_path).with_content(/^source \${HOME}\/.bashrc$/) + expect(chef_run).to render_file(bash_profile_path).with_content(/^source \$BASH_IT\/bash_it.sh$/) + end +end + shared_examples 'it does not raise error' do it 'does not raise error' do expect { chef_run }.to_not raise_error @@ -116,6 +129,7 @@ end end + include_examples 'bash_profile' include_examples 'bash_logout' end @@ -127,6 +141,7 @@ end include_examples 'default .bashrc' + include_examples 'bash_profile' include_examples 'bash_logout' end end diff --git a/templates/default/bash_profile.erb b/templates/default/bash_profile.erb new file mode 100755 index 0000000..d9c951c --- /dev/null +++ b/templates/default/bash_profile.erb @@ -0,0 +1,50 @@ +export PATH="/usr/local/bin:$PATH" + +# Path to the bash it configuration +export BASH_IT="<%= @user_home -%>/.bash_it" + +# Lock and Load a custom theme file +export BASH_IT_THEME="bobby" + +# powerline-plain # nice, but special chars could mess up tty sometimes, no timestamps +# radek # nice for python, but bright & no ruby, no timestamp +# ramses # very nice clean multiline, has python & ruby, no timestamp +# doubletime_multiline # nice clean multiline, has python & ruby + timestamp, but dimmer +# iterate # minimal unless changing directory.. also no timestamps +# luan # Bright nice multiline w/arrows, has ruby + timestamp, no python +# mairan # Nice autumn Halloween theme, has ruby & python + timestamp, and vim shell support! +# mbriggs # Red & Green Xmas theme, has ruby, no python, no timestamp +# metal # Rockin' theme, has python, no ruby, no timestamp +# minimal +# modern # Clean teal theme, has python, no ruby, no timestamp, but vim shell support! +# modern-t # same as modern, but with minimal 't' python TODO integration, breaks bash-it todo plugin +# modern-time # same as modern, no python, no ruby, but with timestamp + vim shell +# n0qorg # super-minimal blue, nothing except git scm +# newin # minimal yellow teal, nothing except git scm + timestamp +# norbu # very minimal green, python + git scm only +# nwinkler # blue green yellow, timestamp +# nwinkler_random_colors # same as above, with randomize_nwinkler function to get random colors + +## This must be done first before we load .bashrc, as PS1 will not be set appropriately otherwise +if [[ $OSTYPE = *darwin* ]] +then + ## Enable iTerm2 Shell Integration + test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash" + export BASH_SILENCE_DEPRECATION_WARNING=1 +fi + +## Always load .bashrc +source ${HOME}/.bashrc + +# Load Bash It +source $BASH_IT/bash_it.sh + +## Currently breaks bash-it: +## Error was: +## bash: trap: __bp_install: invalid signal specification +## /Users/jcuzella/.bash_it/vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh +#test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash" + +export PYENV_ROOT="$HOME/.pyenv" +command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH" +eval "$(pyenv init -)" From a81dcd912c6e2ecc2c12eb2aa23dd91a6815dc5f Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Mon, 23 May 2022 23:57:50 -0600 Subject: [PATCH 28/60] lyraphase_workstation::bashrc: Add InSpec tests for GitHub token comment & .bash_profile --- test/integration/default/bashrc_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/integration/default/bashrc_test.rb b/test/integration/default/bashrc_test.rb index 601fb90..3b58af8 100644 --- a/test/integration/default/bashrc_test.rb +++ b/test/integration/default/bashrc_test.rb @@ -26,6 +26,7 @@ bashrc_path = "/Users/#{test_kitchen_user}/.bashrc" bash_logout_path = "/Users/#{test_kitchen_user}/.bash_logout" homebrew_github_api_token = 'gh_f00dcafevagrant' +homebrew_github_api_token_comment = 'homebrew - 2022-05-23 23:56:02 -0600 - vagrant.example.com - public_repo RO' describe file(bashrc_path) do it { should exist } @@ -34,6 +35,7 @@ its('owner') { should eq test_kitchen_user } its('content') { should match Regexp.new("^\s*export HOMEBREW_GITHUB_API_TOKEN='#{homebrew_github_api_token}'") } + its('content') { should match Regexp.new("^\s*export HOMEBREW_GITHUB_API_TOKEN='.*?' # #{homebrew_github_api_token_comment}") } its('content') { should match /^\s*export DEBFULLNAME='vagrant'$/ } its('content') { should match /^\s*export DEBEMAIL='vagrant@vagrant.com'$/ } its('content') { should match /^\s*export DEBSIGN_KEYID='0xBADC0DE00FEED000'$/ } @@ -46,3 +48,14 @@ its('owner') { should eq test_kitchen_user } its('mode') { should cmp '0644' } end + +describe file(bash_profile_path) do + it { should exist } + it { should be_file } + its('owner') { should eq test_kitchen_user } + its('mode') { should cmp '0644' } + + its('content') { should match /^export BASH_IT="\/Users\/brubble\/.bash_it"$/ } + its('content') { should match /^source \${HOME}\/.bashrc$/ } + its('content') { should match /^source \$BASH_IT\/bash_it.sh$/ } +end \ No newline at end of file From 5fe2a58a1574484787639b4643c08bc30963b7c0 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Tue, 24 May 2022 00:53:36 -0600 Subject: [PATCH 29/60] lyraphase_workstation::bashrc: Update test fixture Encrypted Data Bag & fix InSpec tests --- recipes/bashrc.rb | 5 +++-- .../data_bags/lyraphase_workstation/bashrc.json | 10 +++++----- test/integration/default/bashrc_test.rb | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/recipes/bashrc.rb b/recipes/bashrc.rb index 5d5982d..cfef559 100644 --- a/recipes/bashrc.rb +++ b/recipes/bashrc.rb @@ -28,13 +28,14 @@ # Gather Homebrew GitHub token from encrypted data bag homebrew_github_api_token_data = begin data_bag_item('lyraphase_workstation', 'bashrc') - rescue => e + rescue nil end +loaded_data = !homebrew_github_api_token_data.nil? ? homebrew_github_api_token_data.to_hash : Hash.new() homebrew_github_api_token_hash = Hash.new() ['homebrew_github_api_token', 'homebrew_github_api_token_comment'].each do |data_bag_key| - if !homebrew_github_api_token_data.nil? && homebrew_github_api_token_data.has_key?(node['name']) && homebrew_github_api_token_data[node['name']].has_key?(data_bag_key) + if !homebrew_github_api_token_data.nil? && loaded_data.has_key?(node['name']) && loaded_data[node['name']].has_key?(data_bag_key) Chef::Log.info("Loading Homebrew GitHub API token for Node Name: #{node['name']}") homebrew_github_api_token_hash[data_bag_key] = begin homebrew_github_api_token_data[node['name']][data_bag_key] diff --git a/test/fixtures/data_bags/lyraphase_workstation/bashrc.json b/test/fixtures/data_bags/lyraphase_workstation/bashrc.json index 7eb432e..f0c052b 100644 --- a/test/fixtures/data_bags/lyraphase_workstation/bashrc.json +++ b/test/fixtures/data_bags/lyraphase_workstation/bashrc.json @@ -1,10 +1,10 @@ { "id": "bashrc", - "homebrew_github_api_token": { - "encrypted_data": "G7B4aiL6U+BK5pGe27kA8M/Ndsw5QiS2cSzxypHYTMzvYsxgXw==\n", - "iv": "VocLxRLb9PrqK/nE\n", - "auth_tag": "1A8JfCMmcOwsAiUK34jaUw==\n", + "default-macos-121": { + "encrypted_data": "ipkLDYhRMPGfq7qvx7mKfXn1EYtJvp2spJC2GGdmutCJ1Ks9pBt3ucNwJ3Zs\nK89x+V+RcxGVUFQ/F6m66VUGDDwaNOpUxERMSPf+wTFjcx4wLnyAe6q+Ptzh\n687KelQZvJPjDkK4hcyRr/Th5Zcoj6oo+MRSAd+q5abqRAEYXw+KvwZTSJKH\nom2qlpm4ApFMuixHvxaQFPO+o3C3Tx/ATK0B5Lzgs6cRvGMt27WBy2LAie+A\nrQ==\n", + "iv": "SKMYSZn48/qNrZpC\n", + "auth_tag": "AgJyQRxU11P2dglGaATXww==\n", "version": 3, "cipher": "aes-256-gcm" } -} +} \ No newline at end of file diff --git a/test/integration/default/bashrc_test.rb b/test/integration/default/bashrc_test.rb index 3b58af8..73f5082 100644 --- a/test/integration/default/bashrc_test.rb +++ b/test/integration/default/bashrc_test.rb @@ -25,6 +25,7 @@ test_kitchen_user = input('test_kitchen_user', value: 'kitchen') bashrc_path = "/Users/#{test_kitchen_user}/.bashrc" bash_logout_path = "/Users/#{test_kitchen_user}/.bash_logout" +bash_profile_path = "/Users/#{test_kitchen_user}/.bash_profile" homebrew_github_api_token = 'gh_f00dcafevagrant' homebrew_github_api_token_comment = 'homebrew - 2022-05-23 23:56:02 -0600 - vagrant.example.com - public_repo RO' @@ -55,7 +56,7 @@ its('owner') { should eq test_kitchen_user } its('mode') { should cmp '0644' } - its('content') { should match /^export BASH_IT="\/Users\/brubble\/.bash_it"$/ } + its('content') { should match Regexp.new("^export BASH_IT=\"\/Users\/#{test_kitchen_user}\/.bash_it\"$") } its('content') { should match /^source \${HOME}\/.bashrc$/ } its('content') { should match /^source \$BASH_IT\/bash_it.sh$/ } end \ No newline at end of file From 97774d9cb39b082d14c105743d83801f5cc0a94c Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Tue, 24 May 2022 01:39:26 -0600 Subject: [PATCH 30/60] Run end-of-file-fixer on files --- .vscode/extensions.json | 2 +- .vscode/lyraphase_workstation.code-workspace | 2 +- recipes/bashrc.rb | 2 +- test/fixtures/data_bags/lyraphase_workstation/bashrc.json | 2 +- test/integration/default/bashrc_test.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 7f1fc95..c57987b 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -2,4 +2,4 @@ "recommendations": [ "chef-software.Chef" ] -} \ No newline at end of file +} diff --git a/.vscode/lyraphase_workstation.code-workspace b/.vscode/lyraphase_workstation.code-workspace index bab1b7f..64bfb87 100644 --- a/.vscode/lyraphase_workstation.code-workspace +++ b/.vscode/lyraphase_workstation.code-workspace @@ -5,4 +5,4 @@ } ], "settings": {} -} \ No newline at end of file +} diff --git a/recipes/bashrc.rb b/recipes/bashrc.rb index cfef559..f88001c 100644 --- a/recipes/bashrc.rb +++ b/recipes/bashrc.rb @@ -84,4 +84,4 @@ user node['lyraphase_workstation']['user'] mode '0644' variables(user_home: node['lyraphase_workstation']['home']) -end \ No newline at end of file +end diff --git a/test/fixtures/data_bags/lyraphase_workstation/bashrc.json b/test/fixtures/data_bags/lyraphase_workstation/bashrc.json index f0c052b..94d92d7 100644 --- a/test/fixtures/data_bags/lyraphase_workstation/bashrc.json +++ b/test/fixtures/data_bags/lyraphase_workstation/bashrc.json @@ -7,4 +7,4 @@ "version": 3, "cipher": "aes-256-gcm" } -} \ No newline at end of file +} diff --git a/test/integration/default/bashrc_test.rb b/test/integration/default/bashrc_test.rb index 73f5082..a8fac25 100644 --- a/test/integration/default/bashrc_test.rb +++ b/test/integration/default/bashrc_test.rb @@ -59,4 +59,4 @@ its('content') { should match Regexp.new("^export BASH_IT=\"\/Users\/#{test_kitchen_user}\/.bash_it\"$") } its('content') { should match /^source \${HOME}\/.bashrc$/ } its('content') { should match /^source \$BASH_IT\/bash_it.sh$/ } -end \ No newline at end of file +end From 3a521e28feb868ebbe2918b7413a036cba9577df Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Tue, 24 May 2022 01:46:10 -0600 Subject: [PATCH 31/60] ci: Fix integration_result check for "failure" --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c17f1f5..14feb0a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,7 +75,7 @@ jobs: job_status=$(curl -X GET -s --header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs | jq ".jobs[] | {job_status: .conclusion, matrix: .name}") echo echo ::set-env JOB_STATUS=$job_status - name: Set matrix job status - if: contains(env.JOB_STATUS, 'failed') + if: contains(env.JOB_STATUS, 'failure') run: | echo 'One or more integration matrix jobs failed!' exit 1 From 1f33035e16642986e6bae871cac61267d57e38fb Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Tue, 24 May 2022 01:49:32 -0600 Subject: [PATCH 32/60] ci: Try to fix JOB_STATUS env var passing --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 14feb0a..b0ff46f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,7 +73,7 @@ jobs: - name: check the jobs # get the matrix job status and combination info run: | job_status=$(curl -X GET -s --header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs | jq ".jobs[] | {job_status: .conclusion, matrix: .name}") - echo echo ::set-env JOB_STATUS=$job_status + echo JOB_STATUS=$job_status | tee $GITHUB_ENV - name: Set matrix job status if: contains(env.JOB_STATUS, 'failure') run: | From 13b86c6edd0448dcd57f557bad9445f1acd58ee3 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Tue, 24 May 2022 02:00:42 -0600 Subject: [PATCH 33/60] ci: Filter only integration jobs for integration_result --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b0ff46f..e3de050 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,7 +72,7 @@ jobs: steps: - name: check the jobs # get the matrix job status and combination info run: | - job_status=$(curl -X GET -s --header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs | jq ".jobs[] | {job_status: .conclusion, matrix: .name}") + job_status=$(curl -X GET -s --header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs | jq ".jobs[] | {job_status: .conclusion, matrix: .name} | select( .matrix | contains(\"integration\")) | select( .job_status | contains(\"failure\"))") echo JOB_STATUS=$job_status | tee $GITHUB_ENV - name: Set matrix job status if: contains(env.JOB_STATUS, 'failure') From 424c2be13b9dc219b49d08602d70ca56a1600f15 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Tue, 24 May 2022 02:04:49 -0600 Subject: [PATCH 34/60] ci: Avoid checking failure status on null set --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3de050..bcd080f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,7 +72,7 @@ jobs: steps: - name: check the jobs # get the matrix job status and combination info run: | - job_status=$(curl -X GET -s --header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs | jq ".jobs[] | {job_status: .conclusion, matrix: .name} | select( .matrix | contains(\"integration\")) | select( .job_status | contains(\"failure\"))") + job_status=$(curl -X GET -s --header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/jobs | jq ".jobs[] | {job_status: .conclusion, matrix: .name} | select( .matrix | contains(\"integration\"))") echo JOB_STATUS=$job_status | tee $GITHUB_ENV - name: Set matrix job status if: contains(env.JOB_STATUS, 'failure') From 415f2fa53ec30071f5876c8e7be26cff112709e1 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Tue, 24 May 2022 02:17:45 -0600 Subject: [PATCH 35/60] lyraphase_workstation::bashrc: FC039: Node method cannot be accessed with key Foodcritic warnings were: Starting Foodcritic linting... Checking 118 files ......................................................x............................................................... /home/runner/work/lyraphase_workstation/lyraphase_workstation/recipes/bashrc.rb FC039: Node method cannot be accessed with key 35|loaded_data = !homebrew_github_api_token_data.nil? ? homebrew_github_api_token_data.to_hash : Hash.new() 36|homebrew_github_api_token_hash = Hash.new() 37|['homebrew_github_api_token', 'homebrew_github_api_token_comment'].each do |data_bag_key| 38| if !homebrew_github_api_token_data.nil? && loaded_data.has_key?(node['name']) && loaded_data[node['name']].has_key?(data_bag_key) FC039: Node method cannot be accessed with key 39| Chef::Log.info("Loading Homebrew GitHub API token for Node Name: #{node['name']}") 40| homebrew_github_api_token_hash[data_bag_key] = begin FC039: Node method cannot be accessed with key 41| homebrew_github_api_token_data[node['name']][data_bag_key] 42| rescue 43| nil 44| end FC039: Node method cannot be accessed with key 49| end 50| 51| if homebrew_github_api_token_hash[data_bag_key].nil? && !homebrew_github_api_token_data.nil? 52| Chef::Log.warn("Could not find Homebrew GitHub API token attribute #{data_bag_key} in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}") FC039: Node method cannot be accessed with key 53| Chef::Log.warn("Expected Data Bag Item Schema: {\"id\": \"bashrc\", \"#{node['name']}\": {\"homebrew_github_api_token\": \"gh_f00dcafevagrant\", \"homebrew_github_api_token_comment\": \"some optional comment\"}}") 54| end 55|end 56| --- recipes/bashrc.rb | 10 +++++----- spec/unit/recipes/bashrc_spec.rb | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/recipes/bashrc.rb b/recipes/bashrc.rb index f88001c..f479e83 100644 --- a/recipes/bashrc.rb +++ b/recipes/bashrc.rb @@ -35,10 +35,10 @@ loaded_data = !homebrew_github_api_token_data.nil? ? homebrew_github_api_token_data.to_hash : Hash.new() homebrew_github_api_token_hash = Hash.new() ['homebrew_github_api_token', 'homebrew_github_api_token_comment'].each do |data_bag_key| - if !homebrew_github_api_token_data.nil? && loaded_data.has_key?(node['name']) && loaded_data[node['name']].has_key?(data_bag_key) - Chef::Log.info("Loading Homebrew GitHub API token for Node Name: #{node['name']}") + if !homebrew_github_api_token_data.nil? && loaded_data.has_key?(node.name) && loaded_data[node.name].has_key?(data_bag_key) + Chef::Log.info("Loading Homebrew GitHub API token for Node Name: #{node.name}") homebrew_github_api_token_hash[data_bag_key] = begin - homebrew_github_api_token_data[node['name']][data_bag_key] + homebrew_github_api_token_data[node.name][data_bag_key] rescue nil end @@ -49,8 +49,8 @@ end if homebrew_github_api_token_hash[data_bag_key].nil? && !homebrew_github_api_token_data.nil? - Chef::Log.warn("Could not find Homebrew GitHub API token attribute #{data_bag_key} in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}") - Chef::Log.warn("Expected Data Bag Item Schema: {\"id\": \"bashrc\", \"#{node['name']}\": {\"homebrew_github_api_token\": \"gh_f00dcafevagrant\", \"homebrew_github_api_token_comment\": \"some optional comment\"}}") + Chef::Log.warn("Could not find Homebrew GitHub API token attribute #{data_bag_key} in data bag item lyraphase_workstation:bashrc for Node Name: #{node.name}") + Chef::Log.warn("Expected Data Bag Item Schema: {\"id\": \"bashrc\", \"#{node.name}\": {\"homebrew_github_api_token\": \"gh_f00dcafevagrant\", \"homebrew_github_api_token_comment\": \"some optional comment\"}}") end end diff --git a/spec/unit/recipes/bashrc_spec.rb b/spec/unit/recipes/bashrc_spec.rb index 423585f..339e5d0 100644 --- a/spec/unit/recipes/bashrc_spec.rb +++ b/spec/unit/recipes/bashrc_spec.rb @@ -176,7 +176,7 @@ def before_each_shared_example # Expect Chef::Log.info message let(:chef_log_info_msgs) { - ["Loading Homebrew GitHub API token for Node Name: #{node['name']}"] + ["Loading Homebrew GitHub API token for Node Name: #{node.name}"] } let(:bashrc_path) { '/Users/brubble/.bashrc' } @@ -210,9 +210,9 @@ def before_each_shared_example # Expect Chef::Log.warn messages let(:chef_log_warn_msgs) { [ - "Could not find Homebrew GitHub API token attribute homebrew_github_api_token in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}", - "Could not find Homebrew GitHub API token attribute homebrew_github_api_token_comment in data bag item lyraphase_workstation:bashrc for Node Name: #{node['name']}", - "Expected Data Bag Item Schema: {\"id\": \"bashrc\", \"#{node['name']}\": {\"homebrew_github_api_token\": \"gh_f00dcafevagrant\", \"homebrew_github_api_token_comment\": \"some optional comment\"}}" + "Could not find Homebrew GitHub API token attribute homebrew_github_api_token in data bag item lyraphase_workstation:bashrc for Node Name: #{node.name}", + "Could not find Homebrew GitHub API token attribute homebrew_github_api_token_comment in data bag item lyraphase_workstation:bashrc for Node Name: #{node.name}", + "Expected Data Bag Item Schema: {\"id\": \"bashrc\", \"#{node.name}\": {\"homebrew_github_api_token\": \"gh_f00dcafevagrant\", \"homebrew_github_api_token_comment\": \"some optional comment\"}}" ] } From 5d52a96a2b31b1896f9bd2339cf001d7de32c9dd Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Tue, 24 May 2022 02:32:35 -0600 Subject: [PATCH 36/60] lyraphase_workstation::bashrc: Sanitize UTC Timezone plus chars in ChefSpec (was breaking Regexp) --- spec/unit/recipes/bashrc_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/recipes/bashrc_spec.rb b/spec/unit/recipes/bashrc_spec.rb index 339e5d0..d6568dc 100644 --- a/spec/unit/recipes/bashrc_spec.rb +++ b/spec/unit/recipes/bashrc_spec.rb @@ -70,7 +70,7 @@ # - homebrew_github_api_token # - homebrew_no_cleanup_formulae [ "export HOMEBREW_GITHUB_API_TOKEN='#{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token']}'", - "export HOMEBREW_GITHUB_API_TOKEN='.*?' # #{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token_comment']}", + "export HOMEBREW_GITHUB_API_TOKEN='.*?' # #{Regexp.escape(chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token_comment'].to_s)}", "export HOMEBREW_NO_CLEANUP_FORMULAE=.*" ].each do |expected_regex| # Note: Negated with_content requires passing a Proc / Block! From b356817b0afac7fc6638076173c0e7fdfaf6f3f6 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Tue, 24 May 2022 02:40:03 -0600 Subject: [PATCH 37/60] lyraphase_workstation::bashrc: Sanitize UTC Timezone chars in another spot --- spec/unit/recipes/bashrc_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/unit/recipes/bashrc_spec.rb b/spec/unit/recipes/bashrc_spec.rb index d6568dc..f8475e7 100644 --- a/spec/unit/recipes/bashrc_spec.rb +++ b/spec/unit/recipes/bashrc_spec.rb @@ -93,7 +93,7 @@ normal_attributes: { 'lyraphase_workstation': { 'bashrc': { 'homebrew_github_api_token': "gh_#{SecureRandom.hex(20)}", - 'homebrew_github_api_token_comment': "rotgut butanol - #{DateTime.now.strftime('%Y-%m-%d %H:%M:%S %z')} - lyra.37om.com - public_repo RO", + 'homebrew_github_api_token_comment': "rotgut butanol - (#{DateTime.now.strftime('%Y-%m-%d %H:%M:%S %z')}) - lyra.37om.com - public_repo RO", 'user_fullname': 'Barney Rubble', 'user_email': 'barney.rubble@lyraphase.com', 'user_gpg_keyid': "0x#{SecureRandom.hex(8)}", @@ -119,7 +119,7 @@ ) [ "export HOMEBREW_GITHUB_API_TOKEN='#{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token']}'", - "export HOMEBREW_GITHUB_API_TOKEN='.*?' # #{chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token_comment']}", + "export HOMEBREW_GITHUB_API_TOKEN='.*?' # #{Regexp.escape(chef_run.node['lyraphase_workstation']['bashrc']['homebrew_github_api_token_comment'].to_s)}", "export DEBFULLNAME='#{chef_run.node['lyraphase_workstation']['bashrc']['user_fullname']}'", "export DEBEMAIL='#{chef_run.node['lyraphase_workstation']['bashrc']['user_email']}'", "export DEBSIGN_KEYID='#{chef_run.node['lyraphase_workstation']['bashrc']['user_gpg_keyid']}'", From be5db927ef5a6d15ebf21223c08880b6a32de126 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Tue, 24 May 2022 03:01:58 -0600 Subject: [PATCH 38/60] ci: Fix lyraphase_workstation::bashrc data bag for GitHub Actions default-macos-12 node name --- .../data_bags/lyraphase_workstation/bashrc.json | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/test/fixtures/data_bags/lyraphase_workstation/bashrc.json b/test/fixtures/data_bags/lyraphase_workstation/bashrc.json index 94d92d7..0ef36fb 100644 --- a/test/fixtures/data_bags/lyraphase_workstation/bashrc.json +++ b/test/fixtures/data_bags/lyraphase_workstation/bashrc.json @@ -1,10 +1,17 @@ { "id": "bashrc", "default-macos-121": { - "encrypted_data": "ipkLDYhRMPGfq7qvx7mKfXn1EYtJvp2spJC2GGdmutCJ1Ks9pBt3ucNwJ3Zs\nK89x+V+RcxGVUFQ/F6m66VUGDDwaNOpUxERMSPf+wTFjcx4wLnyAe6q+Ptzh\n687KelQZvJPjDkK4hcyRr/Th5Zcoj6oo+MRSAd+q5abqRAEYXw+KvwZTSJKH\nom2qlpm4ApFMuixHvxaQFPO+o3C3Tx/ATK0B5Lzgs6cRvGMt27WBy2LAie+A\nrQ==\n", - "iv": "SKMYSZn48/qNrZpC\n", - "auth_tag": "AgJyQRxU11P2dglGaATXww==\n", + "encrypted_data": "14mvD4foM6IDEFYa3Q6w+/PMp40FepzvCSb2agNMyR3Shp7oTzQqSfqM4Uvs\nGRpHnjRkyZm2kSlNddgbj0/QATZ1ORt/LgHf7jj8538gUeSygKIOaPtCqx03\niCh6FTvISIqPerxndW3OKS5GTgqwc0l8AyWeU2mpwBfMCILubRx0pgQ+c/TS\n5Z6lI59qUva+ooa9D+2uUpcw5kWF0xIAPr7133WB4WJb7mX6bdWUrwQGOVJV\nsg==\n", + "iv": "ppQ9AA1dnyJWPiji\n", + "auth_tag": "AZ31tTTLOjYAv3kSGpjVug==\n", + "version": 3, + "cipher": "aes-256-gcm" + }, + "default-macos-12": { + "encrypted_data": "mWMv2DnywIZdQsQexxkzLpArcfK/Tksd/ceWnY7eKGQugatitDmIXqc9YR1p\nsdqAGq+Cso2Xsvnfpmmr80i5aA1WTuHxsf2kO4CoXbyHUgW3C8/LwWok26P8\n4q0oZwTyBq2Bj1cvpcrqjLicCS4zST+ZUNYOKX7QavMKLEDB9gYC7Np3SSne\nf5f7RMAxAFTxz3nQV5KFiPIyKPP6Ay0a/vywAaIVSw/UlVs0rZ7bamqQp0RS\n+w==\n", + "iv": "mGLSxmWSK7K7QIFC\n", + "auth_tag": "OR9li+6s7vqHxetM1nknVQ==\n", "version": 3, "cipher": "aes-256-gcm" } -} +} \ No newline at end of file From 82e219d960c21c99ac43000854d80efc1a24c5d9 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Tue, 24 May 2022 03:02:36 -0600 Subject: [PATCH 39/60] Run end-of-file-fixer on encrypted data bag file --- test/fixtures/data_bags/lyraphase_workstation/bashrc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixtures/data_bags/lyraphase_workstation/bashrc.json b/test/fixtures/data_bags/lyraphase_workstation/bashrc.json index 0ef36fb..bc7926f 100644 --- a/test/fixtures/data_bags/lyraphase_workstation/bashrc.json +++ b/test/fixtures/data_bags/lyraphase_workstation/bashrc.json @@ -14,4 +14,4 @@ "version": 3, "cipher": "aes-256-gcm" } -} \ No newline at end of file +} From ea1fb3f5fac3d978d73764f73cb5644a227f390c Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Tue, 24 May 2022 03:17:19 -0600 Subject: [PATCH 40/60] ci: Fix lyraphase_workstation::bashrc data bag for GitHub Actions default-macos-11 node name --- .../lyraphase_workstation/bashrc.json | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/test/fixtures/data_bags/lyraphase_workstation/bashrc.json b/test/fixtures/data_bags/lyraphase_workstation/bashrc.json index bc7926f..2c9983d 100644 --- a/test/fixtures/data_bags/lyraphase_workstation/bashrc.json +++ b/test/fixtures/data_bags/lyraphase_workstation/bashrc.json @@ -1,16 +1,23 @@ { "id": "bashrc", "default-macos-121": { - "encrypted_data": "14mvD4foM6IDEFYa3Q6w+/PMp40FepzvCSb2agNMyR3Shp7oTzQqSfqM4Uvs\nGRpHnjRkyZm2kSlNddgbj0/QATZ1ORt/LgHf7jj8538gUeSygKIOaPtCqx03\niCh6FTvISIqPerxndW3OKS5GTgqwc0l8AyWeU2mpwBfMCILubRx0pgQ+c/TS\n5Z6lI59qUva+ooa9D+2uUpcw5kWF0xIAPr7133WB4WJb7mX6bdWUrwQGOVJV\nsg==\n", - "iv": "ppQ9AA1dnyJWPiji\n", - "auth_tag": "AZ31tTTLOjYAv3kSGpjVug==\n", + "encrypted_data": "vZJHK/onhK6LTo1c/Ue3zNOEi14GNgad5tBynP2DQES5ZcQAm/3tVLTyR+wZ\ntkZAm8B8jgDpKi7uUqluYt+I3eiFy8xnmoS8pUBy/tW0hUKzhakbTxSKAxbM\nZQK9ckNfYlHc52l4ZuBbU8+hD07efhn4xJGa/YGp7KwXReFQ/se3gozfmm1u\nEm9Hs4PSb4/ajCRmG48uTCtg7NVRFuXykYzLUIzRcZIgoUgJ49kjw5NMSrBp\npw==\n", + "iv": "QmULPHF22+9EpE0p\n", + "auth_tag": "+/HhF03lghtRJR6jIelmvQ==\n", "version": 3, "cipher": "aes-256-gcm" }, "default-macos-12": { - "encrypted_data": "mWMv2DnywIZdQsQexxkzLpArcfK/Tksd/ceWnY7eKGQugatitDmIXqc9YR1p\nsdqAGq+Cso2Xsvnfpmmr80i5aA1WTuHxsf2kO4CoXbyHUgW3C8/LwWok26P8\n4q0oZwTyBq2Bj1cvpcrqjLicCS4zST+ZUNYOKX7QavMKLEDB9gYC7Np3SSne\nf5f7RMAxAFTxz3nQV5KFiPIyKPP6Ay0a/vywAaIVSw/UlVs0rZ7bamqQp0RS\n+w==\n", - "iv": "mGLSxmWSK7K7QIFC\n", - "auth_tag": "OR9li+6s7vqHxetM1nknVQ==\n", + "encrypted_data": "SDduVmGIthqhkLwH0fgKYos0+WTWvNv8PosuTkR0C7ohpH/g0x2spbiJWLA3\n15uBodQsMArAIiUiJ/+SIhdIH0poWFXNe/CgK4skx4XA6WC+ptZpcX5Zy1vx\n2IL/IrunQEKAqXMtBt072h1lxyPLBKWUakW+KJfsd/qNZDfM3p63RogvutD+\nCxKu5wulqUC/74Z7SP7G+aEbZrkwcjZ9J1tqKRwDVFOjYL1P5Zx2cH/5ULvV\n1w==\n", + "iv": "Lw4BrFUU0TlnHwYS\n", + "auth_tag": "QeElLJ16XYob+2D6kId59Q==\n", + "version": 3, + "cipher": "aes-256-gcm" + }, + "default-macos-11": { + "encrypted_data": "6K1t/EaRrkKGjdMxeSDH0xz4Q3A4M7MXXR7KuHelhvVNNbJ5V0/iIaotj3Ep\n8H8McWWO7VOC0y8NVq3ZyYpsmvQvB84bwaHEfekmTj7TDGW66TWsPUZymrqQ\nAgTnzd8pwwHfwyPDhNZZynpcjO+oPMCbJzxf2VTLEbWuyCE4MxmsC3cICSrW\niwcv8PRJSdPAneOT4yjscE+2VhKAGDwUMx3d/cJJDiuXEtD3QE0EMHz+uVUL\nQQ==\n", + "iv": "j5xzvsb4INBM0cuO\n", + "auth_tag": "5Lh1RiE5qipxZ5D4UfqFnA==\n", "version": 3, "cipher": "aes-256-gcm" } From 9d9a54008d2b212c362233b41e9693ad9135fbdf Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Tue, 24 May 2022 03:13:16 -0600 Subject: [PATCH 41/60] lyraphase_workstation::bashrc: Set default HOMEBREW_CASK_OPTS="--no-quarantine" --- templates/default/bashrc.erb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/templates/default/bashrc.erb b/templates/default/bashrc.erb index c351583..bd78fa1 100644 --- a/templates/default/bashrc.erb +++ b/templates/default/bashrc.erb @@ -184,6 +184,9 @@ then # Keep old versions for specific formulae export HOMEBREW_NO_CLEANUP_FORMULAE=<%= @homebrew_no_cleanup_formulae.join(',') %> <% end %> + # Remove the com.apple.quarantine extended file attribute for installed Casks + export HOMEBREW_CASK_OPTS="--no-quarantine" + # Alias defunkt/hub as git eval "$(hub alias -s)" From 0909ea11e4218e8955b5a352664ee09a427e5d22 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Wed, 25 May 2022 20:55:13 -0600 Subject: [PATCH 42/60] lyraphase_workstation::ableton_live: Upgrade Ableton 11.1.5 Suite (Universal installer for M1 & Intel Mac support!) --- attributes/ableton_live.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/attributes/ableton_live.rb b/attributes/ableton_live.rb index b7d0aad..9723bd0 100644 --- a/attributes/ableton_live.rb +++ b/attributes/ableton_live.rb @@ -1,8 +1,8 @@ default['lyraphase_workstation']['ableton_live'] = {} default['lyraphase_workstation']['ableton_live']['dmg'] = {} -default['lyraphase_workstation']['ableton_live']['dmg']['source'] = 'http://www.lyraphase.com/doc/installers/mac/ableton_live_suite_10.0.1_64.dmg' -default['lyraphase_workstation']['ableton_live']['dmg']['checksum'] = '73f8b7d9c2e058639466cbb765e6e1610f97f542745e2c69567d7bf55a407e11' -default['lyraphase_workstation']['ableton_live']['dmg']['volumes_dir'] = 'Ableton Live 10 Suite Installer' -default['lyraphase_workstation']['ableton_live']['dmg']['dmg_name'] = 'ableton_live_suite_10.0.1_64' -default['lyraphase_workstation']['ableton_live']['dmg']['app'] = 'Ableton Live 10 Suite' +default['lyraphase_workstation']['ableton_live']['dmg']['source'] = 'http://www.lyraphase.com/doc/installers/mac/ableton_live_suite_11.1.5_universal.dmg' +default['lyraphase_workstation']['ableton_live']['dmg']['checksum'] = 'bbce5e7a5c5632f88fb319df2daaf7ba1b9b0a1af0e94f60ee21d9dd059bf1a7' +default['lyraphase_workstation']['ableton_live']['dmg']['volumes_dir'] = 'Ableton Live 11 Suite Installer' +default['lyraphase_workstation']['ableton_live']['dmg']['dmg_name'] = 'ableton_live_suite_11.1.5_universal' +default['lyraphase_workstation']['ableton_live']['dmg']['app'] = 'Ableton Live 11 Suite' default['lyraphase_workstation']['ableton_live']['dmg']['type'] = 'app' From cd05f01d7e364dc938c130999a9b047462757c9e Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Wed, 25 May 2022 20:58:39 -0600 Subject: [PATCH 43/60] lyraphase_workstation::ableton_live: Update InSpec tests to check for Ableton 11 Suite --- test/integration/default/ableton_live_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/default/ableton_live_test.rb b/test/integration/default/ableton_live_test.rb index a61ade6..b2582cc 100644 --- a/test/integration/default/ableton_live_test.rb +++ b/test/integration/default/ableton_live_test.rb @@ -22,13 +22,13 @@ # InSpec test for recipe lyraphase_workstation::ableton_live -app = 'Ableton Live 10 Suite.app' +app = 'Ableton Live 11 Suite.app' app_bundle_id_regex = /^com\.ableton\.live/ test_kitchen_user = input('test_kitchen_user', value: 'kitchen') applications_path = '/Applications' app_path = File.join(applications_path, app) -get_bundle_id_cmd = "sudo su -m #{test_kitchen_user} -c 'osascript -e '\\''id of app \"Ableton Live 10 Suite.app\"'\\'''" +get_bundle_id_cmd = "sudo su -m #{test_kitchen_user} -c 'osascript -e '\\''id of app \"Ableton Live 11 Suite.app\"'\\'''" describe file(app_path) do it { should exist } From 4e6d4773e9da1d445019a4af4c28a75d1cbb70c8 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Wed, 25 May 2022 21:35:32 -0600 Subject: [PATCH 44/60] lyraphase_workstation::ableton_live: Update Test Kitchen Attributes for Ableton Live 11 Suite --- .kitchen.libvirt.ssh.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.kitchen.libvirt.ssh.yml b/.kitchen.libvirt.ssh.yml index 891fbcf..8e03ade 100644 --- a/.kitchen.libvirt.ssh.yml +++ b/.kitchen.libvirt.ssh.yml @@ -87,9 +87,17 @@ platforms: customize: memory: 4096 # cpus: 2 + attributes: + lyraphase_workstation: + ableton_live: + dmg: + source: http://saturn.local:8888/mac/ableton_live_suite_11.1.5_universal.dmg + bitfocus_companion: + dmg: + source: http://saturn.local:8888/mac/bitfocus-companion-2.2.0-ccea40c7-mac-x64.dmg -#suites: -# - name: default +# suites: +# - name: default # run_list: # - recipe[sprout-base::default] # includes: [ubuntu-20.04, macos-latest] From 10c32ede69a5d218f24a29a7669f9fbd0902d4fe Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Wed, 25 May 2022 21:36:28 -0600 Subject: [PATCH 45/60] .kitchen.libvirt.ssh.yml: Use local Docker webserver to host installers instead of rsync synced_folders --- .kitchen.libvirt.ssh.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.kitchen.libvirt.ssh.yml b/.kitchen.libvirt.ssh.yml index 8e03ade..b569fa5 100644 --- a/.kitchen.libvirt.ssh.yml +++ b/.kitchen.libvirt.ssh.yml @@ -21,8 +21,8 @@ driver: provider: libvirt vagrantfiles: - 'test/fixtures/Vagrantfile.libvirt-ssh' - synced_folders: - - [".", "/tmp/kitchen/soloist", "disabled: false, type: 'rsync'"] + #synced_folders: + # - [".", "/tmp/kitchen/soloist", "disabled: false, type: 'rsync'"] # TODO: Find & fix bugs in Vagrant where it checks for vagrant-host path... needs to support remote NFS & 9p libvirt mounts # TODO: Fix mount: false setting for 9p # TODO: Fix auto-mount capability for Darwin / macOS... needs mount_9p support (see man mount_9p) @@ -77,8 +77,11 @@ platforms: - name: macos-12.1 lifecycle: pre_converge: + - local: ssh saturn.local '[[ "$(docker ps -q --filter 'name=kitchen-installer-server-macos-12.1' | wc -l)" == '1' ]] || docker run --name=kitchen-installer-server-macos-12.1 --rm -d -v /media/terabyte/installers/:/var/www:ro -p 8888:8080 trinitronx/python-simplehttpserver' - remote: sudo mkdir -p /tmp/kitchen - remote: sudo chown -R vagrant:vagrant /tmp/kitchen + post_converge: + - local: ssh saturn.local '[ $(docker ps -aq --filter 'name=kitchen-installer-server-macos-12.1' | wc -l) -ge 1 ] && docker kill kitchen-installer-server-macos-12.1' driver: box: lyraphase-runner/macos-monterey-base box_url: http://saturn.local:8888/lyraphase-runner-macos-monterey-base.box From a5c608ddd1e0f3233c9f091942e8f8652fb73ab7 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Wed, 25 May 2022 21:37:47 -0600 Subject: [PATCH 46/60] .kitchen.yml: Add ableton_live_options to run_list, Add attributes for testing the recipe in Test Kitchen --- .kitchen.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.kitchen.yml b/.kitchen.yml index 633e8d8..37959ef 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -19,10 +19,19 @@ suites: - name: default run_list: - recipe[lyraphase_workstation::ableton_live] + - recipe[lyraphase_workstation::ableton_live_options] - recipe[lyraphase_workstation::bashrc] - recipe[lyraphase_workstation::bitfocus_companion] attributes: lyraphase_workstation: + ableton_live: + managed_versions: + - 10.0.1 + - 10.1.35 + options: + - EnableMapToSiblings + - AutoAdjustMacroMappingRange + - _PluginAutoPopulateThreshold=-1 bashrc: user_fullname: 'vagrant' user_email: 'vagrant@vagrant.com' From 027fcb7ea4212f48fffc51a7030a0467d815c06f Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Wed, 25 May 2022 21:39:03 -0600 Subject: [PATCH 47/60] lyraphase_workstation::ableton_live_options: Add ChefSpec test for Ableton Preferences directory --- spec/unit/recipes/ableton_live_options_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/unit/recipes/ableton_live_options_spec.rb b/spec/unit/recipes/ableton_live_options_spec.rb index 45f15ff..d5c7d4e 100644 --- a/spec/unit/recipes/ableton_live_options_spec.rb +++ b/spec/unit/recipes/ableton_live_options_spec.rb @@ -54,6 +54,9 @@ end.converge(described_recipe) } + it "creates Ableton Preferences directory" do + expect(chef_run).to create_directory(ableton_preferences_path) + end it "creates Ableton Preferences directory for latest detected version: #{ableton_live_version}" do expected_directory = "#{ableton_preferences_path}/Live #{ableton_live_version}" From 06913f005eed7d339337176e9868ae6e01ac6631 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Wed, 25 May 2022 21:41:31 -0600 Subject: [PATCH 48/60] lyraphase_workstation::ableton_live_options: Fix parent directory creation --- recipes/ableton_live_options.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/recipes/ableton_live_options.rb b/recipes/ableton_live_options.rb index a148ae0..f7aba33 100644 --- a/recipes/ableton_live_options.rb +++ b/recipes/ableton_live_options.rb @@ -72,8 +72,14 @@ Chef::Log.info("Ableton Live Managed Versions: #{ableton_live_managed_versions}") unless ableton_live_managed_versions.nil? || ableton_live_managed_versions.empty? + # Ensure directories exist if Ableton has never been started yet (installed first time) + directory ableton_preferences_path do + owner node['lyraphase_workstation']['user'] + group 'staff' + mode '0755' + action :create + end ableton_live_managed_versions.each do |ableton_live_version| - # Ensure directory exists if Ableton has never been started yet (installed first time) directory "#{ableton_preferences_path}/Live #{ableton_live_version}" do owner node['lyraphase_workstation']['user'] group 'staff' From fa9d45a8e776c4d90efa59c0749ccdea216ec86d Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Wed, 25 May 2022 21:57:59 -0600 Subject: [PATCH 49/60] Find/Replace all instances of old repo name with: LyraPhase/lyraphase_workstation Commands were: ag 'trinitronx/lyraphase_workstation' -l | xargs -I{} sed -i '' -e 's#trinitronx/lyraphase_workstation#LyraPhase/lyraphase_workstation#g' '{}' ag 'LyraPhase/lyraphase_workstation' -l | xargs -I{} git add '{}' --- README.md | 8 ++++---- SECURITY.md | 2 +- ... Tunneled Proxy Access to VPC from Docker Container.md | 2 +- metadata.rb | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9d5dfca..16714c4 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ # lyraphase_workstation cookbook -[![ci](https://github.com/trinitronx/lyraphase_workstation/actions/workflows/ci.yml/badge.svg)](https://github.com/trinitronx/lyraphase_workstation/actions/workflows/ci.yml) +[![ci](https://github.com/LyraPhase/lyraphase_workstation/actions/workflows/ci.yml/badge.svg)](https://github.com/LyraPhase/lyraphase_workstation/actions/workflows/ci.yml) [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit) [![pre-commit](https://github.com/LyraPhase/sprout-wrap/actions/workflows/pre-commit.yml/badge.svg)](https://github.com/LyraPhase/sprout-wrap/actions/workflows/pre-commit.yml) @@ -306,7 +306,7 @@ Some general rules of thumb: - `lyraphase_workstation::korg_kontrol_editor`: Install [Korg Kontrol Editor](http://www.korg.com/us/support/download/software/1/253/1355/) ([Manual](http://www.korg.com/us/support/download/manual/1/253/1843/) [Archived DL](https://web.archive.org/web/20150919212752/http://www.korg.com/filedl/61a78cbcf754384af8104114d7cde1c7/840/download.php)) -- `lyraphase_workstation::loopback_alias_ip`: Install [loopback alias IP LaunchDaemon](https://github.com/trinitronx/lyraphase_workstation/blob/master/templates/default/com.runlevel1.lo0.alias.plist.erb) +- `lyraphase_workstation::loopback_alias_ip`: Install [loopback alias IP LaunchDaemon](https://github.com/LyraPhase/lyraphase_workstation/blob/master/templates/default/com.runlevel1.lo0.alias.plist.erb) for [SSH Tunneled Proxy Access to VPC / Private Network from a Docker Container][ssh-tunnel-docs] - Adds support for local [SSH tunnel port forwarding across Docker bridge networks](https://gist.github.com/trinitronx/6427d6454fb3b121fc2ab5ca7ac766bc) - Use case for `terraform` [explained here](https://github.com/hashicorp/terraform/issues/17754#issuecomment-383227407) @@ -388,7 +388,7 @@ Some general rules of thumb: - `lyraphase_workstation::root_bootstrap_ssh_config`: Installs a minimal `.ssh/config` + `known_hosts` file for GitHub & Homebrew bootstrap - `lyraphase_workstation::ssh_tunnel_port_override`: Install - [`ssh-tunnel-port-override.sh` script](https://github.com/trinitronx/lyraphase_workstation/blob/master/templates/default/ssh-tunnel-port-override.sh.erb) + [`ssh-tunnel-port-override.sh` script](https://github.com/LyraPhase/lyraphase_workstation/blob/master/templates/default/ssh-tunnel-port-override.sh.erb) & `LaunchDaemon` to allow killing some process (_cough_ McAfee -Anti-virus _cough_ 🦠😷) that claims your favorite SSH tunnel port (Default: `8081`) on login. @@ -442,4 +442,4 @@ Author:: James Cuzella ([@trinitronx][keybase-id]) [iterm2-shell]: https://www.iterm2.com/documentation-shell-integration.html [bash-it]: https://github.com/Bash-it/bash-it [sprout-base]: https://github.com/pivotal-sprout/sprout-base -[ssh-tunnel-docs]: https://github.com/trinitronx/lyraphase_workstation/blob/master/docs/SSH%20Tunneled%20Proxy%20Access%20to%20VPC%20from%20Docker%20Container.md +[ssh-tunnel-docs]: https://github.com/LyraPhase/lyraphase_workstation/blob/master/docs/SSH%20Tunneled%20Proxy%20Access%20to%20VPC%20from%20Docker%20Container.md diff --git a/SECURITY.md b/SECURITY.md index a6c7055..6883f28 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -48,5 +48,5 @@ Good Day Sir! [🟣🎩😬🍫][1] ... So shines a good deed in a weary world ... [😌🙂😄😁][2] [1]: https://web.archive.org/web/20200512084230/https://www.youtube.com/watch?v=fpK36FZmTFY -[2]: https://raw.githubusercontent.com/trinitronx/lyraphase_workstation/master/SECURITY.md +[2]: https://raw.githubusercontent.com/LyraPhase/lyraphase_workstation/master/SECURITY.md [you-passed-the-test]: https://web.archive.org/web/20200512094026/https://www.youtube.com/watch?v=dOu2NpXXgiI&lc=UgxfSAyhy6gW4koFlpB4AaABAg diff --git a/docs/SSH Tunneled Proxy Access to VPC from Docker Container.md b/docs/SSH Tunneled Proxy Access to VPC from Docker Container.md index 4253968..9e71433 100644 --- a/docs/SSH Tunneled Proxy Access to VPC from Docker Container.md +++ b/docs/SSH Tunneled Proxy Access to VPC from Docker Container.md @@ -179,4 +179,4 @@ There is an [upstream bug in Golang to ask for `socks5h://` support in If this is ever fixed, perhaps Golang code that uses standard `x/net/proxy` library will _just work_! -[1]: https://github.com/trinitronx/lyraphase_workstation/blob/master/recipes/loopback_alias_ip.rb +[1]: https://github.com/LyraPhase/lyraphase_workstation/blob/master/recipes/loopback_alias_ip.rb diff --git a/metadata.rb b/metadata.rb index b0fa451..adb4324 100644 --- a/metadata.rb +++ b/metadata.rb @@ -7,8 +7,8 @@ version "3.3.0" chef_version ">= 12.0" if respond_to?(:chef_version) -source_url 'https://github.com/trinitronx/lyraphase_workstation' if respond_to?(:source_url) -issues_url 'https://github.com/trinitronx/lyraphase_workstation/issues' if respond_to?(:issues_url) +source_url 'https://github.com/LyraPhase/lyraphase_workstation' if respond_to?(:source_url) +issues_url 'https://github.com/LyraPhase/lyraphase_workstation/issues' if respond_to?(:issues_url) require 'chef/version_constraint' From 48dbc235556be1f9bd0724a46ef494f2037bc10b Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Wed, 25 May 2022 22:12:21 -0600 Subject: [PATCH 50/60] Document repo migration in README --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/README.md b/README.md index 16714c4..a8a2057 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ "*", "## Sponsor", "*", + "## Migration", + "*", "# Attributes", "*", "# Recipes", @@ -208,6 +210,47 @@ and help me continue? Every little bit is appreciated! Thank you! 🙏 +## Migration + +**Note:** This Chef Cookbook has migrated from the old location +(`trinitronx/lyraphase_workstation`) to `LyraPhase/lyraphase_workstation`. +It has **NOT** changed ownership or maintainers at this time. It has been moved +to benefit from GitHub's CI/CD automation features that are available to a +GitHub Organization. + +While all links to the previous repository location are automatically redirected +to the new location by GitHub, it is recommended to migrate any references you +may have, or previously cloned `git` repos to use the new URL. + +To avoid confusion, we strongly recommend updating any existing local clones to +point to the new repository URL. + + cd path/to/trinitronx/lyraphase_workstation + git remote -vv # List remote repos + # Find the named remote URL with 'trinitronx/lyraphase_workstation' + # (usually 'origin' by default) + # If you checked this repo out as a fork + # or named the remote repo something other than 'origin', + # then use that in the following command + git remote set-url origin https://github.com/LyraPhase/lyraphase_workstation.git + git remote -vv # Check that the remote repo URL now contains 'LyraPhase/lyraphase_workstation' + +The cookbook and recipe names have not changed. While generally repo names are +not as important to Chef Infra or Cinc Client, they may appear in dependency +manager files such as: + +- `Policyfile`s +- `Berksfile`s +- `Cheffile`s + +You can do this easily in your codebase using the following commands: + + grep -rin -l 'trinitronx/lyraphase_workstation' ./ | xargs -I{} sed -i '' -e 's#trinitronx/lyraphase_workstation#LyraPhase/lyraphase_workstation#g' '{}' + grep -rin -l 'LyraPhase/lyraphase_workstation' ./ | xargs -I{} git add '{}' + git commit -m 'Migrating Cookbook trinitronx/lyraphase_workstation => LyraPhase/lyraphase_workstation' + +Then, run your dependency manager tool commands appropriately. + # Attributes Too many to list! Please see the appropriate recipe's From aaad1eef2b21a654df1c3c3a597100a6eb014fa1 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Wed, 25 May 2022 22:15:01 -0600 Subject: [PATCH 51/60] Fix markdownlint MD013/line-length Markdownlint Warning was: README.md:248:121 MD013/line-length Line length [Expected: 120; Actual: 156] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a8a2057..2411276 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,8 @@ manager files such as: You can do this easily in your codebase using the following commands: - grep -rin -l 'trinitronx/lyraphase_workstation' ./ | xargs -I{} sed -i '' -e 's#trinitronx/lyraphase_workstation#LyraPhase/lyraphase_workstation#g' '{}' + grep -rin -l 'trinitronx/lyraphase_workstation' ./ | \ + xargs -I{} sed -i '' -e 's#trinitronx/lyraphase_workstation#LyraPhase/lyraphase_workstation#g' '{}' grep -rin -l 'LyraPhase/lyraphase_workstation' ./ | xargs -I{} git add '{}' git commit -m 'Migrating Cookbook trinitronx/lyraphase_workstation => LyraPhase/lyraphase_workstation' From 5beaab343916566e29b9296e31536f46d3bcd772 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Wed, 25 May 2022 22:20:53 -0600 Subject: [PATCH 52/60] ci: Cleanup GitHub Actions Workspace directory to try and clear out old repository names --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bcd080f..25b33d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,7 @@ jobs: rake-ci: runs-on: ubuntu-latest steps: + - uses: rtCamp/action-cleanup@master - name: Check out code uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 @@ -42,6 +43,7 @@ jobs: fail-fast: false steps: + - uses: rtCamp/action-cleanup@master - name: Check out code uses: actions/checkout@v2 - name: Install Chef From f273131bde7cb27ebace73af5a88c8a3b5cf66e5 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Wed, 25 May 2022 22:23:58 -0600 Subject: [PATCH 53/60] ci: Use original cleanup Action rather than forked version --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 25b33d7..2d74977 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: rake-ci: runs-on: ubuntu-latest steps: - - uses: rtCamp/action-cleanup@master + - uses: AutoModality/action-clean@v1 - name: Check out code uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 @@ -43,7 +43,7 @@ jobs: fail-fast: false steps: - - uses: rtCamp/action-cleanup@master + - uses: AutoModality/action-clean@v1 - name: Check out code uses: actions/checkout@v2 - name: Install Chef From 7c7734c6317b48f7d699a77132a5c613466a8b81 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Wed, 25 May 2022 22:28:24 -0600 Subject: [PATCH 54/60] README: Migrate some more missed URLs --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2411276..e3df1a7 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ [![ci](https://github.com/LyraPhase/lyraphase_workstation/actions/workflows/ci.yml/badge.svg)](https://github.com/LyraPhase/lyraphase_workstation/actions/workflows/ci.yml) [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit) -[![pre-commit](https://github.com/LyraPhase/sprout-wrap/actions/workflows/pre-commit.yml/badge.svg)](https://github.com/LyraPhase/sprout-wrap/actions/workflows/pre-commit.yml) +[![pre-commit](https://github.com/LyraPhase/lyraphase_workstation/actions/workflows/pre-commit.yml/badge.svg)](https://github.com/LyraPhase/lyraphase_workstation/actions/workflows/pre-commit.yml) A cookbook including various recipes for installing tools used by myself. This includes Ableton Live [DAW][1], VSTs, and other various tools and @@ -476,7 +476,7 @@ Author:: James Cuzella ([@trinitronx][keybase-id]) [1]: https://en.wikipedia.org/wiki/Digital_audio_workstation [keybase-id]: https://gist.github.com/trinitronx/aee110cbdf55e67185dc44272784e694 -[sprout-wrap]: https://github.com/trinitronx/sprout-wrap/ +[sprout-wrap]: https://github.com/LyraPhase/sprout-wrap/ [dmg-cookbook]: https://github.com/chef-cookbooks/dmg [data-bags]: https://docs.chef.io/data_bags.html [knife-solo_data_bag]: https://github.com/thbishop/knife-solo_data_bag From 2fbf42294b141e19e8d89f27fbf9fd745a0c78ae Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Wed, 25 May 2022 22:38:36 -0600 Subject: [PATCH 55/60] ci: Debug GitHub workspace & repo name --- .github/workflows/ci.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d74977..ca890e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,9 +43,17 @@ jobs: fail-fast: false steps: - - uses: AutoModality/action-clean@v1 - name: Check out code uses: actions/checkout@v2 + - name: DEBUG GitHub Workspace + run: + ls -lA $GITHUB_WORKSPACE + - name: DEBUG Repo Name + run: + pwd + ls -lA ./ + git remote -vv + echo "github.repository=${{ github.repository }}" - name: Install Chef uses: actionshub/chef-install@main - name: Test Kitchen From 56e320fa61f53596e4187f42e398262ae32c581b Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Thu, 26 May 2022 00:28:20 -0600 Subject: [PATCH 56/60] ci: Remove Debugging & action-clean... it was a weird transient heisenbug --- .github/workflows/ci.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ca890e1..bcd080f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,6 @@ jobs: rake-ci: runs-on: ubuntu-latest steps: - - uses: AutoModality/action-clean@v1 - name: Check out code uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 @@ -45,15 +44,6 @@ jobs: steps: - name: Check out code uses: actions/checkout@v2 - - name: DEBUG GitHub Workspace - run: - ls -lA $GITHUB_WORKSPACE - - name: DEBUG Repo Name - run: - pwd - ls -lA ./ - git remote -vv - echo "github.repository=${{ github.repository }}" - name: Install Chef uses: actionshub/chef-install@main - name: Test Kitchen From 0625d0a4a327e235a45aecfd2ec29a453e9dc5ce Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Thu, 26 May 2022 00:33:32 -0600 Subject: [PATCH 57/60] ci: DEBUG GitHub runner IP --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bcd080f..e788dc7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,6 +42,9 @@ jobs: fail-fast: false steps: + - name: What is GitHub IP? + run: | + curl -Ls ifconfig.co - name: Check out code uses: actions/checkout@v2 - name: Install Chef From b02d0025f81d5129a0abbbcfee18bc201e97368e Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Thu, 26 May 2022 01:01:36 -0600 Subject: [PATCH 58/60] ci: DEBUG GitHub ifconfig IP --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e788dc7..75f4cf5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,9 @@ jobs: - name: What is GitHub IP? run: | curl -Ls ifconfig.co + - name: What is GitHub ifconfig? + run: | + ifconfig - name: Check out code uses: actions/checkout@v2 - name: Install Chef From 4618ac21a93ff3047ddc51231e64788a53a0df65 Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Thu, 26 May 2022 01:08:51 -0600 Subject: [PATCH 59/60] Revert "ci: DEBUG GitHub ifconfig IP" This reverts commit b02d0025f81d5129a0abbbcfee18bc201e97368e. --- .github/workflows/ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 75f4cf5..e788dc7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,9 +45,6 @@ jobs: - name: What is GitHub IP? run: | curl -Ls ifconfig.co - - name: What is GitHub ifconfig? - run: | - ifconfig - name: Check out code uses: actions/checkout@v2 - name: Install Chef From edcd8b61afee8a70dad502d507ddeba1abb3b16d Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Thu, 26 May 2022 01:46:29 -0600 Subject: [PATCH 60/60] Bump cookbook to v3.4.0 --- metadata.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.rb b/metadata.rb index adb4324..3d46a2e 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license "GPL-3.0+" description "Recipes to Install & Configure my workstation" long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "3.3.0" +version "3.4.0" chef_version ">= 12.0" if respond_to?(:chef_version) source_url 'https://github.com/LyraPhase/lyraphase_workstation' if respond_to?(:source_url)