From 86fa13f36d314b45c8e24aade266c9b27282d3d9 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Thu, 27 Jul 2017 14:20:34 +0200 Subject: [PATCH] adds basic module layout --- .vscode/cSpell.json | 39 +++++++ .vscode/settings.json | 50 +++++++++ appveyor.yml | 54 +++++++++ bin/.gitignore | 1 + resources/.gitignore | 0 resources/cs/Broken_CS.json | 3 + resources/cs/Challenge.bin | 1 + resources/cs/CredentialStore.json | Bin 0 -> 2084 bytes src/PSCredentialStore.psd1 | 123 +++++++++++++++++++++ tests/.gitignore | 0 tools/AppVeyor.psm1 | 178 ++++++++++++++++++++++++++++++ 11 files changed, 449 insertions(+) create mode 100644 .vscode/cSpell.json create mode 100644 .vscode/settings.json create mode 100644 appveyor.yml create mode 100644 bin/.gitignore create mode 100644 resources/.gitignore create mode 100644 resources/cs/Broken_CS.json create mode 100644 resources/cs/Challenge.bin create mode 100644 resources/cs/CredentialStore.json create mode 100644 src/PSCredentialStore.psd1 create mode 100644 tests/.gitignore create mode 100644 tools/AppVeyor.psm1 diff --git a/.vscode/cSpell.json b/.vscode/cSpell.json new file mode 100644 index 0000000..ed2510a --- /dev/null +++ b/.vscode/cSpell.json @@ -0,0 +1,39 @@ +// cSpell Settings +{ + // Version of the setting file. Always 0.1 + "version": "0.1", + // language - current active spelling language + "language": "en", + // words - list of words to be always considered correct + "words": [ + "Ponduit", + "NTFS", + "Repo", + "Hashtable", + "googlemail", + "Cmdlet", + "appveyor", + "GUID", + "wildcards", + "Cmdlets", + "codecoverage", + "notmatch", + "Httpclient", + "Multipart", + "formdata", + "callsign", + "Veyor", + "notlike", + "Params", + "testresults", + "powershellgallery", + "chocolatey", + "choco" + ], + // flagWords - list of words to be always considered incorrect + // This is useful for offensive words and common spelling errors. + // For example "hte" should be "the" + "flagWords": [ + "hte" + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..05e9a14 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,50 @@ +// Place your settings in this file to overwrite default and user settings. +{ + // Set basic file related options: + "files.encoding": "utf8", + "files.eol": "\r\n", + "files.trimTrailingWhitespace": true, + "files.insertFinalNewline": true, + // Formation and editor options + "editor.renderWhitespace": "boundary", + "editor.formatOnSave": true, + "editor.formatOnType": true, + "editor.rulers": [ + 116 + ], + // powershell general + "powershell.startAutomatically": true, + "powershell.useX86Host": false, + "powershell.enableProfileLoading": true, + "powershell.scriptAnalysis.enable": true, + // powershell code Formatting + "powershell.codeFormatting.openBraceOnSameLine": true, + "powershell.codeFormatting.newLineAfterOpenBrace": true, + "powershell.codeFormatting.newLineAfterCloseBrace": true, + "powershell.codeFormatting.whitespaceBeforeOpenBrace": true, + "powershell.codeFormatting.whitespaceBeforeOpenParen": true, + "powershell.codeFormatting.whitespaceAroundOperator": true, + "powershell.codeFormatting.whitespaceAfterSeparator": true, + "powershell.codeFormatting.ignoreOneLineBlock": true, + "powershell.codeFormatting.alignPropertyValuePairs": false, + // cspell spellchecker options + "cSpell.enabledLanguageIds": [ + "c", + "cpp", + "csharp", + "go", + "javascript", + "javascriptreact", + "json", + "latex", + "markdown", + "php", + "plaintext", + "powershell", + "python", + "text", + "typescript", + "typescriptreact", + "yml" + ] +} diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..4b42772 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,54 @@ +version: 0.1.{build} + +branches: + only: + - master + - dev + - debug + +skip_tags: true + +#image: WMF 5 +# Test ne build image: +image: Visual Studio 2017 + +# Install pester module and init the Appveyor support. +install: + - ps: Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force -Verbose + - ps: Import-PackageProvider NuGet -MinimumVersion '2.8.5.201' -Force +# - ps: Install-Module -Name 'Pester' -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber +# - ps: Update-Module 'Pester' +# - ps: Install-Module -Name 'posh-git' -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber +# - ps: Update-Module 'posh-git' + - ps: Import-Module .\tools\AppVeyor.psm1 + +environment: + NuGetToken: + secure: 835qfZIkC9mE7QhkYfOZVAdR8rZhPvxG8BO4CbeaelRQOhlqmaSr8G1DWRJzZ/bS + CoverallsToken: + secure: eTjWqHL48MBr8wp1rSgLrXHdtpfDV/uClacP3svlWJfCvn/zVokpuaMnWM5RoyIY + +build: false + +before_build: + - ps: Invoke-AppVeyorBumpVersion + +build_script: + - ps: Invoke-AppVeyorBuild + +test_script: + - ps: Invoke-AppVeyorTests + - ps: Invoke-CoverageReport + +deploy: + - provider: GitHub + auth_token: + secure: M+bBX5/nKdJB0eViP7xtrLVTwf3vGDUA9N2MMprZp2i+9ZR3CBVcJnSzJWUmalhB + artifact: PSCredentialStore.zip # upload all NuGet packages to release assets + draft: false + prerelease: false + on: + branch: master # release from master branch only + +after_deploy: + - ps: Invoke-AppVeyorPSGallery diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..7756187 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1 @@ +This is a placeholder file. The build Server will create all bin files here. diff --git a/resources/.gitignore b/resources/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/resources/cs/Broken_CS.json b/resources/cs/Broken_CS.json new file mode 100644 index 0000000..23e8eee --- /dev/null +++ b/resources/cs/Broken_CS.json @@ -0,0 +1,3 @@ +{ + "Version": "1.2.0", + "Creation": "2016-06-14 08:41:10" diff --git a/resources/cs/Challenge.bin b/resources/cs/Challenge.bin new file mode 100644 index 0000000..3b80551 --- /dev/null +++ b/resources/cs/Challenge.bin @@ -0,0 +1 @@ +!pH4"=wS2 \ No newline at end of file diff --git a/resources/cs/CredentialStore.json b/resources/cs/CredentialStore.json new file mode 100644 index 0000000000000000000000000000000000000000..4d45b386150656d9a9c66102720bfe29dfa7623e GIT binary patch literal 2084 zcmeH{%Wl*_5JhW^#6Lt{1Mze0$(A3;0@&MaTgrx@nFti2{5o)MbtcnxX2B4aQOW(N zuGek%t>3?X+FN^L7mt$J7n^Knd%Lk)`)Zk8`AKGleef?w_ip9$5s%4wyL;wUT8`Jo z-ZN_~tR`M=9dT=RSA3@;ezJS}M$BXWYjWJ!ch4gIx`vs0Z*Aaw_vE$2cEEUg&g?U& zh5eW_#$4w*?SIf_c1;a?(-W?vUbfHbqu{vy+OS_alU4)_pk2LvI=M<0iCoXtJrHAPSa2%#7+^>ImYp_TrEFgjlEk(XdjlQFp93U9wiy$!5e;cp|rix_kz1TcC yL$_GTx?>a*#pkWZi(XpS=o +$CALLSIGN = 'PSCoverage' +Write-Host ("Callsign is: {0}" -f $CALLSIGN) -ForegroundColor Yellow + +Function Invoke-AppVeyorBumpVersion() { + [CmdletBinding()] + Param() + + Write-Host "Listing Env Vars for debugging:" -ForegroundColor Yellow + # Filter Results to prevent exposing secure vars. + Get-ChildItem -Path "Env:*" | Where-Object { $_.name -notmatch "(NuGetToken|CoverallsToken)"} | Sort-Object -Property Name | Format-Table + + Try { + $ModManifest = Get-Content -Path (".\src\{0}.psd1" -f $CALLSIGN) + $BumpedManifest = $ModManifest -replace '\$Env:APPVEYOR_BUILD_VERSION', "'$Env:APPVEYOR_BUILD_VERSION'" + Remove-Item -Path (".\src\{0}.psd1" -f $CALLSIGN) + Out-File -FilePath (".\src\{0}.psd1" -f $CALLSIGN) -InputObject $BumpedManifest -NoClobber -Encoding utf8 -Force + } + Catch { + $MsgParams = @{ + Message = 'Could not bump current version into module manifest.' + Category = 'Error' + Details = $_.Exception.Message + } + Add-AppveyorMessage @MsgParams + Throw $MsgParams.Message + } +} + +Function Invoke-AppVeyorBuild() { + [CmdletBinding()] + Param() + $MsgParams = @{ + Message = 'Creating build artifacts' + Category = 'Information' + Details = 'Extracting source files and compressing them into zip file.' + } + Add-AppveyorMessage @MsgParams + $CompParams = @{ + Path = "{0}\src\*" -f $env:APPVEYOR_BUILD_FOLDER + DestinationPath = "{0}\bin\{1}.zip" -f $env:APPVEYOR_BUILD_FOLDER, $CALLSIGN + Update = $True + Verbose = $True + } + Compress-Archive @CompParams + $MsgParams = @{ + Message = 'Pushing artifacts' + Category = 'Information' + Details = 'Pushing artifacts to AppVeyor store.' + } + Add-AppveyorMessage @MsgParams + Push-AppveyorArtifact (".\bin\{0}.zip" -f $CALLSIGN) +} + +Function Invoke-AppVeyorTests() { + [CmdletBinding()] + Param() + + $MsgParams = @{ + Message = 'Starting Pester tests' + Category = 'Information' + Details = 'Now running all test found in .\tests\ dir.' + } + Add-AppveyorMessage @MsgParams + $testresults = Invoke-Pester -Path ".\tests\*" -ExcludeTag 'Disabled' -PassThru + ForEach ($Item in $testresults.TestResult) { + Switch ($Item.Result) { + "Passed" { + $TestParams = @{ + Name = "{0}: {1}" -f $Item.Context, $Item.Name + Framework = "NUnit" + Filename = $Item.Describe + Outcome = "Passed" + Duration = $Item.Time.Milliseconds + } + Add-AppveyorTest @TestParams + } + "Failed" { + $TestParams = @{ + Name = "{0}: {1}" -f $Item.Context, $Item.Name + Framework = "NUnit" + Filename = $Item.Describe + Outcome = "Failed" + Duration = $Item.Time.Milliseconds + ErrorMessage = $Item.FailureMessage + ErrorStackTrace = $Item.StackTrace + } + Add-AppveyorTest @TestParams + } + Default { + $TestParams = @{ + Name = "{0}: {1}" -f $Item.Context, $Item.Name + Framework = "NUnit" + Filename = $Item.Describe + Outcome = "None" + Duration = $Item.Time.Milliseconds + ErrorMessage = $Item.FailureMessage + ErrorStackTrace = $Item.StackTrace + } + Add-AppveyorTest @TestParams + } + } + } + If ($testresults.FailedCount -gt 0) { + $MsgParams = @{ + Message = 'Pester Tests failed.' + Category = 'Error' + Details = "$($testresults.FailedCount) tests failed." + } + Add-AppveyorMessage @MsgParams + Throw $MsgParams.Message + } + +} + +Function Invoke-CoverageReport() { + [CmdletBinding()] + Param( + [Parameter(Mandatory = $False)] + [ValidateNotNullOrEmpty()] + [String]$RepoToken = $Env:CoverallsToken + ) + + Import-Module '.\src\PSCoverage.psm1' -Verbose -Force + $FileMap = New-PesterFileMap -SourceRoot '.\src' -PesterRoot '.\tests' + $CoverageReport = New-CoverageReport -PesterFileMap $FileMap -RepoToken $RepoToken + Write-Host "CoverageReport JSON:" -ForegroundColor Yellow + $CoverageReport | Out-String | Write-Host + Publish-CoverageReport -CoverageReport $CoverageReport +} + +Function Invoke-AppVeyorPSGallery() { + [CmdletBinding()] + Param() + Expand-Archive -Path (".\bin\{0}.zip" -f $CALLSIGN) -DestinationPath ("C:\Users\appveyor\Documents\WindowsPowerShell\Modules\{0}\" -f $CALLSIGN) -Verbose + Import-Module -Name $CALLSIGN -Verbose -Force + Write-Host "Available Package Provider:" -ForegroundColor Yellow + Get-PackageProvider -ListAvailable + Write-Host "Available Package Sources:" -ForegroundColor Yellow + Get-PackageSource + Try { + Write-Host "Try to get NuGet Provider:" -ForegroundColor Yellow + Get-PackageProvider -Name NuGet -ErrorAction Stop + } + Catch { + Write-Host "Installing NuGet..." -ForegroundColor Yellow + Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force -Verbose + Import-PackageProvider NuGet -MinimumVersion '2.8.5.201' -Force + } + Try { + If ($env:APPVEYOR_REPO_BRANCH -eq 'master') { + Write-Host "try to publish module" -ForegroundColor Yellow + Write-Host ("Callsign is: {0}" -f $CALLSIGN) -ForegroundColor Yellow + Publish-Module -Name $CALLSIGN -NuGetApiKey $env:NuGetToken -Verbose -Force + } + Else { + Write-Host "Skip publishing to PS Gallery because we are on $($env:APPVEYOR_REPO_BRANCH) branch." -ForegroundColor Yellow + # had to remove the publish-Module statement because it would publish although the -WhatIf is given. + # Publish-Module -Name $CALLSIGN -NuGetApiKey $env:NuGetToken -Verbose -WhatIf + } + } + Catch { + $MsgParams = @{ + Message = 'Could not deploy module to PSGallery.' + Category = 'Error' + Details = $_.Exception.Message + } + Add-AppveyorMessage @MsgParams + Throw $MsgParams.Message + } +}