Add more Xcode logging to better tell what Xcode version is being installed (#269)

Remove a control for a test that does not exist
Call the log command with credentials.
Fix tests expecting side-effects from xcode.version.call. Fix logging to not attempt to auth when no credentials will exist (using a download URL).

Co-authored-by: Gustave Granroth <gugra@microsoft.com>
This commit is contained in:
Gustave Granroth 2022-11-16 13:07:00 -08:00 коммит произвёл GitHub
Родитель 22e870b095
Коммит f20bdc2fe0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 56 добавлений и 40 удалений

Просмотреть файл

@ -1,5 +1,11 @@
# Changelog
## [5.0.2] - 2022-09-08
### Added
- Xcode resource logs the Xcode version to install computed from the provided version.
- Xcode library supports calling the `version` property more than once by not changing the stored data type.
## [5.0.1] - 2022-05-25
### Fixed

Просмотреть файл

@ -130,7 +130,6 @@ suites:
controls:
- keychain-creation
- login-keychain-creation
- default-keychain-creation
- name: remote-access
provisioner:

Просмотреть файл

@ -13,11 +13,11 @@ module MacOS
end
def determine_version
@version = if @download_url.empty?
latest_xcode_revision(Xcode::Version.new(@semantic_version))
else
@semantic_version
end
if @download_url.empty?
latest_xcode_revision(Xcode::Version.new(@semantic_version))
else
@semantic_version
end
end
def available_xcode_versions
@ -41,7 +41,7 @@ module MacOS
def current_path
if installed_path.nil?
"/Applications/Xcode-#{@version.tr(' ', '.')}.app"
"/Applications/Xcode-#{@version.call.tr(' ', '.')}.app"
else
installed_path[@semantic_version]
end

Просмотреть файл

@ -4,7 +4,7 @@ maintainer_email 'chef@microsoft.com'
license 'MIT'
description 'Resources for configuring and provisioning macOS'
chef_version '>= 14.0'
version '5.0.1'
version '5.0.2'
source_url 'https://github.com/Microsoft/macos-cookbook'
issues_url 'https://github.com/Microsoft/macos-cookbook/issues'

Просмотреть файл

@ -9,6 +9,19 @@ property :ios_simulators, Array
property :download_url, String, default: ''
property :apple_id, Hash
action_class do
def with_appleid_credentials(credentials)
begin
ENV['XCODE_INSTALL_USER'] = credentials[:XCODE_INSTALL_USER]
ENV['XCODE_INSTALL_PASSWORD'] = credentials[:XCODE_INSTALL_PASSWORD]
yield
ensure
ENV['XCODE_INSTALL_USER'] = ''
ENV['XCODE_INSTALL_PASSWORD'] = ''
end
end
end
action :install_gem do
command_line_tools 'latest'
@ -25,12 +38,22 @@ action :install_gem do
end
action :install_xcode do
developer = DeveloperAccount.new(new_resource.apple_id, new_resource.download_url)
xcode = Xcode.new(
new_resource.version,
new_resource.path,
new_resource.download_url
)
if new_resource.download_url.empty?
with_appleid_credentials(developer.credentials) do
log 'Log Xcode information' do
message "Will install Xcode #{xcode.version.call} computed from #{new_resource.version}"
end
end
end
unless xcode.compatible_with_platform?(node['platform_version'])
ruby_block 'exception' do
raise("Xcode #{new_resource.version} not supported on #{node['platform_version']}")
@ -45,7 +68,6 @@ action :install_xcode do
end
execute "install Xcode #{new_resource.version}" do
developer = DeveloperAccount.new(new_resource.apple_id, new_resource.download_url)
command XCVersion.install_xcode(xcode)
environment developer.credentials
cwd '/Users/Shared'

Просмотреть файл

@ -90,58 +90,49 @@ describe MacOS::Xcode do
end
it 'returns the name of the latest Xcode 12 beta when initialized with the semantic version' do
xcode = MacOS::Xcode.new('12.0', '/Applications/Xcode.app')
xcode.version.call
expect(xcode.version).to eq '12 beta 4'
expect(xcode.version).to_not eq '12 beta'
expect(xcode.version).to_not eq '12 for macOS Universal Apps beta'
expect(xcode.version.call).to eq '12 beta 4'
expect(xcode.version.call).to_not eq '12 beta'
expect(xcode.version.call).to_not eq '12 for macOS Universal Apps beta'
end
it 'returns the name of the latest Xcode 11.6 beta when initialized with the semantic version' do
xcode = MacOS::Xcode.new('11.6', '/Applications/Xcode.app')
xcode.version.call
expect(xcode.version).to eq '11.6 beta 2'
expect(xcode.version).to_not eq '11.6 beta'
expect(xcode.version).to_not eq '11.6 beta2'
expect(xcode.version.call).to eq '11.6 beta 2'
expect(xcode.version.call).to_not eq '11.6 beta'
expect(xcode.version.call).to_not eq '11.6 beta2'
end
it 'returns the name of Xcode 11.5 official when initialized with the semantic version' do
xcode = MacOS::Xcode.new('11.5', '/Applications/Xcode.app')
xcode.version.call
expect(xcode.version).to eq '11.5'
expect(xcode.version).to_not eq '11.5 beta'
expect(xcode.version).to_not eq '11.5 Release Candidate'
expect(xcode.version.call).to eq '11.5'
expect(xcode.version.call).to_not eq '11.5 beta'
expect(xcode.version.call).to_not eq '11.5 Release Candidate'
end
it 'returns the name of Xcode 10 official when initialized with the semantic version' do
xcode = MacOS::Xcode.new('10.0', '/Applications/Xcode.app')
xcode.version.call
expect(xcode.version).to eq '10'
expect(xcode.version).to_not eq '10 Release Candidate'
expect(xcode.version).to_not eq '10 beta 1'
expect(xcode.version.call).to eq '10'
expect(xcode.version.call).to_not eq '10 Release Candidate'
expect(xcode.version.call).to_not eq '10 beta 1'
end
it 'returns the name of Xcode 9.4.2 official when initialized with the semantic version' do
xcode = MacOS::Xcode.new('9.4.2', '/Applications/Xcode.app')
xcode.version.call
expect(xcode.version).to eq '9.4.2'
expect(xcode.version).to_not eq '9.4.2 beta 2'
expect(xcode.version).to_not eq '9.4.2 beta 3'
expect(xcode.version.call).to eq '9.4.2'
expect(xcode.version.call).to_not eq '9.4.2 beta 2'
expect(xcode.version.call).to_not eq '9.4.2 beta 3'
end
it 'returns the temporary beta path set by xcversion when initialized with the semantic version' do
xcode = MacOS::Xcode.new('9.4.2', '/Applications/Xcode.app')
xcode.version.call
expect(xcode.current_path).to eq '/Applications/Xcode-9.4.2.app'
end
it 'returns the name of Xcode 9.3 when initialized with the semantic version' do
xcode = MacOS::Xcode.new('9.3', '/Applications/Xcode.app')
xcode.version.call
expect(xcode.version).to eq '9.3'
expect(xcode.version.call).to eq '9.3'
end
it 'returns the name of Xcode 9 when initialized with the semantic version' do
xcode = MacOS::Xcode.new('9.0', '/Applications/Xcode.app')
xcode.version.call
expect(xcode.version).to eq '9'
expect(xcode.version.call).to eq '9'
end
it 'returns the name of Xcode 8.3.3 when initialized with the semantic version' do
xcode = MacOS::Xcode.new('8.3.3', '/Applications/Xcode.app')
xcode.version.call
expect(xcode.version).to eq '8.3.3'
expect(xcode.version.call).to eq '8.3.3'
end
it 'correctly determines platform compatibility for Xcode 11' do
xcode = MacOS::Xcode.new('11.0', '/Applications/Xcode.app')
@ -212,14 +203,12 @@ describe MacOS::Xcode do
it 'ignores the Apple version list and uses the provided version' do
xcode = MacOS::Xcode.new('0.0', '/Applications/Xcode.app', 'https://www.apple.com')
xcode.version.call
expect(xcode.version).to eq '0.0'
expect(xcode.version.call).to eq '0.0'
end
it 'ignores the Apple version list and uses the provided version' do
xcode = MacOS::Xcode.new('2', '/Applications/Xcode.app', 'https://www.apple.com')
xcode.version.call
expect(xcode.version).to eq '2'
expect(xcode.version.call).to eq '2'
end
end
end