-
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.
This should enable gallery publishing for the module
- Loading branch information
1 parent
8e1d4d3
commit 2c3d3a2
Showing
7 changed files
with
211 additions
and
0 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,58 @@ | ||
# 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 | ||
|
||
# Publish to gallery with a few restrictions | ||
if( | ||
$env:BHPSModulePath -and | ||
$env:BHBuildSystem -ne 'Unknown' -and | ||
$env:BHBranchName -eq "master" -and | ||
$env:BHCommitMessage -match '!deploy' | ||
) | ||
{ | ||
Deploy Module { | ||
By PSGalleryModule { | ||
FromSource $ENV:BHPSModulePath | ||
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:BHPSModulePath -and | ||
$env:BHBuildSystem -eq 'AppVeyor' | ||
) | ||
{ | ||
Deploy DeveloperBuild { | ||
By AppVeyorModule { | ||
FromSource $ENV:BHPSModulePath | ||
To AppVeyor | ||
WithOptions @{ | ||
Version = $env:APPVEYOR_BUILD_VERSION | ||
} | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,19 @@ | ||
environment: | ||
NuGetApiKey: | ||
secure: 8YkGfuwtA1voj3pVNxbyatmJbhEn82hV+41hVTf9r3efcfuhEH2OEunUzOltIpdf | ||
install: | ||
- ps: $Module = Get-Module -Name 'Pester' -ListAvailable | ||
- ps: "[version]$RequiredPesterVersion = '4.0.8'" | ||
- ps: if ($Module) { if (-not ($Module | Where-Object -FilterScript {$_.Version -ge $RequiredPesterVersion})) { Install-Module -Name 'Pester' -MinimumVersion $RequiredPesterVersion -SkipPublisherCheck -Force }; Import-Module -Name 'Pester' -MinimumVersion $RequiredPesterVersion; Get-Module -Name 'Pester' | Where-Object -FilterScript {$_.Version -lt $RequiredPesterVersion} | Remove-Module -Force } else { Install-Module -Name 'Pester' -MinimumVersion $RequiredPesterVersion; Import-Module -Name 'Pester' } | ||
|
||
build: false | ||
|
||
test_script: | ||
- ps: . .\build.ps1 | ||
|
||
skip_commits: | ||
files: | ||
- .gitattributes | ||
- .gitignore | ||
- LICENSE | ||
- README.md |
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,56 @@ | ||
function Resolve-Module | ||
{ | ||
[Cmdletbinding()] | ||
param | ||
( | ||
[Parameter(Mandatory)] | ||
[string[]]$Name | ||
) | ||
|
||
Process | ||
{ | ||
foreach ($ModuleName in $Name) | ||
{ | ||
$Module = Get-Module -Name $ModuleName -ListAvailable | ||
Write-Verbose -Message "Resolving Module $($ModuleName)" | ||
|
||
if ($Module) | ||
{ | ||
$Version = $Module | Measure-Object -Property Version -Maximum | Select-Object -ExpandProperty Maximum | ||
$GalleryVersion = Find-Module -Name $ModuleName -Repository PSGallery | Measure-Object -Property Version -Maximum | Select-Object -ExpandProperty Maximum | ||
|
||
if ($Version -lt $GalleryVersion) | ||
{ | ||
|
||
if ((Get-PSRepository -Name PSGallery).InstallationPolicy -ne 'Trusted') { Set-PSRepository -Name PSGallery -InstallationPolicy Trusted } | ||
|
||
Write-Verbose -Message "$($ModuleName) Installed Version [$($Version.tostring())] is outdated. Installing Gallery Version [$($GalleryVersion.tostring())]" | ||
|
||
Install-Module -Name $ModuleName -Force | ||
Import-Module -Name $ModuleName -Force -RequiredVersion $GalleryVersion | ||
} | ||
else | ||
{ | ||
Write-Verbose -Message "Module Installed, Importing $($ModuleName)" | ||
Import-Module -Name $ModuleName -Force -RequiredVersion $Version | ||
} | ||
} | ||
else | ||
{ | ||
Write-Verbose -Message "$($ModuleName) Missing, installing Module" | ||
Install-Module -Name $ModuleName -Force | ||
Import-Module -Name $ModuleName -Force -RequiredVersion $Version | ||
} | ||
} | ||
} | ||
} | ||
|
||
# Grab nuget bits, install modules, set build variables, start build. | ||
Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null | ||
|
||
Resolve-Module Psake, PSDeploy, Pester, BuildHelpers | ||
|
||
Set-BuildEnvironment | ||
|
||
Invoke-psake .\psake.ps1 | ||
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,78 @@ | ||
# 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 | ||
|
||
# Load the module, read the exported functions, update the psd1 FunctionsToExport | ||
Set-ModuleFunctions | ||
|
||
# Bump the module version | ||
Update-Metadata -Path $env:BHPSModuleManifest | ||
} | ||
|
||
Task Deploy -Depends Build { | ||
$lines | ||
|
||
$Params = @{ | ||
Path = $ProjectRoot | ||
Force = $true | ||
Recurse = $false # We keep psdeploy artifacts, avoid deploying those : ) | ||
} | ||
Invoke-PSDeploy @Verbose @Params | ||
} |