diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f2138a9..cc93b22 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,15 +22,16 @@ jobs: strategy: matrix: os: + - almalinux-8 - amazonlinux-2 - - debian-9 - - debian-10 - centos-7 - - centos-8 - - ubuntu-1604 + - centos-stream-8 + - debian-10 + - debian-11 + - opensuse-leap-15 + - rockylinux-8 - ubuntu-1804 - ubuntu-2004 - - opensuse-leap-15 suite: - resources - source @@ -57,16 +58,14 @@ jobs: sudo journalctl -l --since today KITCHEN_LOCAL_YAML=kitchen.dokken.yml /usr/bin/kitchen exec ${{ matrix.suite }}-${{ matrix.os }} -c "journalctl -l" - integration-macos: + integration-windows: needs: lint-unit - runs-on: macos-latest + runs-on: macos-10.15 strategy: matrix: os: - - windows-2012r2 - windows-2016 - windows-2019 - - macos-1015 suite: - resources fail-fast: false @@ -83,3 +82,28 @@ jobs: with: suite: ${{ matrix.suite }} os: ${{ matrix.os }} + + integration-macos: + needs: lint-unit + runs-on: macos-latest + strategy: + matrix: + os: + - macos-latest + suite: + - resources + fail-fast: false + + steps: + - name: Check out code + uses: actions/checkout@v2 + - name: Install Chef + uses: actionshub/chef-install@main + - name: test-kitchen + uses: actionshub/test-kitchen@main + env: + CHEF_LICENSE: accept-no-persist + KITCHEN_LOCAL_YAML: kitchen.exec.yml + with: + suite: ${{ matrix.suite }} + os: ${{ matrix.os }} diff --git a/.overcommit.yml b/.overcommit.yml index 1d27ed8..cd8682a 100644 --- a/.overcommit.yml +++ b/.overcommit.yml @@ -11,10 +11,6 @@ PreCommit: enabled: true required_executable: 'cookstyle' command: ["cookstyle"] - Delivery: - enabled: true - required_executable: 'delivery' - flags: ['local', 'all'] CommitMsg: HardTabs: enabled: true diff --git a/CHANGELOG.md b/CHANGELOG.md index aaf9144..520048f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- Standardise files with files in sous-chefs/repo-management +- Update tested platforms +- Update Windows version to 2.35.1 + - Update helpers to deal with 32/64bit + - Switch `git::package` to use `git_client` for windows +- Remove inclusion of `git::default` from `git_config` resource +- Add `password` property to `git_config` resource which is required on Windows if running as a different user +- Fix tests on MacOS and Windows + ## 11.0.2 - *2022-05-16* - Remove delivery folder diff --git a/attributes/default.rb b/attributes/default.rb index 3ac5c34..cffcad3 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -18,7 +18,7 @@ # limitations under the License. if platform_family?('windows') - default['git']['version'] = '2.8.1' + default['git']['version'] = '2.35.1' if node['kernel']['machine'] == 'x86_64' default['git']['architecture'] = '64' default['git']['checksum'] = '5e5283990cc91d1e9bd0858f8411e7d0afb70ce26e23680252fb4869288c7cfb' diff --git a/chefignore b/chefignore index cc170ea..a27b0b2 100644 --- a/chefignore +++ b/chefignore @@ -61,7 +61,7 @@ Dangerfile examples/* features/* Guardfile -kitchen.yml* +kitchen*.yml mlc_config.json Procfile Rakefile diff --git a/kitchen.dokken.yml b/kitchen.dokken.yml index 23e30ce..61a6cc5 100644 --- a/kitchen.dokken.yml +++ b/kitchen.dokken.yml @@ -12,33 +12,34 @@ provisioner: chef_license: accept-no-persist platforms: + - name: almalinux-8 + driver: + image: dokken/almalinux-8 + pid_one_command: /usr/lib/systemd/systemd + - name: amazonlinux-2 driver: image: dokken/amazonlinux-2 pid_one_command: /usr/lib/systemd/systemd - - name: debian-9 + - name: debian-10 driver: - image: dokken/debian-9 + image: dokken/debian-10 pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update - - name: debian-10 + - name: debian-11 driver: - image: dokken/debian-10 + image: dokken/debian-11 pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update - name: centos-7 driver: image: dokken/centos-7 pid_one_command: /usr/lib/systemd/systemd - - name: centos-8 + - name: centos-stream-8 driver: - image: dokken/centos-8 + image: dokken/centos-stream-8 pid_one_command: /usr/lib/systemd/systemd - name: fedora-latest @@ -46,28 +47,22 @@ platforms: image: dokken/fedora-latest pid_one_command: /usr/lib/systemd/systemd - - name: ubuntu-16.04 - driver: - image: dokken/ubuntu-16.04 - pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update - - name: ubuntu-18.04 driver: image: dokken/ubuntu-18.04 pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update - name: ubuntu-20.04 driver: image: dokken/ubuntu-20.04 pid_one_command: /bin/systemd - intermediate_instructions: - - RUN /usr/bin/apt-get update - name: opensuse-leap-15 driver: image: dokken/opensuse-leap-15 - pid_one_command: /bin/systemd + pid_one_command: /usr/lib/systemd/systemd + + - name: rockylinux-8 + driver: + image: dokken/rockylinux-8 + pid_one_command: /usr/lib/systemd/systemd diff --git a/kitchen.exec.yml b/kitchen.exec.yml new file mode 100644 index 0000000..84621fa --- /dev/null +++ b/kitchen.exec.yml @@ -0,0 +1,17 @@ +--- +driver: + name: exec + +transport: + name: exec + +provisioner: + name: chef_zero + deprecations_as_errors: true + +platforms: + - name: windows-latest + provisioner: + enforce_idempotency: false + multiple_converge: 1 + - name: macos-latest diff --git a/kitchen.yml b/kitchen.yml index c6f7478..026be6d 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -1,13 +1,15 @@ --- driver: name: vagrant + gui: false provisioner: - name: chef_zero - product_name: chef + name: chef_infra + product_name: <%= ENV['CHEF_PRODUCT_NAME'] || 'chef' %> enforce_idempotency: true multiple_converge: 2 deprecations_as_errors: true + chef_license: accept-no-persist verifier: name: inspec @@ -15,32 +17,54 @@ verifier: platforms: - name: amazonlinux-2 - name: centos-7 - - name: centos-8 - - name: debian-9 + - name: centos-stream-8 - name: debian-10 - - name: freebsd-11 - - name: fedora-29 + - name: debian-11 + - name: freebsd-13 + - name: fedora-latest - name: opensuse-leap-15 - - name: ubuntu-16.04 - name: ubuntu-18.04 - name: ubuntu-20.04 - name: windows-2012r2 driver: box: tas50/windows_2012r2 - gui: false + customize: + cpus: 2 + memory: 4096 + transport: + name: winrm + elevated: true + provisioner: + enforce_idempotency: false + multiple_converge: 1 - name: windows-2016 driver: box: tas50/windows_2016 - gui: false + customize: + cpus: 2 + memory: 4096 + transport: + name: winrm + elevated: true + provisioner: + enforce_idempotency: false + multiple_converge: 1 - name: windows-2019 driver: box: tas50/windows_2019 - gui: false + customize: + cpus: 2 + memory: 4096 + transport: + name: winrm + elevated: true + provisioner: + enforce_idempotency: false + multiple_converge: 1 - name: macos-10.15 run_list: homebrew::default driver: box: tas50/macos_10.15 - provider: vmware_fusion suites: - name: resources diff --git a/libraries/helpers.rb b/libraries/helpers.rb index 7bf29b3..a9f52d6 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -31,17 +31,25 @@ def parsed_windows_display_name def parsed_windows_package_version return new_resource.windows_package_version if new_resource.windows_package_version - '2.7.4' + '2.35.1' end def parsed_windows_package_url return new_resource.windows_package_url if new_resource.windows_package_url - "https://github.com/git-for-windows/git/releases/download/v%#{parsed_windows_package_version}.windows.1/Git-%#{parsed_windows_package_version}-32-bit.exe" + if node['kernel']['machine'] == 'x86_64' + "https://github.com/git-for-windows/git/releases/download/v#{parsed_windows_package_version}.windows.1/Git-#{parsed_windows_package_version}-64-bit.exe" + else + "https://github.com/git-for-windows/git/releases/download/v#{parsed_windows_package_version}.windows.1/Git-#{parsed_windows_package_version}-32-bit.exe" + end end def parsed_windows_package_checksum return new_resource.windows_package_checksum if new_resource.windows_package_checksum - '49601d5102df249d6f866ecfa1eea68eb5672acc1dbb7e4051099e792f6da5fc' + if node['kernel']['machine'] == 'x86_64' + '5d66948e7ada0ab184b2745fdf6e11843443a97655891c3c6268b5985b88bf4f' + else + '5e45b1226b106dd241de0be0b350052afe53bd61dce80ac6044600dc85fbfa0b' + end end end end diff --git a/recipes/package.rb b/recipes/package.rb index 873acaa..1699056 100644 --- a/recipes/package.rb +++ b/recipes/package.rb @@ -16,8 +16,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -if platform?('windows') - include_recipe 'git::windows' -else - git_client 'default' -end +git_client 'default' diff --git a/resources/client_osx.rb b/resources/client_osx.rb index 42dfb21..992a5b7 100644 --- a/resources/client_osx.rb +++ b/resources/client_osx.rb @@ -3,5 +3,7 @@ provides :git_client, platform: 'mac_os_x' action :install do - package 'git' + package 'git' do + options '--override' + end end diff --git a/resources/client_windows.rb b/resources/client_windows.rb index fb5fab2..4252d24 100644 --- a/resources/client_windows.rb +++ b/resources/client_windows.rb @@ -15,6 +15,7 @@ windows_package parsed_windows_display_name do source parsed_windows_package_url checksum parsed_windows_package_checksum + version parsed_windows_package_version installer_type :inno end diff --git a/resources/config.rb b/resources/config.rb index 2b9ad11..9bbb3a6 100644 --- a/resources/config.rb +++ b/resources/config.rb @@ -6,17 +6,25 @@ property :path, String, desired_state: false property :user, String, desired_state: false property :group, String, desired_state: false +property :password, String, desired_state: false, sensitive: true property :options, String, desired_state: false -def initialize(*args) - super - - @run_context.include_recipe 'git' -end - load_current_value do - cmd_env = user ? { 'USER' => user, 'HOME' => ::Dir.home(user) } : nil - config_vals = Mixlib::ShellOut.new("git config --get --#{scope} #{key}", user: user, group: group, cwd: path, env: cmd_env) + begin + home_dir = ::Dir.home(user) + rescue + value nil + end + + cmd_env = user ? { 'USER' => user, 'HOME' => home_dir } : nil + config_vals = Mixlib::ShellOut.new( + "git config --get --#{scope} #{key}", + user: user, + group: group, + password: password, + cwd: path, + env: cmd_env + ) config_vals.run_command if config_vals.stdout.empty? value nil @@ -31,6 +39,7 @@ def initialize(*args) cwd new_resource.path user new_resource.user group new_resource.group + password new_resource.password environment cmd_env end end diff --git a/spec/unit/recipes/default_spec.rb b/spec/unit/recipes/default_spec.rb index 7a5586c..7ca52ad 100644 --- a/spec/unit/recipes/default_spec.rb +++ b/spec/unit/recipes/default_spec.rb @@ -9,7 +9,7 @@ ).converge(described_recipe) end - it { expect(chef_run).to include_recipe('git::windows') } + it { is_expected.to install_git_client('default') } end context 'on linux' do diff --git a/spec/unit/recipes/windows_spec.rb b/spec/unit/recipes/windows_spec.rb index 93d97d5..cb10804 100644 --- a/spec/unit/recipes/windows_spec.rb +++ b/spec/unit/recipes/windows_spec.rb @@ -10,8 +10,8 @@ it do expect(chef_run).to install_git_client('default').with( - windows_display_name: 'Git version 2.8.1', - windows_package_url: 'https://github.com/git-for-windows/git/releases/download/v2.8.1.windows.1/Git-2.8.1-64-bit.exe', + windows_display_name: 'Git version 2.35.1', + windows_package_url: 'https://github.com/git-for-windows/git/releases/download/v2.35.1.windows.1/Git-2.35.1-64-bit.exe', windows_package_checksum: '5e5283990cc91d1e9bd0858f8411e7d0afb70ce26e23680252fb4869288c7cfb' ) end diff --git a/test/fixtures/cookbooks/test/recipes/default.rb b/test/fixtures/cookbooks/test/recipes/default.rb index 1199f23..fc6f89c 100644 --- a/test/fixtures/cookbooks/test/recipes/default.rb +++ b/test/fixtures/cookbooks/test/recipes/default.rb @@ -2,29 +2,40 @@ git_client 'install it' +home_dir = + if windows? + 'C:\temp' + elsif macos? + '/Users/random' + else + '/home/random' + end + user 'random' do manage_home true - home '/home/random' -end + home home_dir +end unless windows? + +directory 'C:\temp' if windows? git_config 'add name to random' do - user 'random' + user 'random' unless windows? scope 'global' key 'user.name' value 'John Doe global' end -git '/home/random/git_repo' do +git "#{home_dir}/git_repo" do repository 'https://github.com/chef/chef-repo.git' - user 'random' + user 'random' unless windows? end git_config 'change local path' do - user 'random' + user 'random' unless windows? scope 'local' key 'user.name' value 'John Doe local' - path '/home/random/git_repo' + path "#{home_dir}/git_repo" end git_config 'change system config' do diff --git a/test/integration/resources/git_installed_spec.rb b/test/integration/resources/git_installed_spec.rb index 8a90469..32f2621 100644 --- a/test/integration/resources/git_installed_spec.rb +++ b/test/integration/resources/git_installed_spec.rb @@ -1,19 +1,47 @@ # rubocop:disable Chef/Deprecations/ResourceWithoutUnifiedTrue +home_dir = + if os.family == 'windows' + if user('vagrant') + 'C:/Users/vagrant' + else + 'C:/Users/RUNNER~1' + end + elsif os.family == 'darwin' + '/Users/random' + else + '/home/random' + end + +repo_dir = + if os.family == 'windows' + 'C:/temp' + else + home_dir + end + +etc_dir = + if os.family == 'windows' + 'C:/Program Files/Git/etc' + elsif os.family == 'darwin' + '/usr/local/etc' + else + '/etc' + end describe command('git --version') do its('exit_status') { should eq 0 } its('stdout') { should match /git version/ } end -describe ini('/home/random/.gitconfig') do +describe ini("#{home_dir}/.gitconfig") do its(%w(user name)) { should eq 'John Doe global' } end -describe ini('/home/random/git_repo/.git/config') do +describe ini("#{repo_dir}/git_repo/.git/config") do its(%w(user name)) { should eq 'John Doe local' } end -describe ini('/etc/gitconfig') do +describe ini("#{etc_dir}/gitconfig") do its(%w(user name)) { should eq 'John Doe system' } its(['url "https://github.com/"', 'insteadOf']) { should eq 'git://github.com/' } end