From fadeb7394a95602736796946d99e8cfdbc7e47c9 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 20 Dec 2017 11:55:18 -0800 Subject: [PATCH] Add more bash magic to our script to avoid issues with unset and unbound variables --- build/tasks/Utilities/ArtifactInfo.cs | 8 ++++++++ run.sh | 25 ++++++++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/build/tasks/Utilities/ArtifactInfo.cs b/build/tasks/Utilities/ArtifactInfo.cs index 6e35289a3b..c03cdacefb 100644 --- a/build/tasks/Utilities/ArtifactInfo.cs +++ b/build/tasks/Utilities/ArtifactInfo.cs @@ -26,6 +26,9 @@ namespace RepoTasks.Utilities case "nugetsymbolspackage": info = new Package { PackageInfo = GetPackageInfo(item), IsSymbolsArtifact = true }; break; + case "vsixpackage": + info = new Vsix { Name = Path.GetFileNameWithoutExtension(item.ItemSpec) }; + break; default: throw new InvalidDataException($"Unrecognized artifact type: {item.GetMetadata("ArtifactType")} for artifact {item.ItemSpec}"); } @@ -43,6 +46,11 @@ namespace RepoTasks.Utilities public string RepositoryRoot { get; private set; } public string RepoName { get; private set; } + public class Vsix : ArtifactInfo + { + public string Name { get; set; } + } + public class Package : ArtifactInfo { public PackageInfo PackageInfo { get; set; } diff --git a/run.sh b/run.sh index cd5ec2d3d6..8f861cf149 100755 --- a/run.sh +++ b/run.sh @@ -180,23 +180,27 @@ while [[ $# -gt 0 ]]; do ;; --package-version-props-url|-PackageVersionPropsUrl) shift - package_version_props_url="${1:-}" - [ -z "$package_version_props_url" ] && __error "Missing value for parameter --package-version-props-url" && __usage + # This parameter can be an empty string, but it should be set + [ -z "${1+x}" ] && __error "Missing value for parameter --package-version-props-url" && __usage + package_version_props_url="$1" ;; --access-token-suffix|-AccessTokenSuffix) shift - access_token_suffix="${1:-}" - # This suffix can be empty + # This parameter can be an empty string, but it should be set + [ -z "${1+x}" ] && __error "Missing value for parameter --access-token-suffix" && __usage + access_token_suffix="$1" ;; --restore-sources|-RestoreSources) shift - restore_sources="${1:-}" - [ -z "$restore_sources" ] && __error "Missing value for parameter --restore-sources" && __usage + # This parameter can be an empty string, but it should be set + [ -z "${1+x}" ] && __error "Missing value for parameter --restore-sources" && __usage + restore_sources="$1" ;; --asset-root-url|-AssetRootUrl) shift - asset_root_url="${1:-}" - [ -z "$asset_root_url" ] && __error "Missing value for parameter --asset-root-url" && __usage + # This parameter can be an empty string, but it should be set + [ -z "${1+x}" ] && __error "Missing value for parameter --asset-root-url" && __usage + asset_root_url="$1" ;; -u|--update|-Update) update=true @@ -273,4 +277,7 @@ fi get_korebuild set_korebuildsettings "$tools_source" "$DOTNET_HOME" "$repo_path" "$config_file" -invoke_korebuild_command "$command" "${msbuild_args[@]}" + +# This incantation avoids unbound variable issues if msbuild_args is empty +# https://stackoverflow.com/questions/7577052/bash-empty-array-expansion-with-set-u +invoke_korebuild_command "$command" ${msbuild_args[@]+"${msbuild_args[@]}"}