Skip to content

Commit 98c47a1

Browse files
author
Nate McMaster (automated)
committed
Update bootstrapper scripts (automated commit) [ci skip]
1 parent 0a1c83a commit 98c47a1

File tree

2 files changed

+48
-10
lines changed

2 files changed

+48
-10
lines changed

run.ps1

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@ The base url where build tools can be downloaded. Overrides the value from the c
2626
.PARAMETER Update
2727
Updates KoreBuild to the latest version even if a lock file is present.
2828
29+
.PARAMETER Reinstall
30+
Re-installs KoreBuild
31+
2932
.PARAMETER ConfigFile
3033
The path to the configuration file that stores values. Defaults to korebuild.json.
3134
3235
.PARAMETER ToolsSourceSuffix
3336
The Suffix to append to the end of the ToolsSource. Useful for query strings in blob stores.
3437
38+
.PARAMETER CI
39+
Sets up CI specific settings and variables.
40+
3541
.PARAMETER Arguments
3642
Arguments to be passed to the command
3743
@@ -65,8 +71,10 @@ param(
6571
[string]$ToolsSource,
6672
[Alias('u')]
6773
[switch]$Update,
68-
[string]$ConfigFile,
74+
[switch]$Reinstall,
6975
[string]$ToolsSourceSuffix,
76+
[string]$ConfigFile = $null,
77+
[switch]$CI,
7078
[Parameter(ValueFromRemainingArguments = $true)]
7179
[string[]]$Arguments
7280
)
@@ -93,6 +101,10 @@ function Get-KoreBuild {
93101
$version = $version.TrimStart('version:').Trim()
94102
$korebuildPath = Join-Paths $DotNetHome ('buildtools', 'korebuild', $version)
95103

104+
if ($Reinstall -and (Test-Path $korebuildPath)) {
105+
Remove-Item -Force -Recurse $korebuildPath
106+
}
107+
96108
if (!(Test-Path $korebuildPath)) {
97109
Write-Host -ForegroundColor Magenta "Downloading KoreBuild $version"
98110
New-Item -ItemType Directory -Path $korebuildPath | Out-Null
@@ -101,9 +113,9 @@ function Get-KoreBuild {
101113
try {
102114
$tmpfile = Join-Path ([IO.Path]::GetTempPath()) "KoreBuild-$([guid]::NewGuid()).zip"
103115
Get-RemoteFile $remotePath $tmpfile $ToolsSourceSuffix
104-
if (Get-Command -Name 'Expand-Archive' -ErrorAction Ignore) {
116+
if (Get-Command -Name 'Microsoft.PowerShell.Archive\Expand-Archive' -ErrorAction Ignore) {
105117
# Use built-in commands where possible as they are cross-plat compatible
106-
Expand-Archive -Path $tmpfile -DestinationPath $korebuildPath
118+
Microsoft.PowerShell.Archive\Expand-Archive -Path $tmpfile -DestinationPath $korebuildPath
107119
}
108120
else {
109121
# Fallback to old approach for old installations of PowerShell
@@ -167,8 +179,9 @@ if (Test-Path $ConfigFile) {
167179
}
168180
}
169181
catch {
170-
Write-Warning "$ConfigFile could not be read. Its settings will be ignored."
171-
Write-Warning $Error[0]
182+
Write-Host -ForegroundColor Red $Error[0]
183+
Write-Error "$ConfigFile contains invalid JSON."
184+
exit 1
172185
}
173186
}
174187

@@ -188,7 +201,7 @@ $korebuildPath = Get-KoreBuild
188201
Import-Module -Force -Scope Local (Join-Path $korebuildPath 'KoreBuild.psd1')
189202

190203
try {
191-
Set-KoreBuildSettings -ToolsSource $ToolsSource -DotNetHome $DotNetHome -RepoPath $Path -ConfigFile $ConfigFile
204+
Set-KoreBuildSettings -ToolsSource $ToolsSource -DotNetHome $DotNetHome -RepoPath $Path -ConfigFile $ConfigFile -CI:$CI
192205
Invoke-KoreBuildCommand $Command @Arguments
193206
}
194207
finally {

run.sh

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1414
[ -z "${DOTNET_HOME:-}" ] && DOTNET_HOME="$HOME/.dotnet"
1515
verbose=false
1616
update=false
17+
reinstall=false
1718
repo_path="$DIR"
1819
channel=''
1920
tools_source=''
2021
tools_source_suffix=''
22+
ci=false
2123

2224
#
2325
# Functions
@@ -38,6 +40,8 @@ __usage() {
3840
echo " -s|--tools-source|-ToolsSource <URL> The base url where build tools can be downloaded. Overrides the value from the config file."
3941
echo " --tools-source-suffix|-ToolsSourceSuffix <SUFFIX> The suffix to append to tools-source. Useful for query strings."
4042
echo " -u|--update Update to the latest KoreBuild even if the lock file is present."
43+
echo " --reinstall Reinstall KoreBuild."
44+
echo " --ci Apply CI specific settings and environment variables."
4145
echo ""
4246
echo "Description:"
4347
echo " This function will create a file \$DIR/korebuild-lock.txt. This lock file can be committed to source, but does not have to be."
@@ -62,6 +66,10 @@ get_korebuild() {
6266
version="$(echo "${version#version:}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
6367
local korebuild_path="$DOTNET_HOME/buildtools/korebuild/$version"
6468

69+
if [ "$reinstall" = true ] && [ -d "$korebuild_path" ]; then
70+
rm -rf "$korebuild_path"
71+
fi
72+
6573
{
6674
if [ ! -d "$korebuild_path" ]; then
6775
mkdir -p "$korebuild_path"
@@ -175,6 +183,12 @@ while [[ $# -gt 0 ]]; do
175183
-u|--update|-Update)
176184
update=true
177185
;;
186+
--reinstall|-[Rr]einstall)
187+
reinstall=true
188+
;;
189+
--ci|-[Cc][Ii])
190+
ci=true
191+
;;
178192
--verbose|-Verbose)
179193
verbose=true
180194
;;
@@ -206,17 +220,28 @@ if [ -f "$config_file" ]; then
206220
config_channel="$(jq -r 'select(.channel!=null) | .channel' "$config_file")"
207221
config_tools_source="$(jq -r 'select(.toolsSource!=null) | .toolsSource' "$config_file")"
208222
else
209-
__warn "$config_file is invalid JSON. Its settings will be ignored."
223+
_error "$config_file contains invalid JSON."
224+
exit 1
210225
fi
211226
elif __machine_has python ; then
212227
if python -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'))" >/dev/null ; then
213228
config_channel="$(python -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'));print(obj['channel'] if 'channel' in obj else '')")"
214229
config_tools_source="$(python -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'));print(obj['toolsSource'] if 'toolsSource' in obj else '')")"
215230
else
216-
__warn "$config_file is invalid JSON. Its settings will be ignored."
231+
_error "$config_file contains invalid JSON."
232+
exit 1
233+
fi
234+
elif __machine_has python3 ; then
235+
if python3 -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'))" >/dev/null ; then
236+
config_channel="$(python3 -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'));print(obj['channel'] if 'channel' in obj else '')")"
237+
config_tools_source="$(python3 -c "import json,codecs;obj=json.load(codecs.open('$config_file', 'r', 'utf-8-sig'));print(obj['toolsSource'] if 'toolsSource' in obj else '')")"
238+
else
239+
_error "$config_file contains invalid JSON."
240+
exit 1
217241
fi
218242
else
219-
__warn 'Missing required command: jq or pyton. Could not parse the JSON file. Its settings will be ignored.'
243+
_error 'Missing required command: jq or python. Could not parse the JSON file.'
244+
exit 1
220245
fi
221246

222247
[ ! -z "${config_channel:-}" ] && channel="$config_channel"
@@ -227,5 +252,5 @@ fi
227252
[ -z "$tools_source" ] && tools_source='https://aspnetcore.blob.core.windows.net/buildtools'
228253

229254
get_korebuild
230-
set_korebuildsettings "$tools_source" "$DOTNET_HOME" "$repo_path" "$config_file"
255+
set_korebuildsettings "$tools_source" "$DOTNET_HOME" "$repo_path" "$config_file" "$ci"
231256
invoke_korebuild_command "$command" "$@"

0 commit comments

Comments
 (0)