-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfixes, Wrappers, CI/CD and Test Automation (#5)
So I reworked the module to enable CI/CD: Added Invoke-Build, BuildHelpers, PlatyPS, Pester and PSScriptanalyzer. I wrote Pester tests for all functionality except the two Invoke functions. (which will be in the next iteration). Because of these changes i had to re-arrange the Module which will BREAK existing installations. I'm sorry for that but this will make sure the future of this repo will be ensured. Also wrote some wrappers for calling functions and generally improved the coding quality because of Pester.
- Loading branch information
1 parent
3574cf4
commit b22f304
Showing
17 changed files
with
1,358 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
############################################################################### | ||
# Set default behavior to automatically normalize line endings. | ||
############################################################################### | ||
* text=auto | ||
|
||
############################################################################### | ||
# Set default behavior for command prompt diff. | ||
# | ||
# This is need for earlier builds of msysgit that does not have it on by | ||
# default for csharp files. | ||
# Note: This is only used by command line | ||
############################################################################### | ||
#*.cs diff=csharp | ||
|
||
############################################################################### | ||
# Set the merge driver for project and solution files | ||
# | ||
# Merging from the command prompt will add diff markers to the files if there | ||
# are conflicts (Merging from VS is not affected by the settings below, in VS | ||
# the diff markers are never inserted). Diff markers may cause the following | ||
# file extensions to fail to load in VS. An alternative would be to treat | ||
# these files as binary and thus will always conflict and require user | ||
# intervention with every merge. To do so, just uncomment the entries below | ||
############################################################################### | ||
#*.sln merge=binary | ||
#*.csproj merge=binary | ||
#*.vbproj merge=binary | ||
#*.vcxproj merge=binary | ||
#*.vcproj merge=binary | ||
#*.dbproj merge=binary | ||
#*.fsproj merge=binary | ||
#*.lsproj merge=binary | ||
#*.wixproj merge=binary | ||
#*.modelproj merge=binary | ||
#*.sqlproj merge=binary | ||
#*.wwaproj merge=binary | ||
|
||
############################################################################### | ||
# behavior for image files | ||
# | ||
# image files are treated as binary by default. | ||
############################################################################### | ||
#*.jpg binary | ||
#*.png binary | ||
#*.gif binary | ||
|
||
############################################################################### | ||
# diff behavior for common document formats | ||
# | ||
# Convert binary document formats to text before diffing them. This feature | ||
# is only available from the command line. Turn it on by uncommenting the | ||
# entries below. | ||
############################################################################### | ||
#*.doc diff=astextplain | ||
#*.DOC diff=astextplain | ||
#*.docx diff=astextplain | ||
#*.DOCX diff=astextplain | ||
#*.dot diff=astextplain | ||
#*.DOT diff=astextplain | ||
#*.pdf diff=astextplain | ||
#*.PDF diff=astextplain | ||
#*.rtf diff=astextplain | ||
#*.RTF diff=astextplain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
function Invoke-Cmd { | ||
<# | ||
.SYNOPSIS | ||
Executes a Invoke-Expression / CMD.Exe based on the Given Parameters. Allows for re-using part of program code and mocking | ||
.DESCRIPTION | ||
<will add later based on actual code > | ||
.PARAMETER Executable | ||
<not used currently> | ||
.PARAMETER Arguments | ||
Specifies the Arguments for which the Invoked Cmd should use. | ||
.PARAMETER logfile | ||
Specifies the Arguments for which the Invoked Cmd should use. | ||
.PARAMETER errorlogfile | ||
Specifies the Arguments for which the Invoked Cmd should use. | ||
.OUTPUTS | ||
A result set with the outcome of the process along with some metrics. | ||
.EXAMPLE | ||
Invoke-Cmd -Arguments <add some arguments> | ||
Will execute the following command: | ||
.LINK | ||
Project home: https://github.com/tsteenbakkers/MSSQL-CICD-Helper | ||
.NOTES | ||
Name: MSSQLCICDHelper | ||
Author: Tobi Steenbakkers | ||
Version: 1.0.0 | ||
#> | ||
[cmdletbinding()] | ||
param( | ||
[Parameter(Mandatory=$true, | ||
HelpMessage='What to find: *.sln, *.dacpac, *.publish.xml *.dtspac or *.sqlproject File. Options are: Solution, DacPac, DTSPac or Project', | ||
Position=0)] | ||
[ValidateNotNullOrEmpty()] | ||
$executable, | ||
|
||
[Parameter(Mandatory=$true, | ||
HelpMessage='Path where search for $typetofind should be started', | ||
Position=0)] | ||
[ValidateNotNullOrEmpty()] | ||
$arguments, | ||
|
||
[Parameter(Mandatory=$true, | ||
HelpMessage='Determines the basepath where logfiles should be stored. if empty the directory where the script is running will be used', | ||
Position=0)] | ||
[Alias("lf")] | ||
[ValidateNotNullOrEmpty()] | ||
[String] $logfile, | ||
|
||
[Parameter(Mandatory=$true, | ||
HelpMessage='Determines the basepath where logfiles should be stored. if empty the directory where the script is running will be used', | ||
Position=0)] | ||
[Alias("elf")] | ||
[ValidateNotNullOrEmpty()] | ||
[String] $errorlogfile | ||
) | ||
$poutput = @{} | ||
$poutput.Output = [string]::Empty | ||
$poutput.ErrorOutput = [string]::Empty | ||
$poutput.Message = [string]::Empty | ||
$poutput.Duration = [TimeSpan]::Zero | ||
$poutput.Succeeded = $null | ||
$poutput.ExitCode = $null | ||
|
||
$logbase = Split-Path -path $logfile -Parent | ||
$errorlogbase = Split-Path -path $logfile -Parent | ||
|
||
if(-not(Test-Path -Path $logbase) -or -not(Test-Path -Path $errorlogbase)){ | ||
|
||
$poutput.Message = "Could not find parent of $logfile or $errorlogfile unable to proceed to execute Cmd." | ||
|
||
Write-Error "$($poutput.message)" | ||
return $result | ||
throw; | ||
} | ||
|
||
try{ | ||
|
||
$pinfo = New-Object System.Diagnostics.ProcessStartInfo | ||
$pinfo.FileName = $executable | ||
$pinfo.Arguments = $arguments | ||
|
||
#$pinfo.Passthru = $true | ||
$pinfo.RedirectStandardError = $true | ||
$pinfo.RedirectStandardOutput = $true | ||
$pinfo.UseShellExecute = $false | ||
|
||
if($debug){ | ||
$pinfo | ||
} | ||
#executing the command and storing the result inside $p: | ||
$p = New-Object System.Diagnostics.Process | ||
$p.StartInfo = $pinfo | ||
$p.Start() | Out-Null | ||
|
||
$poutput.output = $p.StandardOutput.ReadToEnd() | ||
$poutput.erroroutput = $p.StandardError.read() | ||
$poutput.Duration = $p.ExitTime - $p.StartTime | ||
$poutput.output | Out-file -literalpath $logfile -Force | ||
$poutput.erroroutput | Out-file -literalpath $errorlogfile -Force | ||
$poutput.ExitCode = $p.ExitCode | ||
|
||
return $poutput | ||
|
||
}catch{ | ||
$errorMessage = $_ | ||
$poutput.Message = "Unexpected error occurred while processing : $errorMessage" | ||
$poutput.Succeeded = $false | ||
Write-Error ($poutput.Message) | ||
return $poutput | ||
throw; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.