Skip to content

Commit

Permalink
Change RubyGems installation to use toolset (actions#3474)
Browse files Browse the repository at this point in the history
  • Loading branch information
miketimofeev authored May 29, 2021
1 parent cfbaf5f commit 5898c5e
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 46 deletions.
32 changes: 32 additions & 0 deletions images/macos/helpers/Tests.Helpers.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,40 @@ function ShouldReturnZeroExitCode {
}
}

function ShouldMatchCommandOutput {
Param(
[String] $ActualValue,
[String] $RegularExpression,
[switch] $Negate
)

$output = (Get-CommandResult $ActualValue).Output | Out-String
[bool] $succeeded = $output -cmatch $RegularExpression

if ($Negate) {
$succeeded = -not $succeeded
}

$failureMessage = ''

if (-not $succeeded) {
if ($Negate) {
$failureMessage = "Expected regular expression '$RegularExpression' for '$ActualValue' command to not match '$output', but it did match."
}
else {
$failureMessage = "Expected regular expression '$RegularExpression' for '$ActualValue' command to match '$output', but it did not match."
}
}

return [PSCustomObject] @{
Succeeded = $succeeded
FailureMessage = $failureMessage
}
}

If (Get-Command -Name Add-ShouldOperator -ErrorAction SilentlyContinue) {
Add-ShouldOperator -Name ReturnZeroExitCode -InternalName ShouldReturnZeroExitCode -Test ${function:ShouldReturnZeroExitCode}
Add-ShouldOperator -Name MatchCommandOutput -InternalName ShouldMatchCommandOutput -Test ${function:ShouldMatchCommandOutput}
}

function Invoke-PesterTests {
Expand Down
33 changes: 6 additions & 27 deletions images/macos/provision/core/rubygem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,12 @@ source ~/utils/utils.sh
echo Updating RubyGems...
gem update --system

echo Installing xcode-install utility...
gem install xcode-install --force

echo Installing CocoaPods...
gem install cocoapods

if is_Less_BigSur; then
# fix nomad-cli installation
if is_HighSierra; then
brew_smart_install "libxml2"
gem install nokogiri -v 1.6.8.1 -- --use-system-libraries --with-xml2-include=$(brew --prefix libxml2)/include/libxml2
fi

echo Installing nomad-cli...
gem install nomad-cli
gemsToInstall=$(get_toolset_value ".rubygems[]")
if [ -n "$gemsToInstall" ]; then
for gem in $gemsToInstall; do
echo "Installing gem $gem"
gem install $gem
done
fi

echo Installing xcpretty...
gem install xcpretty

echo Installing bundler...
gem install bundler --force

# AppStoreRelease Azure DevOps has issues with Fastlane 2.184.0. Temporary hardcoding the version until the issue is fixed
# https://github.com/microsoft/app-store-vsts-extension/issues/244
echo Installing fastlane tools...
gem uninstall fastlane -aI
gem install fastlane -v 2.183.2

invoke_tests "RubyGem"
13 changes: 9 additions & 4 deletions images/macos/software-report/SoftwareReport.Xcode.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,18 @@ function Build-XcodeSupportToolsSection {
"xcversion $xcversion"
)

$nomadOutput = Run-Command "gem list nomad-cli"
$nomadCLI = [regex]::matches($nomadOutput, "(\d+.){2}\d+").Value
$nomadShenzhenOutput = Run-Command "ipa -version"
$nomadShenzhen = [regex]::matches($nomadShenzhenOutput, "(\d+.){2}\d+").Value
$toolList += @(
"Nomad CLI $nomadCLI",
"Nomad shenzhen CLI $nomadShenzhen"
)

if ($os.IsLessThanBigSur) {
$nomadCLI = Run-Command "gem -v nomad-cli"
$nomadIPA = Run-Command "ipa -version"
$xctool = Run-Command "xctool --version"
$toolList += @(
"Nomad CLI $nomadCLI",
"Nomad CLI IPA $nomadIPA",
"xctool $xctool"
)
}
Expand Down
27 changes: 15 additions & 12 deletions images/macos/tests/RubyGem.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
$os = Get-OSVersion
Describe "RubyGems" {
$gemTestCases = Get-ToolsetValue -KeyPath "rubygems" | ForEach-Object {
@{gemName = $_}
}

if ($gemTestCases)
{
It "Gem <gemName> is installed" -TestCases $gemTestCases {
"gem list -i '^$gemName$'" | Should -MatchCommandOutput "true"
}
}
}

Describe "Bundler" {
It "Bundler" {
"bundler --version" | Should -ReturnZeroExitCode
}
}

Describe "Nomad" -Skip:($os.IsBigSur) {
Context "Nomad" {
It "Nomad CLI" {
$result = Get-CommandResult "gem list"
$result.Output | Should -BeLike "*nomad-cli*"
}
}
Context "Nomad CLI" {
It "Nomad CLI IPA" {
"ipa --version" | Should -ReturnZeroExitCode
}
Describe "Nomad shenzhen CLI" {
It "Nomad shenzhen CLI" {
"ipa --version" | Should -ReturnZeroExitCode
}
}

Expand Down
10 changes: 9 additions & 1 deletion images/macos/toolsets/toolset-10.14.json
Original file line number Diff line number Diff line change
Expand Up @@ -339,5 +339,13 @@
"versions": [
"2.1"
]
}
},
"rubygems": [
"xcode-install",
"cocoapods",
"nomad-cli",
"xcpretty",
"bundler",
"fastlane"
]
}
10 changes: 9 additions & 1 deletion images/macos/toolsets/toolset-10.15.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,5 +294,13 @@
"3.1",
"5.0"
]
}
},
"rubygems": [
"xcode-install",
"cocoapods",
"nomad-cli",
"xcpretty",
"bundler",
"fastlane"
]
}
10 changes: 9 additions & 1 deletion images/macos/toolsets/toolset-11.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,13 @@
"3.1",
"5.0"
]
}
},
"rubygems": [
"xcode-install",
"cocoapods",
"nomad-cli",
"xcpretty",
"bundler",
"fastlane"
]
}

0 comments on commit 5898c5e

Please sign in to comment.