|
1 | | -######################## |
2 | | -# FUNCTIONS |
3 | | -######################## |
4 | | -function Install-Dnvm |
5 | | -{ |
6 | | - & where.exe dnvm 2>&1 | Out-Null |
7 | | - if(($LASTEXITCODE -ne 0) -Or ((Test-Path Env:\APPVEYOR) -eq $true)) |
8 | | - { |
9 | | - Write-Host "DNVM not found" |
10 | | - &{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))} |
11 | | - |
12 | | - # Normally this happens automatically during install but AppVeyor has |
13 | | - # an issue where you may need to manually re-run setup from within this process. |
14 | | - if($env:DNX_HOME -eq $NULL) |
15 | | - { |
16 | | - Write-Host "Initial DNVM environment setup failed; running manual setup" |
17 | | - $tempDnvmPath = Join-Path $env:TEMP "dnvminstall" |
18 | | - $dnvmSetupCmdPath = Join-Path $tempDnvmPath "dnvm.ps1" |
19 | | - & $dnvmSetupCmdPath setup |
20 | | - } |
21 | | - } |
22 | | -} |
23 | | - |
24 | | -function Get-DnxVersion |
25 | | -{ |
26 | | - $globalJson = join-path $PSScriptRoot "global.json" |
27 | | - $jsonData = Get-Content -Path $globalJson -Raw | ConvertFrom-JSON |
28 | | - return $jsonData.sdk.version |
29 | | -} |
30 | | - |
31 | | -function Restore-Packages |
32 | | -{ |
33 | | - param([string] $DirectoryName) |
34 | | - & dnu restore ("""" + $DirectoryName + """") |
35 | | -} |
36 | | - |
37 | | -function Build-Project |
38 | | -{ |
39 | | - param([string] $DirectoryName) |
40 | | - & dnu build ("""" + $DirectoryName + """") --configuration Release; if($LASTEXITCODE -ne 0) { exit 1 } |
41 | | -} |
42 | | - |
43 | | -function Package-Project |
44 | | -{ |
45 | | - param([string] $DirectoryName) |
46 | | - & dnu pack ("""" + $DirectoryName + """") --configuration Release --out .\artifacts\packages; if($LASTEXITCODE -ne 0) { exit 1 } |
47 | | -} |
48 | | - |
49 | | -function Publish-TestProject |
50 | | -{ |
51 | | - param([string] $DirectoryName, [int]$Index) |
52 | | - |
53 | | - # Publish to a numbered/indexed folder rather than the full test project name |
54 | | - # because the package paths get long and start exceeding OS limitations. |
55 | | - & dnu publish ("""" + $DirectoryName + """") --configuration Release --no-source --out .\artifacts\tests\$Index; if($LASTEXITCODE -ne 0) { exit 2 } |
56 | | -} |
57 | | - |
58 | | -function Invoke-Tests |
59 | | -{ |
60 | | - Get-ChildItem .\artifacts\tests -Filter test.cmd -Recurse | ForEach-Object { & $_.FullName; if($LASTEXITCODE -ne 0) { exit 3 } } |
61 | | -} |
62 | | - |
63 | | -function Remove-PathVariable |
64 | | -{ |
65 | | - param([string] $VariableToRemove) |
66 | | - $path = [Environment]::GetEnvironmentVariable("PATH", "User") |
67 | | - $newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove } |
68 | | - [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User") |
69 | | - $path = [Environment]::GetEnvironmentVariable("PATH", "Process") |
70 | | - $newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove } |
71 | | - [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process") |
72 | | -} |
73 | | - |
74 | | -######################## |
75 | | -# THE BUILD! |
76 | | -######################## |
77 | | - |
78 | | -Push-Location $PSScriptRoot |
79 | | - |
80 | | -$dnxVersion = Get-DnxVersion |
81 | | - |
82 | | -# Clean |
83 | | -if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse } |
84 | | - |
85 | | -# Remove the installed DNVM from the path and force use of |
86 | | -# per-user DNVM (which we can upgrade as needed without admin permissions) |
87 | | -Remove-PathVariable "*Program Files\Microsoft DNX\DNVM*" |
88 | | -Install-Dnvm |
89 | | - |
90 | | -# Install DNX |
91 | | -dnvm update-self |
92 | | -dnvm upgrade |
93 | | - |
94 | | -# Make sure these versions of DNX (for now) are installed |
95 | | -dnvm install $dnxVersion -r clr -a x86 -NoNative |
96 | | -dnvm install $dnxVersion -r clr -a x64 -NoNative |
97 | | -dnvm install $dnxVersion -r coreclr -a x86 -NoNative |
98 | | -dnvm install $dnxVersion -r coreclr -a x64 -NoNative |
99 | | -dnvm use $dnxVersion -r clr |
100 | | -dnvm list |
101 | | -npm cache clean |
102 | | -dnu restore |
103 | | - |
104 | | -# Package restore |
105 | | -Get-ChildItem -Path . -Filter *.xproj -Recurse | ForEach-Object { dnu restore ("""" + $_.DirectoryName + """") } |
106 | | - |
107 | | -# Set build number |
108 | | -$env:DNX_BUILD_VERSION = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1}[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; |
109 | | -Write-Host "Build number:" $env:DNX_BUILD_VERSION |
110 | | - |
111 | | -# Build/package |
112 | | -Get-ChildItem -Path .\src -Filter *.xproj -Recurse | ForEach-Object { Package-Project $_.DirectoryName } |
113 | | -# Get-ChildItem -Path .\samples -Filter *.xproj -Recurse | ForEach-Object { Build-Project $_.DirectoryName } |
114 | | - |
115 | | -# Publish tests so we can test without recompiling |
116 | | -Get-ChildItem -Path .\test -Filter *.xproj -Recurse | ForEach-Object -Begin { $TestIndex = 0 } -Process { Publish-TestProject -DirectoryName $_.DirectoryName -Index $TestIndex; $TestIndex++; } |
117 | | - |
118 | | -# Test under CLR |
119 | | -# Invoke-Tests |
120 | | - |
121 | | -# Switch to Core CLR |
122 | | -#dnvm use $dnxVersion -r CoreCLR |
123 | | - |
124 | | -# Test under Core CLR |
125 | | -#Invoke-Tests |
126 | | - |
127 | | -Pop-Location |
| 1 | +echo "build: Build started" |
| 2 | + |
| 3 | +Push-Location $PSScriptRoot |
| 4 | + |
| 5 | +if(Test-Path .\artifacts) { |
| 6 | + echo "build: Cleaning .\artifacts" |
| 7 | + Remove-Item .\artifacts -Force -Recurse |
| 8 | +} |
| 9 | + |
| 10 | +& dotnet restore --no-cache |
| 11 | + |
| 12 | +$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL]; |
| 13 | +$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; |
| 14 | +$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"] |
| 15 | + |
| 16 | +echo "build: Version suffix is $suffix" |
| 17 | + |
| 18 | +foreach ($src in ls src/*) { |
| 19 | + Push-Location $src |
| 20 | + |
| 21 | + echo "build: Packaging project in $src" |
| 22 | + |
| 23 | + & dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix |
| 24 | + if($LASTEXITCODE -ne 0) { exit 1 } |
| 25 | + |
| 26 | + Pop-Location |
| 27 | +} |
| 28 | + |
| 29 | + |
| 30 | +Pop-Location |
| 31 | + |
| 32 | + |
0 commit comments