forked from AutoMapper/AutoMapper.Collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
95 lines (74 loc) · 3.34 KB
/
build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
Framework '4.5.1x86'
properties {
$base_dir = resolve-path .
$source_dir = "$base_dir\src"
$result_dir = "$base_dir\results"
$artifacts_dir = "$base_dir\artifacts"
$global:config = "debug"
}
task default -depends local
task local -depends init, compile, test
task ci -depends clean, release, local
task clean {
rd "$artifacts_dir" -recurse -force -ErrorAction SilentlyContinue | out-null
rd "$result_dir" -recurse -force -ErrorAction SilentlyContinue | out-null
}
task init {
# Make sure per-user dotnet is installed
Install-Dotnet
}
task release {
$global:config = "release"
}
task compile -depends clean {
$tag = $(git tag -l --points-at HEAD)
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
$suffix = @{ $true = ""; $false = "ci-$revision"}[$tag -ne $NULL -and $revision -ne "local"]
$commitHash = $(git rev-parse --short HEAD)
$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]
$buildParam = @{ $true = ""; $false = "--version-suffix=$buildSuffix"}[$tag -ne $NULL -and $revision -ne "local"]
$packageParam = @{ $true = ""; $false = "--version-suffix=$suffix"}[$tag -ne $NULL -and $revision -ne "local"]
echo "build: Tag is $tag"
echo "build: Package version suffix is $suffix"
echo "build: Build version suffix is $buildSuffix"
# restore all project references (creating project.assets.json for each project)
exec { dotnet restore $base_dir\AutoMapper.Collection.sln /nologo }
exec { dotnet build $base_dir\AutoMapper.Collection.sln -c $config $buildParam /nologo --no-restore }
exec { dotnet pack $base_dir\AutoMapper.Collection.sln -c $config --include-symbols --no-build --no-restore --output $artifacts_dir $packageParam /nologo}
}
task test {
exec { dotnet test $source_dir\AutoMapper.Collection.Tests -c $config --no-build --no-restore --results-directory $result_dir --logger trx /nologo }
exec { dotnet test $source_dir\AutoMapper.Collection.EntityFramework.Tests -c $config --no-build --no-restore --results-directory $result_dir --logger trx /nologo }
}
function Install-Dotnet
{
$dotnetcli = where-is('dotnet')
if($dotnetcli -eq $null)
{
$dotnetPath = "$pwd\.dotnet"
$dotnetCliVersion = if ($env:DOTNET_CLI_VERSION -eq $null) { 'Latest' } else { $env:DOTNET_CLI_VERSION }
$dotnetInstallScriptUrl = 'https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/install.ps1'
$dotnetInstallScriptPath = '.\scripts\obtain\install.ps1'
md -Force ".\scripts\obtain\" | Out-Null
curl $dotnetInstallScriptUrl -OutFile $dotnetInstallScriptPath
& .\scripts\obtain\install.ps1 -Channel "preview" -version $dotnetCliVersion -InstallDir $dotnetPath -NoPath
$env:Path = "$dotnetPath;$env:Path"
}
}
function where-is($command) {
(ls env:\path).Value.split(';') | `
where { $_ } | `
%{ [System.Environment]::ExpandEnvironmentVariables($_) } | `
where { test-path $_ } |`
%{ ls "$_\*" -include *.bat,*.exe,*cmd } | `
%{ $file = $_.Name; `
if($file -and ($file -eq $command -or `
$file -eq ($command + '.exe') -or `
$file -eq ($command + '.bat') -or `
$file -eq ($command + '.cmd'))) `
{ `
$_.FullName `
} `
} | `
select -unique
}