Skip to content

Commit

Permalink
This should enable gallery publishing for the module
Browse files Browse the repository at this point in the history
  • Loading branch information
exchange12rocks committed Mar 14, 2018
1 parent 8e1d4d3 commit 2c3d3a2
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Deploy.SplitOutput.ps1
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.
19 changes: 19 additions & 0 deletions appveyor.yml
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
56 changes: 56 additions & 0 deletions build.ps1
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 ) )
78 changes: 78 additions & 0 deletions psake.ps1
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
}

0 comments on commit 2c3d3a2

Please sign in to comment.