Skip to content

Commit

Permalink
Add pipeline to deploy as WFTools
Browse files Browse the repository at this point in the history
* It's not really a module, but it will make it easier for me to pull it
down.  Sorry!
* !Deploy with !Verbose
  • Loading branch information
RamblingCookieMonster committed Sep 3, 2016
1 parent aecea77 commit e88eada
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 10 deletions.
9 changes: 9 additions & 0 deletions .build/0.build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Grab nuget bits, install modules, set build variables, start build.
Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null
Install-Module PSDepend -Force

Invoke-PSDepend -Force
Set-BuildEnvironment
Invoke-psake .\.build\2.psake.ps1

exit ( [int]( -not $psake.build_success ) )
16 changes: 16 additions & 0 deletions .build/1.depend.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@{
# Set up a mini virtual environment...
PSDependOptions = @{
Target = 'C:\PSDeployBuild'
AddToPath = $True
Parameters = @{
Force = $True
Import = $True
}
}

psdeploy = 'latest'
buildhelpers = 'latest'
pester = 'latest'
psake = 'latest'
}
82 changes: 82 additions & 0 deletions .build/2.psake.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# 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 = Split-Path $PSScriptRoot -Parent
}

$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
"`nTests? Maybe some day."

"`n"
}

Task Build -Depends Test {
$lines

#Should just use plaster...
$ModuleName = 'WFTools'
$Guid = 'afb48b37-44c5-456d-ab0e-05cce6366994'
$ModPath = Join-Path $ProjectRoot $ModuleName
$PSD1Path = Join-Path $ModPath WFTools.psd1
$Null = mkdir WFTools
Copy-Item $ProjectRoot\*.ps1 $ModPath
Copy-Item $ProjectRoot\.build\WFTools.psm1 $ModPath
New-ModuleManifest -Guid $Guid `
-Path $PSD1Path `
-Author 'Warren Frame' `
-ProjectUri https://github.com/RamblingCookieMonster/PowerShell `
-LicenseUri https://github.com/RamblingCookieMonster/PowerShell/blob/master/LICENSE `
-RootModule 'WFTools.psm1' `
-ModuleVersion "0.1.$env:BHBuildNumber" `
-Description "Assorted handy, largely unrelated PowerShell functions" `
-FunctionsToExport '*' `
-Tags 'AD', 'Active', 'Directory',
'Azure', 'SQL', 'GPP', 'Smorgasbord'

$PSD1 = Get-Content $PSD1Path -Raw
$PSD1 = $PSD1 -replace 'RootModule', 'ModuleToProcess'

# We have a module, BuildHelpers will see it
Set-BuildEnvironment

# Load the module, read the exported functions, update the psd1 FunctionsToExport
Set-ModuleFunctions
}

Task Deploy -Depends Build {
$lines

$Params = @{
Path = $ProjectRoot
Force = $true
Recurse = $false # We keep psdeploy artifacts, avoid deploying those : )
}
Invoke-PSDeploy @Verbose @Params
}
62 changes: 62 additions & 0 deletions .build/3.deploy.psdeploy.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Generic module deployment.
#
# ASSUMPTIONS:
#
# * folder structure either like:
#
# - RepoFolder
# - This PSDeploy file
# - ModuleName
# - ModuleName.psd1
#
# OR the less preferable:
# - RepoFolder
# - RepoFolder.psd1
#
# * Nuget key in $ENV:NugetApiKey
#
# * Set-BuildEnvironment from BuildHelpers module has populated ENV:BHPSModulePath and related variables

# 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
}
}
}
}
25 changes: 25 additions & 0 deletions .build/WFTools.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#handle PS2
if(-not $PSScriptRoot)
{
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
}

#Get public and private function definition files.
$Public = @( Get-ChildItem -Path $PSScriptRoot\*.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): $_"
}
}

Export-ModuleMember -Function $Public.Basename
21 changes: 11 additions & 10 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,19 +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.*/

install:
- cinst pester -y
message: /updated readme.*|update readme.*s/

build: false

#Kick off the CI/CD pipeline
test_script:
# Test with native PS version
- ps: . .\Tests\appveyor.pester.ps1 -Test
# Test with PS version 2
- ps: powershell.exe -version 2.0 -executionpolicy bypass -noprofile -file .\Tests\appveyor.pester.ps1 -Test
# Finalize pass - collect and upload results
- ps: . .\Tests\appveyor.pester.ps1 -Finalize
- ps: . .\.build\0_build.ps1

0 comments on commit e88eada

Please sign in to comment.