diff --git a/PSDepend/PSDepend.psd1 b/PSDepend/PSDepend.psd1 new file mode 100644 index 0000000..15552a2 --- /dev/null +++ b/PSDepend/PSDepend.psd1 @@ -0,0 +1,111 @@ +@{ + +# Script module or binary module file associated with this manifest. +RootModule = 'PSDepend.psm1' + +# Version number of this module. +ModuleVersion = '0.0.1' + +# ID used to uniquely identify this module +GUID = '63ea9e2a-320d-43ff-a11a-4930ca03cce6' + +# Author of this module +Author = 'Warren Frame' + +# Company or vendor of this module +#CompanyName = 'Unknown' + +# Copyright statement for this module +Copyright = '(c) 2016 Warren F. All rights reserved.' + +# Description of the functionality provided by this module +Description = 'PowerShell Dependency Handler' + +# Minimum version of the Windows PowerShell engine required by this module +PowerShellVersion = '3.0' + +# Name of the Windows PowerShell host required by this module +# PowerShellHostName = '' + +# Minimum version of the Windows PowerShell host required by this module +# PowerShellHostVersion = '' + +# Minimum version of Microsoft .NET Framework required by this module +# DotNetFrameworkVersion = '' + +# Minimum version of the common language runtime (CLR) required by this module +# 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 = '.Format.ps1xml' + +# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess +# NestedModules = @() + +# Functions to export from this module +FunctionsToExport = '*' + +# Cmdlets to export from this module +CmdletsToExport = '*' + +# Variables to export from this module +VariablesToExport = '*' + +# Aliases to export from this module +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 = @('requirements', 'dependencies', 'dependency') + + # A URL to the license for this module. + LicenseUri = 'https://github.com/RamblingCookieMonster/PSDepend/blob/master/LICENSE' + + # A URL to the main website for this project. + ProjectUri = 'https://github.com/RamblingCookieMonster/PSDepend/' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + # ReleaseNotes = '' + + } # 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 = '' + +} diff --git a/PSDepend/PSDepend.psm1 b/PSDepend/PSDepend.psm1 new file mode 100644 index 0000000..c063103 --- /dev/null +++ b/PSDepend/PSDepend.psm1 @@ -0,0 +1,29 @@ +#Get public and private function definition files. + $Public = @( Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -ErrorAction SilentlyContinue ) + $Private = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -ErrorAction SilentlyContinue ) + $ModuleRoot = $PSScriptRoot + +#Dot source the files + Foreach($import in @($Public + $Private)) + { + Try + { + . $import.fullname + } + Catch + { + Write-Error -Message "Failed to import function $($import.fullname): $_" + } + } + +# Load dependencies. TODO: Move to module dependency once the bug that +# causes this is fixed: https://ci.appveyor.com/project/RamblingCookieMonster/buildhelpers/build/1.0.22 +# Thanks to Joel Bennett for this! + Import-Module $PSScriptRoot\Private\Modules\Configuration + +Export-ModuleMember -Function $Public.Basename +Export-ModuleMember -Function Get-Metadata, Update-Metadata, Export-Metadata + +# Set aliases (#10) +Set-Alias -Name Set-BuildVariable -Value $PSScriptRoot\Scripts\Set-BuildVariable.ps1 +Export-ModuleMember -Alias Set-BuildVariable diff --git a/PSDepend/Public/Get-Dependency.ps1 b/PSDepend/Public/Get-Dependency.ps1 new file mode 100644 index 0000000..9170fff --- /dev/null +++ b/PSDepend/Public/Get-Dependency.ps1 @@ -0,0 +1,19 @@ +function Get-Dependency { + <# + .SYNOPSIS + Read a dependency file + + .DESCRIPTION + Read a dependency file + + .PARAMETER Path + Path to project root or dependency file. + + If a folder is specified, we search for and process *depends.psd1 files. + #> + [cmdletbinding()] + param( + $Path = $PWD.Path + ) + +} \ No newline at end of file diff --git a/PSDepend/en-US/about_PSDepend.help.txt b/PSDepend/en-US/about_PSDepend.help.txt new file mode 100644 index 0000000..e306379 --- /dev/null +++ b/PSDepend/en-US/about_PSDepend.help.txt @@ -0,0 +1,11 @@ +PSTOPIC + about_PSDepend + +SHORT DESCRIPTION + +LONG DESCRIPTION + +DETAILED DESCRIPTION + +LINK + https://github.com/RamblingCookieMonster/PSDepend \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..8162b8a --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +PSDepend +======== diff --git a/Tests/PSDepend.Tests.ps1 b/Tests/PSDepend.Tests.ps1 new file mode 100644 index 0000000..128a79a --- /dev/null +++ b/Tests/PSDepend.Tests.ps1 @@ -0,0 +1,25 @@ +$PSVersion = $PSVersionTable.PSVersion.Major +$ModuleName = $ENV:BHProjectName + +# Verbose output for non-master builds on appveyor +# Handy for troubleshooting. +# Splat @Verbose against commands as needed (here or in pester tests) + $Verbose = @{} + if($ENV:BHBranchName -notlike "master" -or $env:BHCommitMessage -match "!verbose") + { + $Verbose.add("Verbose",$True) + } + +Import-Module $PSScriptRoot\..\$ModuleName -Force + +Describe "$ModuleName PS$PSVersion" { + Context 'Strict mode' { + + Set-StrictMode -Version latest + + It 'Should load' { + $Module = Get-Module $ModuleName + $Module.Name | Should be $ModuleName + } + } +} diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..b92a324 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,20 @@ +# See http://www.appveyor.com/docs/appveyor-yml for many more options + +#Publish to PowerShell Gallery with this key +environment: + NuGetApiKey: + secure: oqMFzG8F65K5l572V7VzlZIWU7xnSYDLtSXECJAAURrXe8M2+BAp9vHLT+1h1lR0 + +# Allow WMF5 (i.e. PowerShellGallery functionality) +os: WMF 5 + +# Skip on updates to the readme. +# We can force this by adding [skip ci] or [ci skip] anywhere in commit message +skip_commits: + message: /updated readme.*|update readme.*s/ + +build: false + +#Kick off the CI/CD pipeline +test_script: + - ps: . .\build.ps1 \ No newline at end of file diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..8fcad7c --- /dev/null +++ b/build.ps1 @@ -0,0 +1,10 @@ +# Grab nuget bits, install modules, set build variables, start build. +Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null + +Install-Module Psake, PSDeploy, Pester, BuildHelpers -force +Import-Module Psake, BuildHelpers + +Set-BuildEnvironment + +Invoke-psake .\psake.ps1 +exit ( [int]( -not $psake.build_success ) ) \ No newline at end of file diff --git a/deploy.psdeploy.ps1 b/deploy.psdeploy.ps1 new file mode 100644 index 0000000..65a21d9 --- /dev/null +++ b/deploy.psdeploy.ps1 @@ -0,0 +1,29 @@ +# Generic module deployment. +# This stuff should be moved to psake for a cleaner deployment view + +# ASSUMPTIONS: + + # folder structure of: + # - RepoFolder + # - This PSDeploy file + # - ModuleName + # - ModuleName.psd1 + + # Nuget key in $ENV:NugetApiKey + + # Set-BuildEnvironment from BuildHelpers module has populated ENV:BHProjectName + +# find a folder that has psd1 of same name... + +if($ENV:BHProjectName -and $ENV:BHProjectName.Count -eq 1) +{ + Deploy Module { + By PSGalleryModule { + FromSource $ENV:BHProjectName + To PSGallery + WithOptions @{ + ApiKey = $ENV:NugetApiKey + } + } + } +} \ No newline at end of file diff --git a/psake.ps1 b/psake.ps1 new file mode 100644 index 0000000..8feb626 --- /dev/null +++ b/psake.ps1 @@ -0,0 +1,88 @@ +# 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 = $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 Deploy + +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" + + # Gather test results. Store them in a variable and file + $TestResults = Invoke-Pester -Path $ProjectRoot\Tests -PassThru -OutputFormat NUnitXml -OutputFile "$ProjectRoot\$TestFile" + + # 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" ) + } + + 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 + #Set-ModuleFunctions +} + +Task Deploy -Depends Build { + $lines + + # Gate deployment + if( + $ENV:BHBuildSystem -ne 'Unknown' -and + $ENV:BHBranchName -eq "master" -and + $ENV:BHCommitMessage -match '!deploy' + ) + { + $Params = @{ + Path = $ProjectRoot + Force = $true + } + + Invoke-PSDeploy @Verbose @Params + } + 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)" + } +} \ No newline at end of file