From 11c8ed74a7b0694bb87c49a96d490d27d4b563c5 Mon Sep 17 00:00:00 2001 From: Robert McLeod Date: Fri, 3 Apr 2020 22:48:55 +1100 Subject: [PATCH] Skeleton Module --- .gitignore | 2 + LICENSE | 21 ++++ PSScriptAnalyzerSettings.psd1 | 68 +++++++++++ PwshSparkPost.psd1 | 141 +++++++++++++++++++++++ PwshSparkPost.psm1 | 14 +++ azure-pipelines.yml | 209 ++++++++++++++++++++++++++++++++++ functions/.gitkeep | 0 gitversion.yml | 2 + internal/.gitkeep | 0 tests/.gitkeep | 0 10 files changed, 457 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 PSScriptAnalyzerSettings.psd1 create mode 100644 PwshSparkPost.psd1 create mode 100644 PwshSparkPost.psm1 create mode 100644 azure-pipelines.yml create mode 100644 functions/.gitkeep create mode 100644 gitversion.yml create mode 100644 internal/.gitkeep create mode 100644 tests/.gitkeep diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9bea433 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +.DS_Store diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..bb91b0f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Telstra Purple Pty. Ltd. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/PSScriptAnalyzerSettings.psd1 b/PSScriptAnalyzerSettings.psd1 new file mode 100644 index 0000000..999fb54 --- /dev/null +++ b/PSScriptAnalyzerSettings.psd1 @@ -0,0 +1,68 @@ +@{ + IncludeRules = @( + 'PSAlignAssignmentStatement', + 'PSAvoid*', + 'PSDSC*', + 'PSMisleadingBacktick', + 'PSMissingModuleManifestField', + 'PSPlaceCloseBrace', + 'PSPlaceOpenBrace', + 'PSPossibleIncorrectComparisonWithNull', + 'PSPossibleIncorrectUsageOfAssignmentOperator', + 'PSPossibleIncorrectUsageOfRedirectionOperator', + 'PSProvideCommentHelp', + 'PSReservedCmdletChar', + 'PSReservedParams', + 'PSShouldProcess', + 'PSUse*' + ) + + Rules = @{ + PSPlaceOpenBrace = @{ + Enable = $true + OnSameLine = $true + NewLineAfter = $true + IgnoreOneLineBlock = $true + } + + PSPlaceCloseBrace = @{ + Enable = $true + NewLineAfter = $false + IgnoreOneLineBlock = $true + NoEmptyLineBefore = $false + } + + PSUseConsistentIndentation = @{ + Enable = $true + Kind = 'space' + PipelineIndentation = 'IncreaseIndentationForFirstPipeline' + IndentationSize = 4 + } + + PSUseConsistentWhitespace = @{ + Enable = $true + CheckInnerBrace = $true + CheckOpenBrace = $false # incorrectly flags all `Should -Throw` Pester assertions + CheckOpenParen = $true + CheckOperator = $false # conflicts with `PSAlignAssignmentStatement` + CheckPipe = $true + CheckSeparator = $true + CheckParameter = $true + } + + PSAlignAssignmentStatement = @{ + Enable = $true + CheckHashtable = $true + } + + PSUseCorrectCasing = @{ + Enable = $true + } + } + + Severity = @( + 'Error' + 'Warning' + 'Information' + ) +} diff --git a/PwshSparkPost.psd1 b/PwshSparkPost.psd1 new file mode 100644 index 0000000..5513c31 --- /dev/null +++ b/PwshSparkPost.psd1 @@ -0,0 +1,141 @@ +# +# Module manifest for module 'PwshSparkPost' +# +# Generated by: rob +# +# Generated on: 3/4/2020 +# + +@{ + +# Script module or binary module file associated with this manifest. +RootModule = './PwshSparkPost.psm1' + +# Version number of this module. +ModuleVersion = '0.1.0' + +# Supported PSEditions +CompatiblePSEditions = @( + 'Core' + 'Desktop' +) + +# ID used to uniquely identify this module +GUID = '6ae6071f-86cd-4ece-916b-8aef4861f838' + +# Author of this module +Author = 'Telstra Purple DevSecOps' + +# Company or vendor of this module +CompanyName = 'Telstra Purple Pty Ltd' + +# Copyright statement for this module +Copyright = '(c) 2020 Telstra Purple Pty Ltd. All rights reserved.' + +# Description of the functionality provided by this module +Description = 'SparkPost Api client' + +# Minimum version of the PowerShell engine required by this module +PowerShellVersion = '5.1' + +# Name of the PowerShell host required by this module +# PowerShellHostName = '' + +# Minimum version of the PowerShell host required by this module +# PowerShellHostVersion = '' + +# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# DotNetFrameworkVersion = '' + +# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# ClrVersion = '' + +# Processor architecture (None, X86, Amd64) required by this module +# ProcessorArchitecture = '' + +# Modules that must be imported into the global environment prior to importing this module +# RequiredModules = @() + +# Assemblies that must be loaded prior to importing this module +# RequiredAssemblies = @() + +# Script files (.ps1) that are run in the caller's environment prior to importing this module. +# ScriptsToProcess = @() + +# Type files (.ps1xml) to be loaded when importing this module +# TypesToProcess = @() + +# Format files (.ps1xml) to be loaded when importing this module +# FormatsToProcess = @() + +# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess +# NestedModules = @() + +# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. +FunctionsToExport = @() + +# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. +CmdletsToExport = @() + +# Variables to export from this module +# VariablesToExport = '*' + +# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. +AliasesToExport = @() + +# DSC resources to export from this module +# DscResourcesToExport = @() + +# List of all modules packaged with this module +# ModuleList = @() + +# List of all files packaged with this module +# FileList = @() + +# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. +PrivateData = @{ + + PSData = @{ + + # Tags applied to this module. These help with module discovery in online galleries. + Tags = @( + 'PSEdition_Desktop' + 'PSEdition_Core' + 'Windows' + 'Linux' + 'MacOS' + ) + + # A URL to the license for this module. + # LicenseUri = '' + + # A URL to the main website for this project. + ProjectUri = 'https://github.com/Readify/PwshSparkPost' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + # ReleaseNotes = '' + + # Prerelease string of this module + # Prerelease = '' + + # Flag to indicate whether the module requires explicit user acceptance for install/update/save + # RequireLicenseAcceptance = $false + + # External dependent modules of this module + # ExternalModuleDependencies = @() + + } # End of PSData hashtable + +} # End of PrivateData hashtable + +# HelpInfo URI of this module +# HelpInfoURI = '' + +# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. +DefaultCommandPrefix = 'SparkPost' + +} + diff --git a/PwshSparkPost.psm1 b/PwshSparkPost.psm1 new file mode 100644 index 0000000..55c2c54 --- /dev/null +++ b/PwshSparkPost.psm1 @@ -0,0 +1,14 @@ + +Set-StrictMode -Version Latest + +Get-ChildItem -Path "$PSScriptRoot\functions" -Filter '*.ps1' -Recurse | ForEach-Object { + . $_.FullName + Export-ModuleMember -Function $_.BaseName +} + +Get-ChildItem -Path "$PSScriptRoot\internal" -Filter '*.ps1' -Recurse | ForEach-Object { + . $_.FullName +} + +$Script:NotConnectedMessage = 'No connection supplied or stored. Please either call `Connect-SparkPost` or call `Get-SparkPostConnection` and pass the result to all additional calls.' +$Script:InvalidConnection = 'Provided connection is invalid.' diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..eb49250 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,209 @@ + +trigger: +- master + +stages: + +- stage: Build + jobs: + + - job: Build + pool: + vmImage: 'macOS-10.14' + steps: + - checkout: self + clean: true + - script: brew install gitversion + displayName: Install Gitversion + - pwsh: | + $version = gitversion | ConvertFrom-Json | ForEach-Object MajorMinorPatch + Write-Host "##vso[build.updatebuildnumber]$version" + displayName: Set Build Number + - pwsh: | + $rawManifest = Get-Content -Path "PwshSparkPost.psd1" -raw + $updatedManifest = $rawManifest -replace "ModuleVersion\s*=\s*['`"][0-9.]+['`"]", "ModuleVersion = '$(Build.BuildNumber)'" + $updatedManifest | Out-File -Path "PwshSparkPost.psd1" -NoNewline + displayName: Update Module Manifest Version Number + - task: CopyFiles@2 + inputs: + contents: | + **/* + !**/.*/**/* + !**/.* + !azure-pipelines.yml + !gitversion.yml + targetFolder: $(Build.ArtifactStagingDirectory)/PwshSparkPost + - publish: '$(Build.ArtifactStagingDirectory)/PwshSparkPost' + artifact: 'files' + displayName: 'Publish Artifact files' + - task: ArchiveFiles@2 + inputs: + rootFolderOrFile: $(Build.ArtifactStagingDirectory)/PwshSparkPost + archiveFile: '$(Build.ArtifactStagingDirectory)/PwshSparkPost_$(Build.BuildNumber).zip' + displayName: 'Archive zip' + - publish: '$(Build.ArtifactStagingDirectory)/PwshSparkPost_$(Build.BuildNumber).zip' + artifact: 'zip' + displayName: 'Publish Artifact zip' + - task: ArchiveFiles@2 + inputs: + rootFolderOrFile: $(Build.ArtifactStagingDirectory)/PwshSparkPost + archiveType: tar + archiveFile: '$(Build.ArtifactStagingDirectory)/PwshSparkPost_$(Build.BuildNumber).tar.gz' + displayName: 'Archive tar' + - publish: '$(Build.ArtifactStagingDirectory)/PwshSparkPost_$(Build.BuildNumber).tar.gz' + artifact: 'tar' + displayName: 'Publish Artifact tar' + +- stage: Test + jobs: + + - job: Mac_10_14 + pool: + vmImage: 'macOS-10.14' + steps: + - checkout: none + - download: current + artifact: files + - pwsh: $PSVersionTable | Out-String + displayName: PSVersionTable + - pwsh: | + Save-Module -Name PSScriptAnalyzer -Path '.' -Repository PSGallery -Confirm:$false + Import-Module -Name './PSScriptAnalyzer/' + Get-ChildItem -Path '$(Pipeline.Workspace)' -Directory | Invoke-ScriptAnalyzer -EnableExit | Format-Table -AutoSize + displayName: Script Analyzer + - pwsh: | + Save-Module -Name Pester -Path '.' -Repository PSGallery -Confirm:$false + Import-Module -Name './Pester/' + Set-Location -Path '$(Pipeline.Workspace)' + Invoke-Pester -EnableExit -OutputFile "$(System.DefaultWorkingDirectory)/Test-Pester-Mac.xml" -OutputFormat NUnitXML + displayName: Pester + - task: PublishTestResults@2 + condition: succeededOrFailed() + inputs: + testResultsFormat: 'NUnit' + testResultsFiles: 'Test-Pester-Mac.xml' + searchFolder: $(System.DefaultWorkingDirectory) + mergeTestResults: true + buildPlatform: Mac 10.14 + + - job: Ubuntu_18_04 + pool: + vmImage: 'ubuntu-18.04' + steps: + - checkout: none + - download: current + artifact: files + - pwsh: $PSVersionTable | Out-String + displayName: PSVersionTable + - pwsh: | + Save-Module -Name PSScriptAnalyzer -Path '.' -Repository PSGallery -Confirm:$false + Import-Module -Name './PSScriptAnalyzer/' + Get-ChildItem -Path '$(Pipeline.Workspace)' -Directory | Invoke-ScriptAnalyzer -EnableExit | Format-Table -AutoSize + displayName: Script Analyzer + - pwsh: | + Save-Module -Name Pester -Path '.' -Repository PSGallery -Confirm:$false + Import-Module -Name './Pester/' + Set-Location -Path '$(Pipeline.Workspace)' + Invoke-Pester -EnableExit -OutputFile "$(System.DefaultWorkingDirectory)/Test-Pester-Ubuntu.xml" -OutputFormat NUnitXML + displayName: Pester + - task: PublishTestResults@2 + condition: succeededOrFailed() + inputs: + testResultsFormat: 'NUnit' + testResultsFiles: 'Test-Pester-Ubuntu.xml' + searchFolder: $(System.DefaultWorkingDirectory) + mergeTestResults: true + buildPlatform: Ubuntu 18.04 + + - job: Windows_2019_Pwsh + pool: + vmImage: 'windows-2019' + steps: + - checkout: none + - download: current + artifact: files + - pwsh: $PSVersionTable | Out-String + displayName: PSVersionTable + - pwsh: | + Save-Module -Name PSScriptAnalyzer -Path '.' -Repository PSGallery -Confirm:$false + Import-Module -Name './PSScriptAnalyzer/' + Get-ChildItem -Path '$(Pipeline.Workspace)' -Directory | Invoke-ScriptAnalyzer -EnableExit | Format-Table -AutoSize + displayName: Script Analyzer + - pwsh: | + Save-Module -Name Pester -Path '.' -Repository PSGallery -Confirm:$false + Import-Module -Name './Pester/' + Set-Location -Path '$(Pipeline.Workspace)' + Invoke-Pester -EnableExit -OutputFile "$(System.DefaultWorkingDirectory)/Test-Pester-Win2019.xml" -OutputFormat NUnitXML + displayName: Pester + - task: PublishTestResults@2 + condition: succeededOrFailed() + inputs: + testResultsFormat: 'NUnit' + testResultsFiles: 'Test-Pester-Win2019.xml' + searchFolder: $(System.DefaultWorkingDirectory) + mergeTestResults: true + buildPlatform: Windows Server 2019 + + - job: Windows_2016_Powershell + pool: + vmImage: 'vs2017-win2016' + steps: + - checkout: none + - download: current + artifact: files + - powershell: $PSVersionTable | Out-String + displayName: PSVersionTable + - powershell: | + Save-Module -Name PSScriptAnalyzer -Path '.' -Repository PSGallery -Confirm:$false + Resolve-Path -Path './PSScriptAnalyzer/*/PSScriptAnalyzer.psd1' | Import-Module + Get-ChildItem -Path '$(Pipeline.Workspace)' -Directory | Invoke-ScriptAnalyzer -EnableExit | Format-Table -AutoSize + displayName: Script Analyzer + - powershell: | + Save-Module -Name Pester -Path '.' -Repository PSGallery -Confirm:$false + Resolve-Path -Path './Pester/*/Pester.psd1' | Import-Module + Set-Location -Path '$(Pipeline.Workspace)' + Invoke-Pester -EnableExit -OutputFile "$(System.DefaultWorkingDirectory)/Test-Pester-Win2016.xml" -OutputFormat NUnitXML + displayName: Pester + - task: PublishTestResults@2 + condition: succeededOrFailed() + inputs: + testResultsFormat: 'NUnit' + testResultsFiles: 'Test-Pester-Win2016.xml' + searchFolder: $(System.DefaultWorkingDirectory) + mergeTestResults: true + buildPlatform: Windows Server 2016 + +- stage: Deploy + condition: eq(variables['Build.SourceBranch'], 'refs/heads/master') + jobs: + + - job: Commit_Updated_Manifest + pool: + vmImage: 'macOS-10.14' + steps: + - checkout: self + clean: true + persistCredentials: true + - download: current + artifact: files + - pwsh: | + Move-Item -Path '$(Pipeline.Workspace)/files/PwshSparkPost.psd1' -Destination 'PwshSparkPost.psd1' -Confirm:$false -Force + git add PwshSparkPost.psd1 + git -c "user.name=$(Build.RequestedFor)" -c "user.email=$(Build.RequestedForEmail)" commit -m "Updated module version: $(Build.BuildNumber) [skip ci]" + git push origin HEAD:master + workingDirectory: '$(Build.SourcesDirectory)' + + - job: Github_Release + dependsOn: Commit_Updated_Manifest + steps: + - task: GithubRelease@0 + displayName: 'Create GitHub Release' + inputs: + target: master + gitHubConnection: RobFaie + repositoryName: Readify/PwshSparkPost + tagSource: manual + tag: $(Build.BuildNumber) + assets: | + $(Pipeline.Workspace)/zip/*.zip + $(Pipeline.Workspace)/tar/*.tar diff --git a/functions/.gitkeep b/functions/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/gitversion.yml b/gitversion.yml new file mode 100644 index 0000000..4690a72 --- /dev/null +++ b/gitversion.yml @@ -0,0 +1,2 @@ +mode: Mainline +no-bump-message: '\[skip ci\]|\+semver:\s?(none|skip)' \ No newline at end of file diff --git a/internal/.gitkeep b/internal/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/.gitkeep b/tests/.gitkeep new file mode 100644 index 0000000..e69de29