-
Notifications
You must be signed in to change notification settings - Fork 221
Expand file tree
/
Copy pathBuildModule.ps1
More file actions
107 lines (96 loc) · 4.55 KB
/
BuildModule.ps1
File metadata and controls
107 lines (96 loc) · 4.55 KB
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
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()][string] $ModuleSrc,
[Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()][string] $ModuleFullName,
[Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()][HashTable] $ModuleMetadata,
[Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()][string] $Version,
[string] $Prerelease,
[hashtable[]] $RequiredModules,
[switch] $EnableSigning,
[switch] $ExcludeExampleTemplates,
[switch] $ExcludeNotesSection
)
$ErrorActionPreference = "Stop"
if ($PSEdition -ne "Core") {
Write-Error "This script requires PowerShell Core to execute. [Note] Generated cmdlets will work in both PowerShell Core or Windows PowerShell."
}
$NuspecHelperPS1 = Join-Path $PSScriptRoot "./NuspecHelper.ps1"
$CSProjHelperPS1 = Join-Path $PSScriptRoot "./CSProjHelper.ps1"
$BuildModulePS1 = Join-Path $ModuleSrc "/build-module.ps1"
$ModuleCsProj = Join-Path $ModuleSrc "$ModuleFullName.csproj"
$ModuleManifest = Join-Path $ModuleSrc "$ModuleFullName.psd1"
$ModuleNuspec = Join-Path $ModuleSrc "$ModuleFullName.nuspec"
# Import scripts
. $NuspecHelperPS1
. $CSProjHelperPS1
if (-not (Test-Path -Path $BuildModulePS1)) {
Write-Error "Build script file '$BuildModulePS1' not found for '$ModuleFullName' module."
}
# Set delay sign to true.
if ($EnableSigning) {
Set-CSProjValues -ModuleCsProj $ModuleCsProj -ModuleVersion $Version -PreRelease $Prerelease -AssemblyOriginatorKeyFile $ModuleMetadata["assemblyOriginatorKeyFile"]
}
else {
Set-CSProjValues -ModuleCsProj $ModuleCsProj -ModuleVersion $Version -PreRelease $Prerelease -Copyright $ModuleMetadata["copyright"]
}
if ($ModuleFullName -ne "Microsoft.Graph.Authentication") {
# Build service modules.
# We need to build the service modules first because AutoREST will override the manifest settings on build.
# See https://github.com/Azure/autorest.powershell/issues/981.
Write-Debug "Building '$ModuleFullName' module..."
& $BuildModulePS1 -Docs -Release -ExcludeExampleTemplates:$ExcludeExampleTemplates -ExcludeNotesSection:$ExcludeNotesSection
if ($lastexitcode -ne 0) {
Write-Debug "Failed to build '$ModuleFullName' module."
exit $lastexitcode
}
# Move generated docs from export folder to root of docs folder.
$DocsPath = Join-Path $ModuleSrc "docs"
$DocsExportPath = Join-Path $DocsPath "exports"
Write-Debug "Moving generated docs from '$DocsExportPath' to '$DocsPath'..."
if (Test-Path $DocsExportPath){
$DocsExportFiles = Get-ChildItem $DocsExportPath -Recurse
foreach ($docFile in $DocsExportFiles) {
$newPath = Join-Path $DocsPath $docFile.Name
Move-Item $docFile.FullName $newPath -Force
}
Write-Debug "Cleaning '$DocsExportPath'..."
Remove-Item $DocsExportPath -Force -Recurse
}
}
# Lock module GUID. See https://github.com/Azure/autorest.powershell/issues/981.
$ExistingModule = Find-Module $ModuleFullName -Repository PSGallery -ErrorAction SilentlyContinue
$ModuleGuid = ($null -eq $ExistingModule) ? (New-Guid).Guid : $ExistingModule.AdditionalMetadata.GUID
[HashTable]$ModuleManifestSettings = @{
Guid = $ModuleGuid
Path = $ModuleManifest
ModuleVersion = $Version
IconUri = $ModuleMetadata["iconUri"]
ReleaseNotes = $ModuleMetadata["releaseNotes"]
}
if ($RequiredModules.Count -gt 0) {
$RequiredModules | ForEach-Object {
$ModuleManifestSettings.RequiredModules += @{ ModuleName = $_.ModuleName ; ModuleVersion = $_.ModuleVersion; RequiredVersion = $_.RequiredVersion }
}
}
if ($Prerelease) {
$ModuleManifestSettings.Prerelease = $Prerelease
$FullVersionNumber = "$Version-$Prerelease"
}
else {
$ModuleManifestSettings.Prerelease = " "
$FullVersionNumber = $Version
}
Write-Debug "Updating '$ModuleFullName' module manifest and nuspec..."
Update-ModuleManifest @ModuleManifestSettings
Set-NuSpecValues -NuSpecFilePath $ModuleNuspec -VersionNumber $FullVersionNumber -Dependencies $RequiredModules -IconUrl $ModuleMetadata["iconUri"] -ReleaseNotes $ReleaseNotes
if ($ModuleFullName -eq "Microsoft.Graph.Authentication") {
# Build auth modules.
Write-Debug "Building '$ModuleFullName' module..."
& $BuildModulePS1 -Docs -Release -ExcludeExampleTemplates:$ExcludeExampleTemplates -ExcludeNotesSection:$ExcludeNotesSection
if ($lastexitcode -ne 0) {
Write-Debug "Failed to build '$ModuleFullName' module."
exit $lastexitcode
}
}