Skip to content

Commit 378c4d7

Browse files
[MacOS] improve errexit option handling (#8432)
* [MacOS] improve errexit option handling * Prevent prompting for override when unzipping * Explicitly allow failing when installing virtualbox * Remove libtcl symlinks * Add debug output
1 parent fc9431c commit 378c4d7

File tree

5 files changed

+26
-18
lines changed

5 files changed

+26
-18
lines changed

images/macos/provision/core/android-toolsets.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ sdkTools="android-sdk-tools.zip"
126126
sdkToolsVersion=$(get_toolset_value '.android."sdk-tools"')
127127
if [ "$sdkToolsVersion" != "null" ]; then
128128
download_with_retries "https://dl.google.com/android/repository/${sdkToolsVersion}" "." $sdkTools
129-
unzip -qq $sdkTools -d ${ANDROID_SDK_ROOT}
129+
unzip -o -qq $sdkTools -d ${ANDROID_SDK_ROOT}
130130
rm -f $sdkTools
131131
fi
132132

images/macos/provision/core/commonutils.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ fi
3636
# System Preferences -> Security & Privacy -> General -> Unlock -> Allow -> Not now
3737
if is_Monterey; then
3838
if is_Veertu; then
39+
echo "Executing AppleScript to change security preferences (with retries)"
3940
retry=5
4041
while [ $retry -gt 0 ]; do
4142
{
@@ -48,6 +49,7 @@ if is_Monterey; then
4849
sleep 10
4950
done
5051
else
52+
echo "Executing AppleScript to change security preferences"
5153
osascript $HOME/utils/confirm-identified-developers.scpt $USER_PASSWORD
5254
fi
5355
fi
@@ -82,13 +84,5 @@ bazel
8284
# Install Azure DevOps extension for Azure Command Line Interface
8385
az extension add -n azure-devops
8486

85-
# Workaround https://github.com/actions/runner-images/issues/4931
86-
# by making Tcl/Tk paths the same on macOS 10.15 and macOS 11
87-
if is_Monterey; then
88-
version=$(brew info tcl-tk --json | jq -r '.[].installed[].version')
89-
ln -s /usr/local/Cellar/tcl-tk/$version/lib/libtcl8.6.dylib /usr/local/lib/libtcl8.6.dylib
90-
ln -s /usr/local/Cellar/tcl-tk/$version/lib/libtk8.6.dylib /usr/local/lib/libtk8.6.dylib
91-
fi
92-
9387
# Invoke tests for all basic tools
9488
invoke_tests "BasicTools"

images/macos/provision/core/pypy.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function InstallPyPy
1111
PACKAGE_URL=$1
1212

1313
PACKAGE_TAR_NAME=$(echo $PACKAGE_URL | awk -F/ '{print $NF}')
14-
echo "Downloading tar archive '$PACKAGE_TAR_NAME' - '$PACKAGE_URL'"
14+
echo "Downloading tar archive '$PACKAGE_TAR_NAME'"
1515
PACKAGE_TAR_TEMP_PATH="/tmp/$PACKAGE_TAR_NAME"
1616
download_with_retries $PACKAGE_URL "/tmp" "$PACKAGE_TAR_NAME"
1717

@@ -89,4 +89,4 @@ for toolsetVersion in $toolsetVersions; do
8989
exit 1
9090
fi
9191
InstallPyPy $latestMajorPyPyVersion
92-
done
92+
done

images/macos/provision/utils/utils.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,31 @@ download_with_retries() {
1515
local COMMAND="curl $URL -4 -sL -o '$DEST/$NAME' -w '%{http_code}'"
1616
fi
1717

18+
# Save current errexit state and disable it to prevent unexpected exit on error
19+
if echo $SHELLOPTS | grep '\(^\|:\)errexit\(:\|$\)' > /dev/null;
20+
then
21+
local ERR_EXIT_ENABLED=true
22+
else
23+
local ERR_EXIT_ENABLED=false
24+
fi
25+
set +e
26+
1827
echo "Downloading '$URL' to '${DEST}/${NAME}'..."
1928
retries=20
2029
interval=30
2130
while [ $retries -gt 0 ]; do
2231
((retries--))
23-
# Temporary disable exit on error to retry on non-zero exit code
24-
set +e
32+
test "$ERR_EXIT_ENABLED" = true && set +e
2533
http_code=$(eval $COMMAND)
2634
exit_code=$?
35+
test "$ERR_EXIT_ENABLED" = true && set -e
2736
if [ $http_code -eq 200 ] && [ $exit_code -eq 0 ]; then
2837
echo "Download completed"
2938
return 0
3039
else
3140
echo "Error — Either HTTP response code for '$URL' is wrong - '$http_code' or exit code is not 0 - '$exit_code'. Waiting $interval seconds before the next attempt, $retries attempts left"
3241
sleep 30
3342
fi
34-
# Enable exit on error back
35-
set -e
3643
done
3744

3845
echo "Could not download $URL"

images/macos/tests/BasicTools.Tests.ps1

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ Describe "Helm" -Skip:($os.IsMonterey -or $os.IsVentura -or $os.IsVenturaArm64)
6767
}
6868
}
6969

70+
Describe "Tcl/Tk" {
71+
It "libtcl" {
72+
"file /usr/local/lib/libtcl8.6.dylib" | Should -ReturnZeroExitCode
73+
"file /usr/local/lib/libtk8.6.dylib" | Should -ReturnZeroExitCode
74+
}
75+
}
76+
7077
Describe "bazelisk" {
7178
It "bazelisk" {
7279
"bazelisk version" | Should -ReturnZeroExitCode
@@ -164,9 +171,9 @@ Describe "Homebrew" {
164171
}
165172

166173
Describe "Kotlin" {
167-
$kotlinPackages = @("kapt", "kotlin", "kotlinc", "kotlinc-jvm", "kotlin-dce-js")
174+
$kotlinPackages = @("kapt", "kotlin", "kotlinc", "kotlinc-jvm", "kotlin-dce-js")
168175

169-
It "<toolName> is available" -TestCases ($kotlinPackages | ForEach-Object { @{ toolName = $_ } }) {
176+
It "<toolName> is available" -TestCases ($kotlinPackages | ForEach-Object { @{ toolName = $_ } }) {
170177
"$toolName -version" | Should -ReturnZeroExitCode
171178
}
172179
}
@@ -187,4 +194,4 @@ Describe "imagemagick" -Skip:($os.IsVentura -or $os.IsVenturaArm64) {
187194
It "imagemagick" {
188195
"magick -version" | Should -ReturnZeroExitCode
189196
}
190-
}
197+
}

0 commit comments

Comments
 (0)