-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from awickham10/development
Initial Release
- Loading branch information
Showing
49 changed files
with
2,651 additions
and
2 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,49 @@ | ||
<# | ||
.SYNOPSIS | ||
Bootstrap PSDepend | ||
.DESCRIPTION | ||
Bootstrap PSDepend | ||
Why? No reliance on PowerShellGallery | ||
* Downloads nuget to your ~\ home directory | ||
* Creates $Path (and full path to it) | ||
* Downloads module to $Path\PSDepend | ||
* Moves nuget.exe to $Path\PSDepend (skips nuget bootstrap on initial PSDepend import) | ||
.PARAMETER Path | ||
Module path to install PSDepend | ||
Defaults to Profile\Documents\WindowsPowerShell\Modules | ||
.EXAMPLE | ||
.\Install-PSDepend.ps1 -Path C:\Modules | ||
# Installs to C:\Modules\PSDepend | ||
#> | ||
[cmdletbinding()] | ||
param( | ||
[string]$Path = $( Join-Path ([Environment]::GetFolderPath('MyDocuments')) 'WindowsPowerShell\Modules') | ||
) | ||
$ExistingProgressPreference = "$ProgressPreference" | ||
$ProgressPreference = 'SilentlyContinue' | ||
try { | ||
# Bootstrap nuget if we don't have it | ||
if(-not ($NugetPath = (Get-Command 'nuget.exe' -ErrorAction SilentlyContinue).Path)) { | ||
$NugetPath = Join-Path $ENV:USERPROFILE nuget.exe | ||
if(-not (Test-Path $NugetPath)) { | ||
Invoke-WebRequest -uri 'https://dist.nuget.org/win-x86-commandline/latest/nuget.exe' -OutFile $NugetPath | ||
} | ||
} | ||
|
||
# Bootstrap PSDepend, re-use nuget.exe for the module | ||
if($path) { $null = mkdir $path -Force } | ||
$NugetParams = 'install', 'PSDepend', '-Source', 'https://www.powershellgallery.com/api/v2/', | ||
'-ExcludeVersion', '-NonInteractive', '-OutputDirectory', $Path | ||
& $NugetPath @NugetParams | ||
Move-Item -Path $NugetPath -Destination "$(Join-Path $Path PSDepend)\nuget.exe" -Force | ||
} | ||
finally { | ||
$ProgressPreference = $ExistingProgressPreference | ||
} |
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,17 @@ | ||
param( | ||
$Task = 'Default' | ||
) | ||
|
||
# dependencies | ||
Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null | ||
if(-not (Get-Module -ListAvailable PSDepend)) { | ||
& (Resolve-Path "$PSScriptRoot\Helpers\Install-PSDepend.ps1") | ||
} | ||
|
||
Import-Module PSDepend | ||
$null = Invoke-PSDepend -Path "$PSScriptRoot\build.requirements.psd1" -Install -Import -Force | ||
|
||
Set-BuildEnvironment -Force | ||
|
||
Invoke-psake $PSScriptRoot\psake.ps1 -taskList $Task -nologo | ||
exit ( [int]( -not $psake.build_success ) ) |
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,17 @@ | ||
@{ | ||
# Some defaults for all dependencies | ||
PSDependOptions = @{ | ||
Target = '$ENV:USERPROFILE\Documents\WindowsPowerShell\Modules' | ||
AddToPath = $True | ||
Parameters = @{ | ||
Force = $True | ||
} | ||
} | ||
|
||
'psake' = '4.7.0' | ||
'PSDeploy' = '0.2.5' | ||
'BuildHelpers' = '1.1.1' | ||
'Pester' = '4.6.0' | ||
'PSFramework' = '0.10.31.176' | ||
'PSCodeCovIo' = '1.0.1' | ||
} |
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,62 @@ | ||
# Generic module deployment. | ||
# | ||
# ASSUMPTIONS: | ||
# | ||
# * folder structure either like: | ||
# | ||
# - RepoFolder | ||
# - This PSDeploy file | ||
# - ModuleName | ||
# - ModuleName.psd1 | ||
# | ||
# OR the less preferable: | ||
# - RepoFolder | ||
# - RepoFolder.psd1 | ||
# | ||
# * Nuget key in $ENV:NugetApiKey | ||
# | ||
# * Set-BuildEnvironment from BuildHelpers module has populated ENV:BHModulePath and related variables | ||
|
||
# Publish to gallery with a few restrictions | ||
if( | ||
$env:BHModulePath -and | ||
$env:BHBuildSystem -ne 'Unknown' -and | ||
$env:BHBranchName -eq "master" -and | ||
$env:BHCommitMessage -match '!deploy' | ||
) | ||
{ | ||
Deploy Module { | ||
By PSGalleryModule { | ||
FromSource $ENV:BHModulePath | ||
To PSGallery | ||
WithOptions @{ | ||
ApiKey = $ENV:NugetApiKey | ||
} | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
"Skipping deployment: To deploy, ensure that...`n" + | ||
"`t* You are in a known build system (Current: $ENV:BHBuildSystem)`n" + | ||
"`t* You are committing to the master branch (Current: $ENV:BHBranchName) `n" + | ||
"`t* Your commit message includes !deploy (Current: $ENV:BHCommitMessage)" | | ||
Write-Host | ||
} | ||
|
||
# Publish to AppVeyor if we're in AppVeyor | ||
if( | ||
$env:BHModulePath -and | ||
$env:BHBuildSystem -eq 'AppVeyor' | ||
) | ||
{ | ||
Deploy DeveloperBuild { | ||
By AppVeyorModule { | ||
FromSource $ENV:BHModulePath | ||
To AppVeyor | ||
WithOptions @{ | ||
Version = $env:APPVEYOR_BUILD_VERSION | ||
} | ||
} | ||
} | ||
} |
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,100 @@ | ||
# PSake makes variables declared here available in other scriptblocks | ||
# Init some things | ||
Properties { | ||
# Find the build folder based on build system | ||
$ProjectRoot = $ENV:BHProjectPath | ||
if(-not $ProjectRoot) | ||
{ | ||
$ProjectRoot = Resolve-Path "$PSScriptRoot\.." | ||
} | ||
|
||
$Timestamp = Get-Date -UFormat "%Y%m%d-%H%M%S" | ||
$PSVersion = $PSVersionTable.PSVersion.Major | ||
$TestFile = "TestResults_PS$PSVersion`_$TimeStamp.xml" | ||
$lines = '----------------------------------------------------------------------' | ||
|
||
$Verbose = @{} | ||
if($ENV:BHCommitMessage -match "!verbose") | ||
{ | ||
$Verbose = @{Verbose = $True} | ||
} | ||
} | ||
|
||
Task Default -Depends Test | ||
|
||
Task Init { | ||
$lines | ||
Set-Location $ProjectRoot | ||
"Build System Details:" | ||
Get-Item ENV:BH* | ||
"`n" | ||
} | ||
|
||
Task Test -Depends Init { | ||
$lines | ||
"`n`tSTATUS: Testing with PowerShell $PSVersion" | ||
|
||
# Testing links on github requires >= tls 1.2 | ||
$SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol | ||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | ||
|
||
$CodeFiles = (Get-ChildItem $ENV:BHModulePath -Recurse -Include "*.psm1","*.ps1").FullName | ||
|
||
# Gather test results. Store them in a variable and file | ||
$TestResults = Invoke-Pester -Path "$ProjectRoot\Tests" -CodeCoverage $CodeFiles -PassThru -OutputFormat 'NUnitXml' -OutputFile "$ProjectRoot\$TestFile" | ||
[Net.ServicePointManager]::SecurityProtocol = $SecurityProtocol | ||
|
||
# In Appveyor? Upload our tests! #Abstract this into a function? | ||
If($ENV:BHBuildSystem -eq 'AppVeyor') | ||
{ | ||
(New-Object 'System.Net.WebClient').UploadFile( | ||
"https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", | ||
"$ProjectRoot\$TestFile" ) | ||
|
||
Export-CodeCovIoJson -CodeCoverage $TestResults.CodeCoverage -RepoRoot $pwd -Path 'coverage.json' | ||
|
||
$env:PATH = 'C:\msys64\usr\bin;' + $env:PATH | ||
Invoke-WebRequest -Uri 'https://codecov.io/bash' -OutFile 'codecov.sh' | ||
bash codecov.sh -f "coverage.json" -t $ENV:CODECOV_TOKEN | ||
} | ||
|
||
Remove-Item "$ProjectRoot\$TestFile" -Force -ErrorAction SilentlyContinue | ||
# Failed tests? | ||
# Need to tell psake or it will proceed to the deployment. Danger! | ||
if($TestResults.FailedCount -gt 0) | ||
{ | ||
Write-Error "Failed '$($TestResults.FailedCount)' tests, build failed" | ||
} | ||
"`n" | ||
} | ||
|
||
Task Build -Depends Test { | ||
$lines | ||
|
||
# Load the module, read the exported functions, update the psd1 FunctionsToExport | ||
Set-ModuleFunctions | ||
|
||
# Bump the module version if we didn't already | ||
Try | ||
{ | ||
$GalleryVersion = Get-NextPSGalleryVersion -Name $env:BHProjectName -ErrorAction Stop | ||
$GithubVersion = Get-MetaData -Path $env:BHPSModuleManifest -PropertyName ModuleVersion -ErrorAction Stop | ||
if($GalleryVersion -ge $GithubVersion) { | ||
Update-Metadata -Path $env:BHPSModuleManifest -PropertyName ModuleVersion -Value $GalleryVersion -ErrorAction stop | ||
} | ||
} | ||
Catch | ||
{ | ||
"Failed to update version for '$env:BHProjectName': $_.`nContinuing with existing version" | ||
} | ||
} | ||
|
||
Task Deploy -Depends Build { | ||
$lines | ||
|
||
$Params = @{ | ||
Path = "$ProjectRoot\Build" | ||
Force = $true | ||
} | ||
Invoke-PSDeploy @Verbose @Params | ||
} |
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,30 @@ | ||
class AccessToken { | ||
[int] $AccessTokenId | ||
[string] $AccessToken | ||
[string] $TokenType | ||
[int] $ExpiresIn | ||
[string] $UserType | ||
[string] $Jti | ||
[DateTime] $Expiration | ||
|
||
AccessToken ([PSCustomObject] $Json) { | ||
$this.AccessTokenId = $Json.id | ||
$this.AccessToken = $Json.access_token | ||
$this.TokenType = $Json.token_type | ||
$this.ExpiresIn = $Json.expires_in | ||
$this.UserType = $Json.userType | ||
$this.Jti = $Json.jti | ||
$this.Expiration = (Get-Date).AddSeconds($this.ExpiresIn) | ||
} | ||
|
||
[string] ToAuthorizationHeader() { | ||
return "$($this.TokenType) $($this.AccessToken)" | ||
} | ||
|
||
[bool] IsValid() { | ||
return ` | ||
(Get-Date) -lt $this.Expiration -and | ||
$null -ne $this.AccessToken -and | ||
$null -ne $this.TokenType | ||
} | ||
} |
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,33 @@ | ||
class Annotation { | ||
[int] $AnnotationId | ||
[int] $DatabaseId | ||
[string] $CreatedBy | ||
[string] $Type | ||
[string] $Title | ||
[string] $Description | ||
[Datetime] $Time | ||
[Monitor] $Monitor | ||
|
||
Annotation ([PSCustomObject] $Json) { | ||
$this.InitializeFromJson($Json) | ||
|
||
$this.DatabaseId = $Json.dbId | ||
$this.Monitor = Get-DpaMonitor -DatabaseId $Json.DatabaseId | ||
} | ||
|
||
Annotation ([Monitor] $Monitor, [PSCustomObject] $Json) { | ||
$this.InitializeFromJson($Json) | ||
|
||
$this.DatabaseId = $Monitor.DatabaseId | ||
$this.Monitor = $Monitor | ||
} | ||
|
||
hidden InitializeFromJson ([PSCustomObject] $Json) { | ||
$this.AnnotationId = $Json.id | ||
$this.CreatedBy = $Json.createdBy | ||
$this.Type = $Json.type | ||
$this.Title = $Json.title | ||
$this.Description = $Json.description | ||
$this.Time = $Json.time | ||
} | ||
} |
Oops, something went wrong.