Skip to content

Instantly share code, notes, and snippets.

@SQLDBAWithABeard
Last active April 16, 2018 15:04
Show Gist options
  • Save SQLDBAWithABeard/3d2e66cf86bd936adf653e12b1960cf0 to your computer and use it in GitHub Desktop.
Save SQLDBAWithABeard/3d2e66cf86bd936adf653e12b1960cf0 to your computer and use it in GitHub Desktop.
Code for VSTS Build and release for PowerShell Gallery
$ModuleName = 'BeardAnalysis'
$Description = "This is a demo module for demoing Plaster and TDD with Pester and CI with VSTS to the PowerShell Gallery"
$plaster = @{
TemplatePath = "GIT:\PlasterTemplate" #(Split-Path $manifestProperties.Path)
DestinationPath = "Git:\$ModuleName"
FullName = "Rob Sewell"
ModuleName = $ModuleName
ModuleDesc = $Description
Version = '0.9.18'
GitHubUserName = "SQLDBAWithABeard"
GitHubRepo = $ModuleName
}
If(!(Test-Path $plaster.DestinationPath))
{
New-Item -ItemType Directory -Path $plaster.DestinationPath
}
Invoke-Plaster @plaster -Verbose
# Set location to module home path in artifacts directory
try {
Set-Location $(System.DefaultWorkingDirectory)\PowerShell_Gallery_Build\BeardAnalysis
}
catch {
Write-Error "Failed to set location"
}
# get the contents of the module manifest file
try {
$file = (Get-Content .\BeardAnalysis.psd1)
}
catch {
Write-Error "Failed to Get-Content"
}
# Use RegEx to get the Version Number and set it as a version datatype
# \s* - between 0 and many whitespace
# ModuleVersion - literal
# \s - 1 whitespace
# = - literal
# \s - 1 whitespace
# ' - literal
# () - capture Group
# \d* - between 0 and many digits
# ' - literal
# \s* between 0 and many whitespace
[version]$Version = [regex]::matches($file, "\s*ModuleVersion\s=\s'(\d*.\d*.\d*)'\s*").groups[1].value
Write-Output "Old Version - $Version"
# Add one to the build of the version number
[version]$NewVersion = $newVersion = "{0}.{1}.{2}" -f $Version.Major, $Version.Minor, ($Version.Build + 1)
Write-Output "New Version - $NewVersion"
# Replace Old Version Number with New Version number in the file
try {
(Get-Content .\BeardAnalysis.psd1) -replace $version, $NewVersion | Out-File .\BeardAnalysis.psd1
Write-Output "Updated Module Version from $Version to $NewVersion"
}
catch {
$_
Write-Error "failed to set file"
}
$manifest = Import-PowerShellDataFile .\BeardAnalysis.psd1
[version]$version = $Manifest.ModuleVersion
# Add one to the build of the version number
[version]$NewVersion = "{0}.{1}.{2}" -f $Version.Major, $Version.Minor, ($Version.Build + 1)
# Update the manifest file
Update-ModuleManifest -Path .\BeardAnalysis.psd1 -ModuleVersion $NewVersion
git config user.email "mrrobsewell@outlook.com"
git config user.name "SQLDBAWithABeard"
git checkout master
git add .\BeardAnalysis.psd1
git commit -m "Updated Version Number ***NO_CI***"
git push https://$(GitHubPAT)@github.com/SQLDBAWithABeard/BeardAnalysis.git HEAD:master
# Set location to module home path in artifacts directory
try {
Set-Location $(System.DefaultWorkingDirectory)\PowerShell_Gallery_Build\BeardAnalysis
}
catch {
Write-Error "Failed to set location"
}
# get the contents of the module manifest file
try {
$file = (Get-Content .\BeardAnalysis.psd1 -Raw)
}
catch {
Write-Error "Failed to Get-Content"
}
# Replace Old Release Notes with the new ones in the file
try {
# Use RegEx to get the Release Notes
# \s* between 0 and many whitespace
# ReleaseNotes - literal
# \s - 1 whitespace
# = - literal
# \s - 1 whitespace
# ' - literal
# () - Capture Group
# [\w\s*.'!:;%&-]* - Any word, Any whitespace, any of those characters zero to many times until
# ' - literal
# \s* - between 0 and many whitespace
# } - literal
$ReleaseNotes = [regex]::matches($file, "\s*ReleaseNotes\s=\s'([\w\s*.'!:;%&-]*)'\s*").groups[1].value
## Use Regex to get Version - see other script for explanation
[version]$Version = [regex]::matches($file, "\s*ModuleVersion\s=\s'(\d*.\d*.\d*)'\s*").groups[1].value
$NewReleasenotes = (Get-Content .\docs\ReleaseNotes.txt -Raw)
## Limit Release Notes to 1000 characters
$NewReleasenotes = $NewReleasenotes[0..999] -join ""
[regex]::Replace($file, $ReleaseNotes, $NewReleasenotes)|Out-File .\BeardAnalysis.psd1
Write-Output "Updated release Notes"
}
catch {
## Write-Error "failed to set file"
$_
}
git config user.email "mrrobsewell@outlook.com"
git config user.name "SQLDBAWithABeard"
git checkout master
git add .\BeardAnalysis.psd1
git commit -m "Updated Release Notes in Manifest File ***NO_CI***"
git push https://$(GitHubPAT)@github.com/SQLDBAWithABeard/BeardAnalysis.git HEAD:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment