|
| 1 | +param( |
| 2 | + [Parameter(Mandatory=$false)][bool] $RestorePackages = $false, |
| 3 | + [Parameter(Mandatory=$false)][string] $Configuration = "Release", |
| 4 | + [Parameter(Mandatory=$false)][string] $VersionSuffix = "", |
| 5 | + [Parameter(Mandatory=$false)][string] $OutputPath = "", |
| 6 | + [Parameter(Mandatory=$false)][bool] $PatchVersion = $false, |
| 7 | + [Parameter(Mandatory=$false)][bool] $RunTests = $true, |
| 8 | + [Parameter(Mandatory=$false)][bool] $CreatePackages = $true |
| 9 | +) |
| 10 | + |
| 11 | +$ErrorActionPreference = "Stop" |
| 12 | + |
| 13 | +$solutionPath = Split-Path $MyInvocation.MyCommand.Definition |
| 14 | +$getDotNet = Join-Path $solutionPath "tools\install.ps1" |
| 15 | +$dotnetVersion = "1.0.0-preview2-003121" |
| 16 | + |
| 17 | +if ($OutputPath -eq "") { |
| 18 | + $OutputPath = "$(Convert-Path "$PSScriptRoot")\artifacts" |
| 19 | +} |
| 20 | + |
| 21 | +$env:DOTNET_INSTALL_DIR = "$(Convert-Path "$PSScriptRoot")\.dotnetcli" |
| 22 | + |
| 23 | +if ($env:CI -ne $null) { |
| 24 | + |
| 25 | + $RestorePackages = $true |
| 26 | + $PatchVersion = $true |
| 27 | + |
| 28 | + if (($VersionSuffix -eq "" -and $env:APPVEYOR_REPO_TAG -eq "false" -and $env:APPVEYOR_BUILD_NUMBER -ne "") -eq $true) { |
| 29 | + |
| 30 | + $LastVersionBuild = (Get-Content ".\releases.txt" | Select -Last 1) |
| 31 | + $LastVersion = New-Object -TypeName System.Version -ArgumentList $LastVersionBuild |
| 32 | + $ThisVersion = $env:APPVEYOR_BUILD_NUMBER -as [int] |
| 33 | + $ThisBuildNumber = $ThisVersion - $LastVersion.Build |
| 34 | + |
| 35 | + $VersionSuffix = "beta-" + $ThisBuildNumber.ToString("0000") |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +if (!(Test-Path $env:DOTNET_INSTALL_DIR)) { |
| 40 | + mkdir $env:DOTNET_INSTALL_DIR | Out-Null |
| 41 | + $installScript = Join-Path $env:DOTNET_INSTALL_DIR "install.ps1" |
| 42 | + Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/dotnet-install.ps1" -OutFile $installScript |
| 43 | + & $installScript -Version "$dotnetVersion" -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath |
| 44 | +} |
| 45 | + |
| 46 | +$env:PATH = "$env:DOTNET_INSTALL_DIR;$env:PATH" |
| 47 | +$dotnet = "$env:DOTNET_INSTALL_DIR\dotnet" |
| 48 | + |
| 49 | +function DotNetRestore { param([string]$Project) |
| 50 | + & $dotnet restore $Project --verbosity minimal |
| 51 | + if ($LASTEXITCODE -ne 0) { |
| 52 | + throw "dotnet restore failed with exit code $LASTEXITCODE" |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +function DotNetBuild { param([string]$Project, [string]$Configuration, [string]$Framework, [string]$VersionSuffix) |
| 57 | + if ($VersionSuffix) { |
| 58 | + & $dotnet build $Project --output (Join-Path $OutputPath $Framework) --framework $Framework --configuration $Configuration --version-suffix "$VersionSuffix" |
| 59 | + } else { |
| 60 | + & $dotnet build $Project --output (Join-Path $OutputPath $Framework) --framework $Framework --configuration $Configuration |
| 61 | + } |
| 62 | + if ($LASTEXITCODE -ne 0) { |
| 63 | + throw "dotnet build failed with exit code $LASTEXITCODE" |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +function DotNetTest { param([string]$Project) |
| 68 | + & $dotnet test $Project |
| 69 | + if ($LASTEXITCODE -ne 0) { |
| 70 | + throw "dotnet test failed with exit code $LASTEXITCODE" |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +function DotNetPack { param([string]$Project, [string]$Configuration, [string]$VersionSuffix) |
| 75 | + if ($VersionSuffix) { |
| 76 | + & $dotnet pack $Project --output $OutputPath --configuration $Configuration --version-suffix "$VersionSuffix" --no-build |
| 77 | + } else { |
| 78 | + & $dotnet pack $Project --output $OutputPath --configuration $Configuration --no-build |
| 79 | + } |
| 80 | + if ($LASTEXITCODE -ne 0) { |
| 81 | + throw "dotnet pack failed with exit code $LASTEXITCODE" |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +if ($PatchVersion -eq $true) { |
| 86 | + |
| 87 | + $gitRevision = (git rev-parse HEAD | Out-String).Trim() |
| 88 | + $gitBranch = (git rev-parse --abbrev-ref HEAD | Out-String).Trim() |
| 89 | + $timestamp = [DateTime]::UtcNow.ToString("yyyy-MM-ddTHH:mm:ssK") |
| 90 | + |
| 91 | + $assemblyVersion = Get-Content ".\AssemblyVersion.cs" -Raw |
| 92 | + $assemblyVersionWithMetadata = "{0}[assembly: AssemblyMetadata(""CommitHash"", ""{1}"")]`r`n[assembly: AssemblyMetadata(""CommitBranch"", ""{2}"")]`r`n[assembly: AssemblyMetadata(""BuildTimestamp"", ""{3}"")]" -f $assemblyVersion, $gitRevision, $gitBranch, $timestamp |
| 93 | + |
| 94 | + Set-Content ".\AssemblyVersion.cs" $assemblyVersionWithMetadata -Encoding utf8 |
| 95 | +} |
| 96 | + |
| 97 | +$projects = @( |
| 98 | + (Join-Path $solutionPath "src\MartinCostello.BrowserStack.Automate\project.json") |
| 99 | +) |
| 100 | + |
| 101 | +$testProjects = @( |
| 102 | + (Join-Path $solutionPath "tests\MartinCostello.BrowserStack.Automate.Tests\project.json") |
| 103 | +) |
| 104 | + |
| 105 | +$packageProjects = @( |
| 106 | + (Join-Path $solutionPath "src\MartinCostello.BrowserStack.Automate\project.json") |
| 107 | +) |
| 108 | + |
| 109 | +$restoreProjects = @( |
| 110 | + (Join-Path $solutionPath "src\MartinCostello.BrowserStack.Automate\project.json"), |
| 111 | + (Join-Path $solutionPath "tests\MartinCostello.BrowserStack.Automate.Tests\project.json") |
| 112 | +) |
| 113 | + |
| 114 | +if ($RestorePackages -eq $true) { |
| 115 | + Write-Host "Restoring NuGet packages for $($restoreProjects.Count) projects..." -ForegroundColor Green |
| 116 | + ForEach ($project in $restoreProjects) { |
| 117 | + DotNetRestore $project |
| 118 | + } |
| 119 | +} |
| 120 | + |
| 121 | +Write-Host "Building $($projects.Count) projects..." -ForegroundColor Green |
| 122 | +ForEach ($project in $projects) { |
| 123 | + DotNetBuild $project $Configuration "netstandard1.3" $VersionSuffix |
| 124 | + DotNetBuild $project $Configuration "net451" $VersionSuffix |
| 125 | +} |
| 126 | + |
| 127 | +if ($RunTests -eq $true) { |
| 128 | + Write-Host "Testing $($testProjects.Count) project(s)..." -ForegroundColor Green |
| 129 | + ForEach ($project in $testProjects) { |
| 130 | + DotNetTest $project |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +if ($CreatePackages -eq $true) { |
| 135 | + Write-Host "Creating $($packageProjects.Count) package(s)..." -ForegroundColor Green |
| 136 | + ForEach ($project in $packageProjects) { |
| 137 | + DotNetPack $project $Configuration $VersionSuffix |
| 138 | + } |
| 139 | +} |
| 140 | + |
| 141 | +if ($PatchVersion -eq $true) { |
| 142 | + Set-Content ".\AssemblyVersion.cs" $assemblyVersion.Trim() -Encoding utf8 |
| 143 | +} |
0 commit comments