Skip to content

Commit e453dc9

Browse files
author
Ben Reader
committed
Updating build pipeline
1 parent 9ec998f commit e453dc9

File tree

2 files changed

+47
-82
lines changed

2 files changed

+47
-82
lines changed

azure-pipelines.yml

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,16 @@ stages:
1717
pool:
1818
vmImage: 'vs2017-win2016'
1919
steps:
20-
- task: PowerShell@2
21-
displayName: Pre-Build
22-
inputs:
23-
targetType: 'inline'
24-
script: |
25-
Install-Module -Name Pester -MaximumVersion 4.10.1 -Verbose -Scope CurrentUser -SkipPublisherCheck -Force
26-
Install-Module WindowsAutoPilotIntune -Scope CurrentUser -Force
27-
Install-Module Microsoft.Graph.Intune -Scope CurrentUser -Force
28-
Install-Module TestJsonSchema -Scope CurrentUser -SkipPublisherCheck -ErrorAction SilentlyContinue -Force
29-
Install-Module PSScriptAnalyzer -Scope CurrentUser -SkipPublisherCheck -ErrorAction SilentlyContinue -Force
30-
pwsh: true
31-
3220
- task: PowerShell@2
3321
displayName: Build
3422
inputs:
3523
filePath: './build.ps1'
36-
arguments: '-modulePath $(modulePath) -moduleName $(moduleName)'
37-
pwsh: true
38-
39-
- task: PowerShell@2
40-
displayName: 'Code Quality Test'
41-
inputs:
42-
filePath: './tests/codecheck.ps1'
24+
arguments: '-modulePath $(modulePath)'
4325
pwsh: true
4426

45-
- task: PublishTestResults@2
46-
displayName: 'Publish Test Results'
47-
inputs:
48-
testResultsFormat: 'NUnit'
49-
testResultsFiles: 'pester.codecheck.test.xml'
50-
searchFolder: '$(System.DefaultWorkingDirectory)/.tests'
51-
failTaskOnFailedTests: true
52-
testRunTitle: 'Code Quality Test'
53-
5427
- task: CopyFiles@2
5528
inputs:
56-
SourceFolder: './bin/release/$(Build.BuildId)'
29+
SourceFolder: './bin/release'
5730
Contents: '**'
5831
TargetFolder: '$(Build.ArtifactStagingDirectory)'
5932
CleanTargetFolder: true
@@ -81,14 +54,6 @@ stages:
8154
targetType: 'inline'
8255
script: |
8356
try {
84-
$modules = @(
85-
"WindowsAutoPilotIntune"
86-
"Microsoft.Graph.Intune"
87-
)
88-
foreach ($m in $modules) {
89-
write-host "Installing module: $m.."
90-
Install-Module $m -Scope CurrentUser -Force
91-
}
9257
write-host "Publishing module from: $env:Pipeline_Workspace\release\$env:MODULENAME"
9358
Publish-Module -Path "$env:Pipeline_Workspace\release\$env:MODULENAME" -NuGetApiKey $env:APIKEY
9459
}

build.ps1

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,66 @@
1-
[cmdletbinding()]
1+
[cmdletbinding()]
22
param (
33
[parameter(Mandatory = $true)]
44
[System.IO.FileInfo]$modulePath,
55

6-
[parameter(Mandatory = $true)]
7-
[string]$moduleName,
8-
96
[parameter(Mandatory = $false)]
107
[switch]$buildLocal
118
)
12-
if ($buildLocal) {
13-
if (Test-Path $PSScriptRoot\localenv.ps1 -ErrorAction SilentlyContinue) {
14-
. $PSScriptRoot\localenv.ps1
15-
if (Test-Path "$PSScriptRoot\bin\release\*") {
16-
$env:BUILD_BUILDID = ((Get-ChildItem $PSScriptRoot\bin\release\).Name | Measure-Object -Maximum | Select-Object -ExpandProperty Maximum) + 1
17-
}
18-
}
19-
}
9+
2010
try {
2111
#region Generate a new version number
22-
$newVersion = New-Object version -ArgumentList 1, 0, 1, $env:BUILD_BUILDID
23-
$lastVersion = (Find-Module $env:ModuleName).Version
24-
$releaseNotes = (Get-Content .\Intune.USB.Creator\ReleaseNotes.txt -Raw).Replace("{{NewVersion}}",$newVersion).Replace("{{LastVersion}}","$lastVersion")
12+
$moduleName = Split-Path -Path $modulePath -Leaf
13+
$PreviousVersion = Find-Module -Name $moduleName -ErrorAction SilentlyContinue | Select-Object *
14+
[Version]$exVer = $PreviousVersion ? $PreviousVersion.Version : $null
15+
if ($buildLocal) {
16+
$rev = ((Get-ChildItem -Path "$PSScriptRoot\bin\release\" -ErrorAction SilentlyContinue).Name | Measure-Object -Maximum | Select-Object -ExpandProperty Maximum) + 1
17+
$newVersion = New-Object -TypeName Version -ArgumentList 1, 0, 0, $rev
18+
}
19+
else {
20+
$newVersion = if ($exVer) {
21+
$rev = ($exVer.Revision + 1)
22+
New-Object version -ArgumentList $exVer.Major, $exVer.Minor, $exVer.Build, $rev
23+
}
24+
else {
25+
$rev = ((Get-ChildItem "$PSScriptRoot\bin\release\" -ErrorAction SilentlyContinue).Name | Measure-Object -Maximum | Select-Object -ExpandProperty Maximum) + 1
26+
New-Object Version -ArgumentList 1, 0, 0, $rev
27+
}
28+
}
29+
$releaseNotes = (Get-Content ".\$moduleName\ReleaseNotes.txt" -Raw -ErrorAction SilentlyContinue).Replace("{{NewVersion}}", $newVersion)
30+
if ($PreviousVersion) {
31+
$releaseNotes = @"
32+
$releaseNotes
33+
34+
$($previousVersion.releaseNotes)
35+
"@
36+
}
2537
#endregion
38+
2639
#region Build out the release
27-
$relPath = "$PSScriptRoot\bin\release\$env:BUILD_BUILDID\$moduleName"
40+
if ($buildLocal) {
41+
$relPath = "$PSScriptRoot\bin\release\$rev\$moduleName"
42+
}
43+
else {
44+
$relPath = "$PSScriptRoot\bin\release\$moduleName"
45+
}
2846
"Version is $newVersion"
2947
"Module Path is $modulePath"
3048
"Module Name is $moduleName"
3149
"Release Path is $relPath"
32-
if (!(Test-Path $relPath)) {
50+
if (!(Test-Path -Path $relPath)) {
3351
New-Item -Path $relPath -ItemType Directory -Force | Out-Null
3452
}
35-
Copy-Item "$modulePath\*" -Destination "$relPath" -Recurse -Exclude ".gitKeep"
36-
#endregion
37-
#region Generate a list of public functions and update the module manifest
38-
$functions = @(Get-ChildItem -Path $relPath\Public\*.ps1 -ErrorAction SilentlyContinue).basename
39-
$params = @{
40-
Path = "$relPath\$ModuleName.psd1"
41-
ModuleVersion = $newVersion
42-
Description = (Get-Content $relPath\description.txt -raw).ToString()
43-
FunctionsToExport = $functions
44-
ReleaseNotes = $releaseNotes.ToString()
53+
54+
Copy-Item -Path "$modulePath\*" -Destination "$relPath" -Recurse -Exclude ".gitKeep", "releaseNotes.txt", "description.txt"
55+
56+
$Manifest = @{
57+
Path = "$relPath\$moduleName.psd1"
58+
ModuleVersion = $newVersion
59+
Description = (Get-Content "$modulePath\description.txt" -Raw).ToString()
60+
FunctionsToExport = (Get-ChildItem -Path "$relPath\Public\*.ps1" -Recurse).BaseName
61+
ReleaseNotes = $releaseNotes
4562
}
46-
Update-ModuleManifest @params
47-
$moduleManifest = Get-Content $relPath\$ModuleName.psd1 -raw | Invoke-Expression
48-
#endregion
49-
#region Generate the nuspec manifest
50-
$t = [xml](Get-Content $PSScriptRoot\module.nuspec -Raw)
51-
$t.package.metadata.id = $moduleName
52-
$t.package.metadata.version = $newVersion.ToString()
53-
$t.package.metadata.authors = $moduleManifest.author.ToString()
54-
$t.package.metadata.owners = $moduleManifest.author.ToString()
55-
$t.package.metadata.requireLicenseAcceptance = "false"
56-
$t.package.metadata.description = (Get-Content $relPath\description.txt -raw).ToString()
57-
$t.package.metadata.description
58-
$t.package.metadata.releaseNotes = $releaseNotes.ToString()
59-
$t.package.metadata.releaseNotes
60-
$t.package.metadata.copyright = $moduleManifest.copyright.ToString()
61-
$t.package.metadata.tags = ($moduleManifest.PrivateData.PSData.Tags -join ',').ToString()
62-
$t.Save("$PSScriptRoot\$moduleName`.nuspec")
63-
#endregion
63+
Update-ModuleManifest @Manifest
6464
}
6565
catch {
6666
$_

0 commit comments

Comments
 (0)