Skip to content

Commit

Permalink
added more stable support for publishing artifacts v1.2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jole78 committed Jun 8, 2013
1 parent e5b6efb commit 74b9f5d
Show file tree
Hide file tree
Showing 11 changed files with 241 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,46 @@ function Invoke-TeamCitySpecFlowReport {

try {

$args = Parse-Arguments
$args = ParseArguments

Invoke-NUnitConsoleExe $args.PathToAssemblyOrProject $categories
Invoke-SpecFlowExe $args.PathToProjectFile | Tee-Object -Variable specflow_out | Out-Null
CleanEnvironment
InvokeNUnitConsoleExe $args.PathToAssemblyOrProject $categories
InvokeSpecFlowExe $args.PathToProjectFile | Tee-Object -Variable specflow_out | Out-Null

Publish-Artifacts $specflow_out.HtmlReport
Remove-Files $specflow_out
PublishArtifacts $specflow_out.HtmlReport.Path
RemoveFile $specflow_out.SpecFlowExeConfig.Path
CreateListOfGeneratedFiles $specflow_out



} catch {
Write-Error $_.Exception
exit 1
}
}

function Parse-Arguments {
function CleanEnvironment{
if($cfg.CleanEnvironment) {
$x = Get-Content .\files.generated -WarningAction:SilentlyContinue -ErrorAction:SilentlyContinue
if($x) {
$x -split ';' | % { RemoveFile $_ }
}
}
}

function CreateListOfGeneratedFiles{
param(
$files
)

($files.GetEnumerator() | % { $_.Value.Path }) -join ';' | Out-File .\files.generated
}

function ParseArguments {

$args = @{}

$proj = Get-ProjectInformation
$proj = GetProjectInformation

# Path to xxx.csproj
if($cfg.PathToProjectFile) {
Expand All @@ -61,7 +82,7 @@ function Parse-Arguments {
return $args
}

function Invoke-NUnitConsoleExe {
function InvokeNUnitConsoleExe {
param (
[Parameter(Position = 0, Mandatory = 1)][string] $assemblyOrProject,
[Parameter(Position = 1, Mandatory = 0)][string[]] $categories
Expand All @@ -71,7 +92,7 @@ function Invoke-NUnitConsoleExe {
if($cfg.PathToNUnitConsoleExe) {
$exe = $cfg.PathToNUnitConsoleExe
} else {
$exe = Find-NUnitConsoleExe
$exe = FindNUnitConsoleExe
}

if(Test-Path $exe -PathType:Leaf) {
Expand All @@ -95,7 +116,17 @@ function Invoke-NUnitConsoleExe {
}
}

function Invoke-SpecFlowExe {
function ConvertToFileInfo {
param(
$file
)

return @{
Path = $($file.FullName)
}
}

function InvokeSpecFlowExe {
param (
[Parameter(Position = 1, Mandatory = 1)][string] $projectFile
)
Expand All @@ -104,14 +135,14 @@ function Invoke-SpecFlowExe {

# Output from NUnit
if(Test-Path .\TestResult.txt -PathType:Leaf) {
$out.NUnitOutput = Get-Item .\TestResult.txt
$out.NUnitOutput = ConvertToFileInfo (Get-Item .\TestResult.txt | Select-Object -First 1)
} else {
throw "Failed to find nunit output"
}

# Report from NUnit
if(Test-Path .\TestResult.xml -PathType:Leaf) {
$out.NUnitReport = Get-Item .\TestResult.xml
$out.NUnitReport = ConvertToFileInfo (Get-Item .\TestResult.xml | Select-Object -First 1)
} else {
throw "Failed to find nunit report"
}
Expand All @@ -120,7 +151,7 @@ function Invoke-SpecFlowExe {
if($cfg.PathToSpecFlowExe) {
$exe = $cfg.PathToSpecFlowExe
} else {
$exe = Find-SpecFlowExe
$exe = FindSpecFlowExe
}

if(Test-Path $exe -PathType:Leaf) {
Expand All @@ -130,7 +161,7 @@ function Invoke-SpecFlowExe {
if(Test-Path .\specflow.exe.config -PathType:Leaf) {
$dir = (Get-Item $exe).Directory
Copy-Item -Path .\specflow.exe.config -Destination $dir
$out.SpecFlowExeConfig = Get-Item (Join-Path $dir -ChildPath specflow.exe.config)
$out.SpecFlowExeConfig = ConvertToFileInfo (Get-Item (Join-Path $dir -ChildPath specflow.exe.config) | Select-Object -First 1)
}

$parameters = @()
Expand All @@ -141,7 +172,7 @@ function Invoke-SpecFlowExe {
&$exe $parameters | Out-Null

if(Test-Path .\TestResult.html -PathType:Leaf) {
$out.HtmlReport = Get-Item .\TestResult.html
$out.HtmlReport = ConvertToFileInfo (Get-Item .\TestResult.html | Select-Object -First 1)
}

return $out
Expand All @@ -154,7 +185,7 @@ function Invoke-SpecFlowExe {
}
}

function Get-PackagesFolder{
function GetPackagesFolder{
$packages = Get-ChildItem -Directory -Path $cfg.PathToPackagesFolder packages
if($packages -eq $null){
throw "Failed to find the packages folder at location: '$($cfg.PathToPackagesFolder)'. Try using Set-Properties @{PathToPackagesFolder='[YOUR PATH]'}"
Expand All @@ -163,7 +194,7 @@ function Get-PackagesFolder{
return $packages
}

function Get-ProjectInformation{
function GetProjectInformation{
$proj = Get-ChildItem -File "*.*proj" | Select-Object -First 1
if($proj -eq $null){
throw "Failed to find the project file (*.*proj)"
Expand All @@ -175,9 +206,9 @@ function Get-ProjectInformation{
}
}

function Find-SpecFlowExe{
function FindSpecFlowExe{

$packages = Get-PackagesFolder
$packages = GetPackagesFolder
#TODO: need to append the version like
#SpecFlow.1.9.0

Expand All @@ -189,9 +220,9 @@ function Find-SpecFlowExe{
return $specflow_exe.FullName
}

function Find-NUnitConsoleExe{
function FindNUnitConsoleExe{

$packages = Get-PackagesFolder
$packages = GetPackagesFolder
#TODO: need to append the version like
#NUnit.Runners.2.6.2

Expand All @@ -203,7 +234,7 @@ function Find-NUnitConsoleExe{
return $nunit_console_exe.FullName
}

function Publish-Artifacts {
function PublishArtifacts {
param(
[string]$path
)
Expand All @@ -212,20 +243,12 @@ function Publish-Artifacts {
}
}

function Remove-Files {
function RemoveFile {
param(
$files
$path
)

if($cfg.Cleanup) {

foreach($key in $files.Keys) {

$file = $files[$key]
if(Test-Path $file -PathType:Leaf) {
Remove-Item $file -ErrorAction:SilentlyContinue | Out-Null
}
}
if(Test-Path $path -PathType:Leaf) {
Remove-Item $path -ErrorAction:SilentlyContinue | Out-Null
}
}

Expand All @@ -236,7 +259,7 @@ $cfg = @{}
$cfg.Configuration = 'Release'
$cfg.SpecFlowReportType = 'nunitexecutionreport'
$cfg.PublishArtifacts = $true
$cfg.Cleanup = $true
$cfg.CleanEnvironment = $true
$cfg.PathToPackagesFolder = '..\'

Export-ModuleMember -Function Invoke-TeamCitySpecFlowReport, Set-Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<package id="NUnit" version="2.6.2" targetFramework="net40" />
<package id="SpecFlow" version="1.9.0" targetFramework="net40" />
<package id="SpecFlow.NUnit" version="1.1.1" targetFramework="net40" />
<package id="TeamCity.SpecFlow.Reporting" version="1.1.1.0" targetFramework="net40" />
<package id="TeamCity.SpecFlow.Reporting" version="1.1.2.1" targetFramework="net40" />
</packages>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>TeamCity.SpecFlow.Reporting</id>
<version>1.1.1.0</version>
<version>1.1.2.1</version>
<authors>Johan Leino</authors>
<owners>Johan Leino</owners>
<projectUrl>https://github.com/jole78/TeamCity.SpecFlow.Reporting</projectUrl>
Expand Down
Loading

0 comments on commit 74b9f5d

Please sign in to comment.