-
Notifications
You must be signed in to change notification settings - Fork 0
/
AzureFileSyncDsc.build.ps1
128 lines (98 loc) · 4.37 KB
/
AzureFileSyncDsc.build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<#
.Synopsis
Build script (https://github.com/nightroman/Invoke-Build)
#>
param ($Configuration = 'Development')
#region use the most strict mode
Set-StrictMode -Version Latest
#endregion
#region Task to Update the PowerShell Module Help Files.
# Pre-requisites: PowerShell Module PlatyPS.
task UpdateHelp {
Import-Module .\AzureFileSyncDsc.psd1 -Force
Update-MarkdownHelp .\docs
New-ExternalHelp -Path .\docs -OutputPath .\en-US -Force
}
#endregion
#region Task to Copy PowerShell Module files to output folder for release as Module
task CopyModuleFiles {
# Copy Module Files to Output Folder
if (-not (Test-Path .\output\AzureFileSyncDsc)) {
$null = New-Item -Path .\output\AzureFileSyncDsc -ItemType Directory
}
Copy-Item -Path '.\en-US\' -Filter *.* -Recurse -Destination .\output\AzureFileSyncDsc -Force
Copy-Item -Path '.\DSCResources\' -Filter *.* -Recurse -Destination .\output\AzureFileSyncDsc -Force
#Copy-Item -Path '.\Examples\' -Filter *.* -Recurse -Destination .\output\AzureFileSyncDsc -Force # Removed due to breaking automated analysis in PowerShell Gallery
#Copy Module Manifest files
Copy-Item -Path @(
'.\README.md'
'.\AzureFileSyncDsc.psd1'
) -Destination .\output\AzureFileSyncDsc -Force
}
#endregion
#region Task to run all Pester tests in folder .\tests
task Test {
$Result = Invoke-Pester .\tests -PassThru
if ($Result.FailedCount -gt 0) {
throw 'Pester tests failed'
}
}
#endregion
#region Task to update the Module Manifest file with info from the Changelog in Readme.
task UpdateManifest {
# Import PlatyPS. Needed for parsing README for Change Log versions
Import-Module -Name PlatyPS
# Find Latest Version in README file from Change log.
$README = Get-Content -Path .\README.md
$MarkdownObject = [Markdown.MAML.Parser.MarkdownParser]::new()
[regex]$regex = '\d\.\d\.\d'
$Versions = $regex.Matches($MarkdownObject.ParseString($README).Children.Spans.Text) | foreach-object {$_.value}
($Versions | Measure-Object -Maximum).Maximum
$manifestPath = '.\AzureFileSyncDsc.psd1'
# Start by importing the manifest to determine the version, then add 1 to the Build
$manifest = Test-ModuleManifest -Path $manifestPath
[System.Version]$version = $manifest.Version
[String]$newVersion = New-Object -TypeName System.Version -ArgumentList ($version.Major, $version.Minor, ($version.Build + 1))
Write-Output -InputObject ('New Module version: {0}' -f $newVersion)
# Update Manifest file with Release Notes
$README = Get-Content -Path .\README.md
$MarkdownObject = [Markdown.MAML.Parser.MarkdownParser]::new()
$ReleaseNotes = ((($MarkdownObject.ParseString($README).Children.Spans.Text) -match '\d\.\d\.\d') -split ' - ')[1]
#Update Module with new version
Update-ModuleManifest -ModuleVersion $newVersion -Path .\AzureFileSyncDsc.psd1 -ReleaseNotes $ReleaseNotes
}
#endregion
#region Task to Publish Module to PowerShell Gallery
task PublishModule -If ($Configuration -eq 'Production') {
if (
$env:Build_SourceBranchName -eq "master" -and
$env:Build_SourceVersionMessage -match '!deploy'
) {
$params = @{
Path = ('{0}\Output\AzureFileSyncDsc' -f $PSScriptRoot )
NuGetApiKey = $env:psgallery
ErrorAction = 'Stop'
}
Write-Output "Branch is master and commit message contains !deploy : $($env:Build_SOURCEVERSIONMESSAGE) - publishing module"
Publish-Module @params
Write-Output -InputObject ('AzureFileSyncDsc module version $newVersion published to the PowerShell Gallery')
}
else {
"Skipping deployment: To deploy, ensure that...`n" +
"`t* You are committing to the master branch (Current: $env:Build_SourceBranchName) `n" +
"`t* Your commit message includes !deploy (Current: $env:Build_SourceVersionMessage)" |
Write-Host
}
}
#endregion
#region Task clean up Output folder
task Clean {
# Clean output folder
if ((Test-Path .\output)) {
Remove-Item -Path .\Output -Recurse -Force
}
}
#endregion
#region Default Task. Runs Clean, Test, CopyModuleFiles Tasks
task . Clean, UpdateHelp, Test, CopyModuleFiles, PublishModule
#endregion