Skip to content

Commit 6491e64

Browse files
committedAug 5, 2020
Build updates to align with core Autofac.
1 parent b863b93 commit 6491e64

File tree

4 files changed

+241
-243
lines changed

4 files changed

+241
-243
lines changed
 

‎build.ps1

+47-38
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,66 @@
22
# THE BUILD!
33
########################
44

5-
param (
5+
param (
66
[switch]$Bench = $false
7-
)
7+
)
88

99
Push-Location $PSScriptRoot
10-
Import-Module $PSScriptRoot\build\Autofac.Build.psd1 -Force
10+
try {
11+
Import-Module $PSScriptRoot/build/Autofac.Build.psd1 -Force
1112

12-
$artifactsPath = "$PSScriptRoot\artifacts"
13-
$packagesPath = "$artifactsPath\packages"
14-
$sdkVersion = (Get-Content "$PSScriptRoot\global.json" | ConvertFrom-Json).sdk.version
13+
$artifactsPath = "$PSScriptRoot/artifacts"
14+
$packagesPath = "$artifactsPath/packages"
15+
$sdkVersion = (Get-Content "$PSScriptRoot/global.json" | ConvertFrom-Json).sdk.version
1516

16-
# Clean up artifacts folder
17-
if (Test-Path $artifactsPath) {
18-
Write-Message "Cleaning $artifactsPath folder"
19-
Remove-Item $artifactsPath -Force -Recurse
20-
}
17+
# Clean up artifacts folder
18+
if (Test-Path $artifactsPath) {
19+
Write-Message "Cleaning $artifactsPath folder"
20+
Remove-Item $artifactsPath -Force -Recurse
21+
}
2122

22-
# Install dotnet CLI
23-
if ($isWindows) {
23+
# Install dotnet CLI
2424
Write-Message "Installing .NET Core SDK version $sdkVersion"
2525
Install-DotNetCli -Version $sdkVersion
26-
}
2726

28-
# Write out dotnet information
29-
& dotnet --info
27+
# Write out dotnet information
28+
& dotnet --info
3029

31-
# Set version suffix
32-
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$NULL -ne $env:APPVEYOR_REPO_BRANCH];
33-
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$NULL -ne $env:APPVEYOR_BUILD_NUMBER];
34-
$versionSuffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"]
30+
# Set version suffix
31+
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$NULL -ne $env:APPVEYOR_REPO_BRANCH];
32+
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$NULL -ne $env:APPVEYOR_BUILD_NUMBER];
33+
$versionSuffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)).Replace('/', '-'))-$revision" }[$branch -eq "master" -and $revision -ne "local"]
3534

36-
Write-Message "Package version suffix is '$versionSuffix'"
35+
Write-Message "Package version suffix is '$versionSuffix'"
3736

38-
# Package restore
39-
Write-Message "Restoring packages"
40-
Get-DotNetProjectDirectory -RootPath $PSScriptRoot | Restore-DependencyPackages
37+
# Package restore
38+
Write-Message "Restoring packages"
39+
Get-DotNetProjectDirectory -RootPath $PSScriptRoot | Restore-DependencyPackages
4140

42-
# Build/package
43-
Write-Message "Building projects and packages"
44-
Get-DotNetProjectDirectory -RootPath $PSScriptRoot\src | Invoke-DotNetPack -PackagesPath $packagesPath -VersionSuffix $versionSuffix
41+
# Build/package
42+
Write-Message "Building projects and packages"
43+
Get-DotNetProjectDirectory -RootPath $PSScriptRoot\src | Invoke-DotNetPack -PackagesPath $packagesPath -VersionSuffix $versionSuffix
4544

46-
# Test
47-
Write-Message "Executing unit tests"
48-
Get-DotNetProjectDirectory -RootPath $PSScriptRoot\test | Where-Object { $_ -inotlike "*Autofac.Test.Scenarios.ScannedAssembly" } | Invoke-Test
45+
# Test
46+
Write-Message "Executing unit tests"
47+
Get-DotNetProjectDirectory -RootPath $PSScriptRoot\test | Where-Object { $_ -inotlike "*Autofac.Test.Scenarios.ScannedAssembly" } | Invoke-Test
4948

50-
# Benchmark
51-
if ($Bench) {
52-
Get-DotNetProjectDirectory -RootPath $PSScriptRoot\bench | Invoke-Test
53-
Get-ChildItem -Path $PSScriptRoot\bench -Filter "BenchmarkDotNet.Artifacts" -Directory -Recurse | Move-Item -Destination "$PSScriptRoot\artifacts\benchmarks"
54-
}
49+
# Benchmark
50+
if ($Bench) {
51+
Get-DotNetProjectDirectory -RootPath $PSScriptRoot\bench | Invoke-Test
52+
Get-ChildItem -Path $PSScriptRoot\bench -Filter "BenchmarkDotNet.Artifacts" -Directory -Recurse | Move-Item -Destination "$PSScriptRoot\artifacts\benchmarks"
53+
}
5554

56-
# Finished
57-
Write-Message "Build finished"
58-
Pop-Location
55+
if ($env:CI -eq "true") {
56+
# Generate Coverage Report
57+
Write-Message "Generating Codecov Report"
58+
Invoke-WebRequest -Uri 'https://codecov.io/bash' -OutFile codecov.sh
59+
& bash codecov.sh -f "coverage.info"
60+
}
61+
62+
# Finished
63+
Write-Message "Build finished"
64+
}
65+
finally {
66+
Pop-Location
67+
}

‎build/Autofac.Build.psd1

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@{
22
RootModule = '.\Autofac.Build.psm1'
3-
ModuleVersion = '0.2.0'
3+
ModuleVersion = '0.3.0'
44
GUID = '55d3f738-f48f-4497-9b2c-ecd90ec1f978'
55
Author = 'Autofac Contributors'
66
CompanyName = 'Autofac'
@@ -12,4 +12,4 @@
1212
ModuleList = @()
1313
FileList = @()
1414
PrivateData = ''
15-
}
15+
}

‎build/Autofac.Build.psm1

+189-203
Original file line numberDiff line numberDiff line change
@@ -5,86 +5,66 @@
55
# 4: dotnet / NuGet package restore failure
66

77
<#
8-
.SYNOPSIS
9-
Writes a build progress message to the host.
8+
.SYNOPSIS
9+
Gets the set of directories in which projects are available for compile/processing.
1010
11-
.PARAMETER Message
12-
The message to write.
11+
.PARAMETER RootPath
12+
Path where searching for project directories should begin.
1313
#>
14-
function Write-Message
15-
{
16-
[CmdletBinding()]
17-
Param(
18-
[Parameter(Mandatory=$True, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$False)]
19-
[ValidateNotNullOrEmpty()]
20-
[string]
21-
$Message
22-
)
23-
24-
Write-Host "[BUILD] $Message" -ForegroundColor Cyan
14+
function Get-DotNetProjectDirectory {
15+
[CmdletBinding()]
16+
Param(
17+
[Parameter(Mandatory = $True, ValueFromPipeline = $False, ValueFromPipelineByPropertyName = $False)]
18+
[ValidateNotNullOrEmpty()]
19+
[string]
20+
$RootPath
21+
)
22+
23+
Get-ChildItem -Path $RootPath -Recurse -Include "*.csproj" | Select-Object @{ Name = "ParentFolder"; Expression = { $_.Directory.FullName.TrimEnd("\") } } | Select-Object -ExpandProperty ParentFolder
2524
}
2625

2726
<#
28-
.SYNOPSIS
29-
Gets the set of directories in which projects are available for compile/processing.
30-
31-
.PARAMETER RootPath
32-
Path where searching for project directories should begin.
27+
.SYNOPSIS
28+
Runs the dotnet CLI install script from GitHub to install a project-local
29+
copy of the CLI.
3330
#>
34-
function Get-DotNetProjectDirectory
35-
{
36-
[CmdletBinding()]
37-
Param(
38-
[Parameter(Mandatory=$True, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$False)]
39-
[ValidateNotNullOrEmpty()]
40-
[string]
41-
$RootPath
42-
)
43-
44-
Get-ChildItem -Path $RootPath -Recurse -Include "*.csproj" | Select-Object @{ Name="ParentFolder"; Expression={ $_.Directory.FullName.TrimEnd("\") } } | Select-Object -ExpandProperty ParentFolder
45-
}
31+
function Install-DotNetCli {
32+
[CmdletBinding()]
33+
Param(
34+
[string]
35+
$Version = "Latest"
36+
)
37+
38+
if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue)) {
39+
$installedVersion = dotnet --version
40+
if ($installedVersion -eq $Version) {
41+
Write-Message ".NET Core SDK version $Version is already installed"
42+
return;
43+
}
44+
}
4645

47-
<#
48-
.SYNOPSIS
49-
Runs the dotnet CLI install script from GitHub to install a project-local
50-
copy of the CLI.
51-
#>
52-
function Install-DotNetCli
53-
{
54-
[CmdletBinding()]
55-
Param(
56-
[string]
57-
$Version = "Latest"
58-
)
59-
60-
if ((Get-Command "dotnet.exe" -ErrorAction SilentlyContinue) -ne $null)
61-
{
62-
$installedVersion = dotnet --version
63-
if ($installedVersion -eq $Version)
64-
{
65-
Write-Message ".NET Core SDK version $Version is already installed"
66-
return;
46+
$callerPath = Split-Path $MyInvocation.PSCommandPath
47+
$installDir = Join-Path -Path $callerPath -ChildPath ".dotnet/cli"
48+
if (!(Test-Path $installDir)) {
49+
New-Item -ItemType Directory -Path "$installDir" | Out-Null
50+
}
51+
52+
# Download the dotnet CLI install script
53+
if ($IsWindows) {
54+
if (!(Test-Path ./.dotnet/dotnet-install.ps1)) {
55+
Invoke-WebRequest "https://dot.net/v1/dotnet-install.ps1" -OutFile "./.dotnet/dotnet-install.ps1"
56+
}
57+
58+
& ./.dotnet/dotnet-install.ps1 -InstallDir "$installDir" -Version $Version
59+
$env:PATH = "$installDir;$env:PATH"
60+
} else {
61+
if (!(Test-Path ./.dotnet/dotnet-install.sh)) {
62+
Invoke-WebRequest "https://dot.net/v1/dotnet-install.sh" -OutFile "./.dotnet/dotnet-install.sh"
63+
}
64+
65+
& bash ./.dotnet/dotnet-install.sh --install-dir "$installDir" --version $Version
66+
$env:PATH = "$installDir`:$env:PATH"
6767
}
68-
}
69-
70-
$callerPath = Split-Path $MyInvocation.PSCommandPath
71-
$installDir = Join-Path -Path $callerPath -ChildPath ".dotnet\cli"
72-
if (!(Test-Path $installDir))
73-
{
74-
New-Item -ItemType Directory -Path "$installDir" | Out-Null
75-
}
76-
77-
# Download the dotnet CLI install script
78-
if (!(Test-Path .\dotnet\install.ps1))
79-
{
80-
Invoke-WebRequest "https://dot.net/v1/dotnet-install.ps1" -OutFile ".\.dotnet\dotnet-install.ps1"
81-
}
82-
83-
# Run the dotnet CLI install
84-
& .\.dotnet\dotnet-install.ps1 -InstallDir "$installDir" -Version $Version
85-
86-
# Add the dotnet folder path to the process.
87-
$env:PATH = "$installDir;$env:PATH"
8868
}
8969

9070
<#
@@ -95,156 +75,162 @@ function Install-DotNetCli
9575
.PARAMETER DirectoryName
9676
The path to the directory containing the project to build.
9777
#>
98-
function Invoke-DotNetBuild
99-
{
100-
[CmdletBinding()]
101-
Param(
102-
[Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)]
103-
[ValidateNotNull()]
104-
[System.IO.DirectoryInfo[]]
105-
$ProjectDirectory
106-
)
107-
Process
108-
{
109-
foreach($Project in $ProjectDirectory)
110-
{
111-
& dotnet build ("""" + $Project.FullName + """") --configuration Release
112-
if ($LASTEXITCODE -ne 0)
113-
{
114-
exit 1
115-
}
78+
function Invoke-DotNetBuild {
79+
[CmdletBinding()]
80+
Param(
81+
[Parameter(Mandatory = $True, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
82+
[ValidateNotNull()]
83+
[System.IO.DirectoryInfo[]]
84+
$ProjectDirectory
85+
)
86+
Process {
87+
foreach ($Project in $ProjectDirectory) {
88+
& dotnet build ("""" + $Project.FullName + """") --configuration Release
89+
if ($LASTEXITCODE -ne 0) {
90+
exit 1
91+
}
92+
}
11693
}
117-
}
11894
}
11995

12096
<#
121-
.SYNOPSIS
122-
Invokes the dotnet utility to package a project.
97+
.SYNOPSIS
98+
Invokes the dotnet utility to package a project.
12399
124-
.PARAMETER ProjectDirectory
125-
Path to the directory containing the project to package.
100+
.PARAMETER ProjectDirectory
101+
Path to the directory containing the project to package.
126102
127-
.PARAMETER PackagesPath
128-
Path to the "artifacts\packages" folder where packages should go.
103+
.PARAMETER PackagesPath
104+
Path to the "artifacts/packages" folder where packages should go.
129105
130-
.PARAMETER VersionSuffix
131-
The version suffix to use for the NuGet package version.
106+
.PARAMETER VersionSuffix
107+
The version suffix to use for the NuGet package version.
132108
#>
133-
function Invoke-DotNetPack
134-
{
135-
[CmdletBinding()]
136-
Param(
137-
[Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)]
138-
[ValidateNotNull()]
139-
[System.IO.DirectoryInfo[]]
140-
$ProjectDirectory,
141-
142-
[Parameter(Mandatory=$True, ValueFromPipeline=$False)]
143-
[ValidateNotNull()]
144-
[System.IO.DirectoryInfo]
145-
$PackagesPath,
146-
147-
[Parameter(Mandatory=$True, ValueFromPipeline=$False)]
148-
[AllowEmptyString()]
149-
[string]
150-
$VersionSuffix = ""
151-
)
152-
Begin
153-
{
154-
New-Item -Path $PackagesPath -ItemType Directory -Force | Out-Null
155-
}
156-
Process
157-
{
158-
foreach($Project in $ProjectDirectory)
159-
{
160-
if ($VersionSuffix -eq "")
161-
{
162-
& dotnet build ("""" + $Project.FullName + """") --configuration Release
163-
}
164-
else
165-
{
166-
& dotnet build ("""" + $Project.FullName + """") --configuration Release --version-suffix $VersionSuffix
167-
}
168-
if ($LASTEXITCODE -ne 0)
169-
{
170-
exit 1
171-
}
172-
173-
if ($VersionSuffix -eq "")
174-
{
175-
& dotnet pack ("""" + $Project.FullName + """") --configuration Release --output $PackagesPath
176-
}
177-
else
178-
{
179-
& dotnet pack ("""" + $Project.FullName + """") --configuration Release --version-suffix $VersionSuffix --output $PackagesPath
180-
}
181-
if ($LASTEXITCODE -ne 0)
182-
{
183-
exit 1
184-
}
109+
function Invoke-DotNetPack {
110+
[CmdletBinding()]
111+
Param(
112+
[Parameter(Mandatory = $True, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
113+
[ValidateNotNull()]
114+
[System.IO.DirectoryInfo[]]
115+
$ProjectDirectory,
116+
117+
[Parameter(Mandatory = $True, ValueFromPipeline = $False)]
118+
[ValidateNotNull()]
119+
[System.IO.DirectoryInfo]
120+
$PackagesPath,
121+
122+
[Parameter(Mandatory = $True, ValueFromPipeline = $False)]
123+
[AllowEmptyString()]
124+
[string]
125+
$VersionSuffix
126+
)
127+
Begin {
128+
New-Item -Path $PackagesPath -ItemType Directory -Force | Out-Null
129+
}
130+
Process {
131+
foreach ($Project in $ProjectDirectory) {
132+
if ($VersionSuffix -eq "") {
133+
& dotnet build ("""" + $Project.FullName + """") --configuration Release
134+
}
135+
else {
136+
& dotnet build ("""" + $Project.FullName + """") --configuration Release --version-suffix $VersionSuffix
137+
}
138+
if ($LASTEXITCODE -ne 0) {
139+
exit 1
140+
}
141+
142+
if ($VersionSuffix -eq "") {
143+
& dotnet pack ("""" + $Project.FullName + """") --configuration Release --output $PackagesPath
144+
}
145+
else {
146+
& dotnet pack ("""" + $Project.FullName + """") --configuration Release --version-suffix $VersionSuffix --output $PackagesPath
147+
}
148+
if ($LASTEXITCODE -ne 0) {
149+
exit 1
150+
}
151+
}
185152
}
186-
}
187153
}
188154

189155
<#
190-
.Synopsis
191-
Invokes dotnet test command.
156+
.SYNOPSIS
157+
Invokes dotnet test command.
192158
193-
.Parameter ProjectDirectory
194-
Path to the directory containing the project to package.
159+
.PARAMETER ProjectDirectory
160+
Path to the directory containing the project to package.
195161
#>
196-
function Invoke-Test
197-
{
198-
[CmdletBinding()]
199-
Param(
200-
[Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)]
201-
[ValidateNotNull()]
202-
[System.IO.DirectoryInfo[]]
203-
$ProjectDirectory
204-
)
205-
Process
206-
{
207-
foreach($Project in $ProjectDirectory)
208-
{
209-
Push-Location $Project
210-
211-
& dotnet test --configuration Release --logger:trx
212-
if ($LASTEXITCODE -ne 0)
213-
{
214-
Pop-Location
215-
exit 3
216-
}
217-
218-
Pop-Location
162+
function Invoke-Test {
163+
[CmdletBinding()]
164+
Param(
165+
[Parameter(Mandatory = $True, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
166+
[ValidateNotNull()]
167+
[System.IO.DirectoryInfo[]]
168+
$ProjectDirectory
169+
)
170+
Process {
171+
foreach ($Project in $ProjectDirectory) {
172+
Push-Location $Project
173+
174+
& dotnet test `
175+
--configuration Release `
176+
--logger:trx `
177+
/p:CollectCoverage=true `
178+
/p:CoverletOutput="..\..\" `
179+
/p:MergeWith="..\..\coverage.json" `
180+
/p:CoverletOutputFormat="json%2clcov" `
181+
/p:ExcludeByAttribute=CompilerGeneratedAttribute `
182+
/p:ExcludeByAttribute=GeneratedCodeAttribute
183+
184+
if ($LASTEXITCODE -ne 0) {
185+
Pop-Location
186+
exit 3
187+
}
188+
189+
Pop-Location
190+
}
219191
}
220-
}
221192
}
222193

223194
<#
224-
.SYNOPSIS
225-
Restores dependencies using the dotnet utility.
195+
.SYNOPSIS
196+
Restores dependencies using the dotnet utility.
226197
227-
.PARAMETER ProjectDirectory
228-
Path to the directory containing the project with dependencies to restore.
198+
.PARAMETER ProjectDirectory
199+
Path to the directory containing the project with dependencies to restore.
229200
#>
230-
function Restore-DependencyPackages
231-
{
232-
[CmdletBinding()]
233-
Param(
234-
[Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)]
235-
[ValidateNotNull()]
236-
[System.IO.DirectoryInfo[]]
237-
$ProjectDirectory
238-
)
239-
Process
240-
{
241-
foreach($Project in $ProjectDirectory)
242-
{
243-
& dotnet restore ("""" + $Project.FullName + """") --no-cache
244-
if($LASTEXITCODE -ne 0)
245-
{
246-
exit 4
247-
}
201+
function Restore-DependencyPackages {
202+
[CmdletBinding()]
203+
Param(
204+
[Parameter(Mandatory = $True, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
205+
[ValidateNotNull()]
206+
[System.IO.DirectoryInfo[]]
207+
$ProjectDirectory
208+
)
209+
Process {
210+
foreach ($Project in $ProjectDirectory) {
211+
& dotnet restore ("""" + $Project.FullName + """") --no-cache
212+
if ($LASTEXITCODE -ne 0) {
213+
exit 4
214+
}
215+
}
248216
}
249-
}
217+
}
218+
219+
<#
220+
.SYNOPSIS
221+
Writes a build progress message to the host.
222+
223+
.PARAMETER Message
224+
The message to write.
225+
#>
226+
function Write-Message {
227+
[CmdletBinding()]
228+
Param(
229+
[Parameter(Mandatory = $True, ValueFromPipeline = $False, ValueFromPipelineByPropertyName = $False)]
230+
[ValidateNotNullOrEmpty()]
231+
[string]
232+
$Message
233+
)
234+
235+
Write-Host "[BUILD] $Message" -ForegroundColor Cyan
250236
}

‎codecov.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
codecov:
2+
branch: develop
3+
require_ci_to_pass: yes

0 commit comments

Comments
 (0)
Please sign in to comment.