Skip to content
This repository was archived by the owner on Dec 24, 2020. It is now read-only.

Commit 8431a13

Browse files
committed
Migrate to the latest KoreBuild version
1 parent 5a90716 commit 8431a13

File tree

7 files changed

+451
-46
lines changed

7 files changed

+451
-46
lines changed

AspNet.Security.OAuth.Extensions.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
44
VisualStudioVersion = 15.0.26228.4
55
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{2CFA7432-2FA7-4CF3-87DC-217C1363E11D}"
7+
ProjectSection(SolutionItems) = preProject
8+
build\common.props = build\common.props
9+
build\dependencies.props = build\dependencies.props
10+
build\key.snk = build\key.snk
11+
build\packages.props = build\packages.props
12+
build\repo.props = build\repo.props
13+
build\tests.props = build\tests.props
14+
build\version.props = build\version.props
15+
EndProjectSection
16+
EndProject
617
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7AADF737-9B13-4E5C-8F32-8BF21429E093}"
718
EndProject
819
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{2B1B08E0-E9A3-40C0-B200-DE09952AF0E7}"
@@ -75,4 +86,7 @@ Global
7586
{719AF040-773B-4DA5-B53E-28B26D1121FF} = {7AADF737-9B13-4E5C-8F32-8BF21429E093}
7687
{6DC60DCF-B34B-4F14-9E73-BE466059A9B2} = {2B1B08E0-E9A3-40C0-B200-DE09952AF0E7}
7788
EndGlobalSection
89+
GlobalSection(ExtensibilityGlobals) = postSolution
90+
SolutionGuid = {7DD610CB-5D2D-4AEB-B5D3-4DEEB694AA36}
91+
EndGlobalSection
7892
EndGlobal

build.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
@ECHO OFF
2-
PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0build.ps1' %*; exit $LASTEXITCODE"
2+
PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0run.ps1' default-build %*; exit $LASTEXITCODE"

build.sh

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,8 @@
11
#!/usr/bin/env bash
2-
repoFolder="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3-
cd $repoFolder
42

5-
koreBuildZip="https://github.com/aspnet/KoreBuild/archive/dev.zip"
6-
if [ ! -z $KOREBUILD_ZIP ]; then
7-
koreBuildZip=$KOREBUILD_ZIP
8-
fi
3+
set -euo pipefail
4+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
95

10-
buildFolder=".build"
11-
buildFile="$buildFolder/KoreBuild.sh"
12-
13-
if test ! -d $buildFolder; then
14-
echo "Downloading KoreBuild from $koreBuildZip"
15-
16-
tempFolder="/tmp/KoreBuild-$(uuidgen)"
17-
mkdir $tempFolder
18-
19-
localZipFile="$tempFolder/korebuild.zip"
20-
21-
retries=6
22-
until (wget -O $localZipFile $koreBuildZip 2>/dev/null || curl -o $localZipFile --location $koreBuildZip 2>/dev/null)
23-
do
24-
echo "Failed to download '$koreBuildZip'"
25-
if [ "$retries" -le 0 ]; then
26-
exit 1
27-
fi
28-
retries=$((retries - 1))
29-
echo "Waiting 10 seconds before retrying. Retries left: $retries"
30-
sleep 10s
31-
done
32-
33-
unzip -q -d $tempFolder $localZipFile
34-
35-
mkdir $buildFolder
36-
cp -r $tempFolder/**/build/** $buildFolder
37-
38-
chmod +x $buildFile
39-
40-
# Cleanup
41-
if test -d $tempFolder; then
42-
rm -rf $tempFolder
43-
fi
44-
fi
45-
46-
$buildFile -r $repoFolder "$@"
6+
# Call "sync" between "chmod" and execution to prevent "text file busy" error in Docker (aufs)
7+
chmod +x "$DIR/run.sh"; sync
8+
"$DIR/run.sh" default-build "$@"

build/dependencies.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22

3-
<PropertyGroup>
3+
<PropertyGroup Label="Package Versions">
44
<AspNetCoreVersion>2.0.0</AspNetCoreVersion>
55
<CoreFxVersion>4.4.0</CoreFxVersion>
66
<IdentityModelVersion>5.2.0-preview1-408290725</IdentityModelVersion>
@@ -14,7 +14,7 @@
1414
<OwinVersion>4.0.0-alpha1</OwinVersion>
1515
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
1616
<TestSdkVersion>15.3.0</TestSdkVersion>
17-
<XunitVersion>2.3.0-*</XunitVersion>
17+
<XunitVersion>2.3.1</XunitVersion>
1818
</PropertyGroup>
1919

2020
</Project>

run.cmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@ECHO OFF
2+
PowerShell -NoProfile -NoLogo -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%~dp0run.ps1' %*; exit $LASTEXITCODE"

run.ps1

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
#!/usr/bin/env powershell
2+
#requires -version 4
3+
4+
<#
5+
.SYNOPSIS
6+
Executes KoreBuild commands.
7+
8+
.DESCRIPTION
9+
Downloads korebuild if required. Then executes the KoreBuild command. To see available commands, execute with `-Command help`.
10+
11+
.PARAMETER Command
12+
The KoreBuild command to run.
13+
14+
.PARAMETER Path
15+
The folder to build. Defaults to the folder containing this script.
16+
17+
.PARAMETER Channel
18+
The channel of KoreBuild to download. Overrides the value from the config file.
19+
20+
.PARAMETER DotNetHome
21+
The directory where .NET Core tools will be stored.
22+
23+
.PARAMETER ToolsSource
24+
The base url where build tools can be downloaded. Overrides the value from the config file.
25+
26+
.PARAMETER Update
27+
Updates KoreBuild to the latest version even if a lock file is present.
28+
29+
.PARAMETER ConfigFile
30+
The path to the configuration file that stores values. Defaults to korebuild.json.
31+
32+
.PARAMETER ToolsSourceSuffix
33+
The Suffix to append to the end of the ToolsSource. Useful for query strings in blob stores.
34+
35+
.PARAMETER Arguments
36+
Arguments to be passed to the command
37+
38+
.NOTES
39+
This function will create a file $PSScriptRoot/korebuild-lock.txt. This lock file can be committed to source, but does not have to be.
40+
When the lockfile is not present, KoreBuild will create one using latest available version from $Channel.
41+
42+
The $ConfigFile is expected to be an JSON file. It is optional, and the configuration values in it are optional as well. Any options set
43+
in the file are overridden by command line parameters.
44+
45+
.EXAMPLE
46+
Example config file:
47+
```json
48+
{
49+
"$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/dev/tools/korebuild.schema.json",
50+
"channel": "dev",
51+
"toolsSource": "https://aspnetcore.blob.core.windows.net/buildtools"
52+
}
53+
```
54+
#>
55+
[CmdletBinding(PositionalBinding = $false)]
56+
param(
57+
[Parameter(Mandatory = $true, Position = 0)]
58+
[string]$Command,
59+
[string]$Path = $PSScriptRoot,
60+
[Alias('c')]
61+
[string]$Channel,
62+
[Alias('d')]
63+
[string]$DotNetHome,
64+
[Alias('s')]
65+
[string]$ToolsSource,
66+
[Alias('u')]
67+
[switch]$Update,
68+
[string]$ConfigFile,
69+
[string]$ToolsSourceSuffix,
70+
[Parameter(ValueFromRemainingArguments = $true)]
71+
[string[]]$Arguments
72+
)
73+
74+
Set-StrictMode -Version 2
75+
$ErrorActionPreference = 'Stop'
76+
77+
#
78+
# Functions
79+
#
80+
81+
function Get-KoreBuild {
82+
83+
$lockFile = Join-Path $Path 'korebuild-lock.txt'
84+
85+
if (!(Test-Path $lockFile) -or $Update) {
86+
Get-RemoteFile "$ToolsSource/korebuild/channels/$Channel/latest.txt" $lockFile $ToolsSourceSuffix
87+
}
88+
89+
$version = Get-Content $lockFile | Where-Object { $_ -like 'version:*' } | Select-Object -first 1
90+
if (!$version) {
91+
Write-Error "Failed to parse version from $lockFile. Expected a line that begins with 'version:'"
92+
}
93+
$version = $version.TrimStart('version:').Trim()
94+
$korebuildPath = Join-Paths $DotNetHome ('buildtools', 'korebuild', $version)
95+
96+
if (!(Test-Path $korebuildPath)) {
97+
Write-Host -ForegroundColor Magenta "Downloading KoreBuild $version"
98+
New-Item -ItemType Directory -Path $korebuildPath | Out-Null
99+
$remotePath = "$ToolsSource/korebuild/artifacts/$version/korebuild.$version.zip"
100+
101+
try {
102+
$tmpfile = Join-Path ([IO.Path]::GetTempPath()) "KoreBuild-$([guid]::NewGuid()).zip"
103+
Get-RemoteFile $remotePath $tmpfile $ToolsSourceSuffix
104+
if (Get-Command -Name 'Expand-Archive' -ErrorAction Ignore) {
105+
# Use built-in commands where possible as they are cross-plat compatible
106+
Expand-Archive -Path $tmpfile -DestinationPath $korebuildPath
107+
}
108+
else {
109+
# Fallback to old approach for old installations of PowerShell
110+
Add-Type -AssemblyName System.IO.Compression.FileSystem
111+
[System.IO.Compression.ZipFile]::ExtractToDirectory($tmpfile, $korebuildPath)
112+
}
113+
}
114+
catch {
115+
Remove-Item -Recurse -Force $korebuildPath -ErrorAction Ignore
116+
throw
117+
}
118+
finally {
119+
Remove-Item $tmpfile -ErrorAction Ignore
120+
}
121+
}
122+
123+
return $korebuildPath
124+
}
125+
126+
function Join-Paths([string]$path, [string[]]$childPaths) {
127+
$childPaths | ForEach-Object { $path = Join-Path $path $_ }
128+
return $path
129+
}
130+
131+
function Get-RemoteFile([string]$RemotePath, [string]$LocalPath, [string]$RemoteSuffix) {
132+
if ($RemotePath -notlike 'http*') {
133+
Copy-Item $RemotePath $LocalPath
134+
return
135+
}
136+
137+
$retries = 10
138+
while ($retries -gt 0) {
139+
$retries -= 1
140+
try {
141+
Invoke-WebRequest -UseBasicParsing -Uri $($RemotePath + $RemoteSuffix) -OutFile $LocalPath
142+
return
143+
}
144+
catch {
145+
Write-Verbose "Request failed. $retries retries remaining"
146+
}
147+
}
148+
149+
Write-Error "Download failed: '$RemotePath'."
150+
}
151+
152+
#
153+
# Main
154+
#
155+
156+
# Load configuration or set defaults
157+
158+
$Path = Resolve-Path $Path
159+
if (!$ConfigFile) { $ConfigFile = Join-Path $Path 'korebuild.json' }
160+
161+
if (Test-Path $ConfigFile) {
162+
try {
163+
$config = Get-Content -Raw -Encoding UTF8 -Path $ConfigFile | ConvertFrom-Json
164+
if ($config) {
165+
if (!($Channel) -and (Get-Member -Name 'channel' -InputObject $config)) { [string] $Channel = $config.channel }
166+
if (!($ToolsSource) -and (Get-Member -Name 'toolsSource' -InputObject $config)) { [string] $ToolsSource = $config.toolsSource}
167+
}
168+
}
169+
catch {
170+
Write-Warning "$ConfigFile could not be read. Its settings will be ignored."
171+
Write-Warning $Error[0]
172+
}
173+
}
174+
175+
if (!$DotNetHome) {
176+
$DotNetHome = if ($env:DOTNET_HOME) { $env:DOTNET_HOME } `
177+
elseif ($env:USERPROFILE) { Join-Path $env:USERPROFILE '.dotnet'} `
178+
elseif ($env:HOME) {Join-Path $env:HOME '.dotnet'}`
179+
else { Join-Path $PSScriptRoot '.dotnet'}
180+
}
181+
182+
if (!$Channel) { $Channel = 'dev' }
183+
if (!$ToolsSource) { $ToolsSource = 'https://aspnetcore.blob.core.windows.net/buildtools' }
184+
185+
# Execute
186+
187+
$korebuildPath = Get-KoreBuild
188+
Import-Module -Force -Scope Local (Join-Path $korebuildPath 'KoreBuild.psd1')
189+
190+
try {
191+
Set-KoreBuildSettings -ToolsSource $ToolsSource -DotNetHome $DotNetHome -RepoPath $Path -ConfigFile $ConfigFile
192+
Invoke-KoreBuildCommand $Command @Arguments
193+
}
194+
finally {
195+
Remove-Module 'KoreBuild' -ErrorAction Ignore
196+
}

0 commit comments

Comments
 (0)