From 4487ec6c852588bc33e79d39278de1651f907032 Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Mon, 22 Sep 2014 21:09:28 +0100 Subject: [PATCH] (#159 #160) Initial Pass at running inspection tools - Updated appveyor to include new artifacts - Added config files for dupfinder and inspectcode to BuildScripts folder - Added Tasks for: - Installing Chocolatey if required - Installing resharper clt if required - Running dupfinder, using config file - Running inspectcode, using config file --- BuildScripts/default.ps1 | 92 ++++++++++++++++++++++++++++++++- BuildScripts/dupfinder.config | 8 +++ BuildScripts/inspectcode.config | 6 +++ appveyor.yml | 8 ++- build.bat | 4 +- 5 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 BuildScripts/dupfinder.config create mode 100644 BuildScripts/inspectcode.config diff --git a/BuildScripts/default.ps1 b/BuildScripts/default.ps1 index c5c47ad9b..ccc3b317d 100644 --- a/BuildScripts/default.ps1 +++ b/BuildScripts/default.ps1 @@ -17,6 +17,10 @@ function get-buildArtifactsDirectory { return "." | Resolve-Path | Join-Path -ChildPath "../BuildArtifacts"; } +function get-buildScriptsDirectory { + return "." | Resolve-Path; +} + function get-sourceDirectory { return "." | Resolve-Path | Join-Path -ChildPath "../Source"; } @@ -49,6 +53,19 @@ function isAppVeyor() { Test-Path -Path env:\APPVEYOR } +function isChocolateyInstalled() { + $script:chocolateyDir = $null + if ($env:ChocolateyInstall -ne $null) { + $script:chocolateyDir = $env:ChocolateyInstall; + } elseif (Test-Path (Join-Path $env:SYSTEMDRIVE Chocolatey)) { + $script:chocolateyDir = Join-Path $env:SYSTEMDRIVE Chocolatey; + } elseif (Test-Path (Join-Path ([Environment]::GetFolderPath("CommonApplicationData")) Chocolatey)) { + $script:chocolateyDir = Join-Path ([Environment]::GetFolderPath("CommonApplicationData")) Chocolatey; + } + + Test-Path -Path $script:chocolateyDir; +} + Task -Name Default -Depends BuildSolution # private tasks @@ -65,18 +82,63 @@ Task -Name __RemoveBuildArtifactsDirectory -Description $private -Action { get-buildArtifactsDirectory | remove-packageDirectory; } +Task -Name __InstallChocolatey -Description $private -Action { + if(isChocolateyInstalled) { + Write-Host "Chocolatey already installed"; + } + else { + Write-Host "Chocolatey is not installed, installing Chocolatey..."; + Invoke-Expression ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')); + + $script:chocolateyDir = Join-Path ([Environment]::GetFolderPath("CommonApplicationData")) Chocolatey + if (-not (Test-Path $script:chocolateyDir)) { + throw "Error installing Chocolatey" + } + } +} + +Task -Name __InstallReSharperCommandLineTools -Depends __InstallChocolatey -Description $private -Action { + $chocolateyBinDir = Join-Path $script:chocolateyDir -ChildPath "bin"; + $inspectCodeExe = Join-Path $chocolateyBinDir -ChildPath "inspectcode.exe"; + + $choco = Join-Path (Join-Path $script:chocolateyDir "chocolateyInstall") -ChildPath "chocolatey.cmd"; + Write-Output "Where is Choco: $choco"; + + if (-not (Test-Path $inspectCodeExe)) { + Invoke-Expression "$choco install resharper-clt"; + if ($LASTEXITCODE -ne 0) { + throw "Error installing resharper-clt"; + } + } else { + Write-Host "resharper-clt already installed"; + } +} + Task -Name __InstallPSBuild -Description $private -Action { # Need a test here to see if this is actually required (new-object Net.WebClient).DownloadString("https://raw.github.com/ligershark/psbuild/master/src/GetPSBuild.ps1") | Invoke-Expression; } +Task -Name __UpdateReSharperCommandLineTools -Description $private -Action { + $choco = Join-Path (Join-Path $script:chocolateyDir "chocolateyInstall") -ChildPath "chocolatey.cmd"; + + Invoke-Expression "$choco update resharper-clt"; + + if ($LASTEXITCODE -ne 0) { + throw "Error updating resharper-clt"; + } +} + # primary targets Task -Name PackageSolution -Depends RebuildSolution, PackageChocolatey -Description "Complete build, including creation of Chocolatey Package." -Task -Name DeploySolutionToMyGet -Depends PackageSolution, DeployPacakgeToMyGet -Description "Complete build, including creation of Chocolatey Package and Deployment to MyGet.org" -Task -Name DeploySolutionToChocolatey -Depends PackageSolution, DeployPackageToChocolatey -Description "Complete build, including creation of Chocolatey Package and Deployment to Chocolatey.org." +Task -Name InspectCodeForProblems -Depends RunDupFinder, RunInspectCode -Description "Complete build, including running dupfinder, and inspectcode." + +Task -Name DeploySolutionToMyGet -Depends InspectCodeForProblems, DeployPacakgeToMyGet -Description "Complete build, including creation of Chocolatey Package and Deployment to MyGet.org" + +Task -Name DeploySolutionToChocolatey -Depends InspectCodeForProblems, DeployPackageToChocolatey -Description "Complete build, including creation of Chocolatey Package and Deployment to Chocolatey.org." # build tasks @@ -108,6 +170,32 @@ Task -Name RunGitVersion -Description "Execute the GitVersion Command Line Tool, } } +Task -Name RunInspectCode -Depends __InstallReSharperCommandLineTools -Description "Execute the InspectCode Command Line Tool" -Action { + $chocolateyBinDir = Join-Path $script:chocolateyDir -ChildPath "bin"; + $inspectCodeExe = Join-Path $chocolateyBinDir -ChildPath "inspectcode.exe"; + $buildScriptsDirectory = get-buildScriptsDirectory; + $inspectCodeConfigFile = Join-Path $buildScriptsDirectory -ChildPath "inspectcode.config"; + + Invoke-Expression "$inspectCodeExe /config=$inspectCodeConfigFile"; + + if ($LASTEXITCODE -ne 0) { + throw "Error running InspectCode"; + } +} + +Task -Name RunDupFinder -Depends __InstallReSharperCommandLineTools -Description "Execute the DupFinder Command Line Tool" -Action { + $chocolateyBinDir = Join-Path $script:chocolateyDir -ChildPath "bin"; + $dupFinderExe = Join-Path $chocolateyBinDir -ChildPath "dupfinder.exe"; + $buildScriptsDirectory = get-buildScriptsDirectory; + $dupFinderConfigFile = Join-Path $buildScriptsDirectory -ChildPath "dupfinder.config"; + + Invoke-Expression "$dupFinderExe /config=$dupFinderConfigFile"; + + if ($LASTEXITCODE -ne 0) { + throw "Error running DupFinder"; + } +} + Task -Name OutputNugetVersion -Description "So that we are clear which version of NuGet is being used, call NuGet" -Action { try { Write-Output "Running NuGet..." diff --git a/BuildScripts/dupfinder.config b/BuildScripts/dupfinder.config new file mode 100644 index 000000000..d6fa7b9c3 --- /dev/null +++ b/BuildScripts/dupfinder.config @@ -0,0 +1,8 @@ + + + + + C:\projects\ChocolateyGUI\Source\**\*.cs + + C:\projects\ChocolateyGUI\BuildArtifacts\dupfinder.xml + \ No newline at end of file diff --git a/BuildScripts/inspectcode.config b/BuildScripts/inspectcode.config new file mode 100644 index 000000000..64d4b7cfa --- /dev/null +++ b/BuildScripts/inspectcode.config @@ -0,0 +1,6 @@ + + + C:\projects\ChocolateyGUI\Source\ChocolateyGui.sln + + C:\projects\ChocolateyGUI\BuildArtifacts\inspectcode.xml + \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 344798168..5efafeb11 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -26,7 +26,7 @@ environment: #---------------------------------# build_script: - - cmd: build.bat PackageSolution + - cmd: build.bat test: off @@ -44,6 +44,12 @@ artifacts: - path: BuildArtifacts\StyleCopReport.xml name: StyleCop Report + - path: BuildArtifacts\inspectcode.xml + name: Inspect Code Report + + - path: BuildArtifacts\dupfinder.xml + name: DupFinder Report + #---------------------------------# # caching configuration # #---------------------------------# diff --git a/build.bat b/build.bat index 6b64d8a6d..46bc5f781 100644 --- a/build.bat +++ b/build.bat @@ -48,7 +48,7 @@ IF "%APPVEYOR%"=="" ( IF "%APPVEYOR_REPO_BRANCH%"=="develop" IF "%APPVEYOR_PULL_REQUEST_NUMBER%" NEQ "" ( ECHO Since we are on develop branch with a pull request number, we are just going to package the solution, with no deployment - powershell -NoProfile -ExecutionPolicy bypass -Command "%~dp0BuildScripts\build.ps1 PackageSolution Release" + powershell -NoProfile -ExecutionPolicy bypass -Command "%~dp0BuildScripts\build.ps1 InspectCodeForProblems Release" GOTO :eof ) @@ -60,7 +60,7 @@ IF "%APPVEYOR%"=="" ( IF "%APPVEYOR_REPO_BRANCH%"=="master" IF "%APPVEYOR_PULL_REQUEST_NUMBER%" NEQ "" ( ECHO Since we are on develop branch with a pull request number, we are just going to package the solution, with no deployment - powershell -NoProfile -ExecutionPolicy bypass -Command "%~dp0BuildScripts\build.ps1 PackageSolution Release" + powershell -NoProfile -ExecutionPolicy bypass -Command "%~dp0BuildScripts\build.ps1 InspectCodeForProblems Release" GOTO :eof ) )