7
7
[string ] $ModuleMappingConfigPath = (Join-Path $PSScriptRoot " ..\config\ModulesMapping.jsonc" ),
8
8
[switch ] $UpdateAutoRest ,
9
9
[switch ] $Build ,
10
+ [switch ] $Test ,
10
11
[switch ] $Pack ,
11
12
[switch ] $Publish ,
12
13
[switch ] $EnableSigning ,
@@ -34,6 +35,7 @@ $RequiredGraphModules = @()
34
35
# PS Scripts
35
36
$ManageGeneratedModulePS1 = Join-Path $PSScriptRoot " .\ManageGeneratedModule.ps1" - Resolve
36
37
$BuildModulePS1 = Join-Path $PSScriptRoot " .\BuildModule.ps1" - Resolve
38
+ $TestModulePS1 = Join-Path $PSScriptRoot " .\TestModule.ps1" - Resolve
37
39
$PackModulePS1 = Join-Path $PSScriptRoot " .\PackModule.ps1" - Resolve
38
40
$PublishModulePS1 = Join-Path $PSScriptRoot " .\PublishModule.ps1" - Resolve
39
41
$ReadModuleReadMePS1 = Join-Path $PSScriptRoot " .\ReadModuleReadMe.ps1" - Resolve
@@ -54,8 +56,7 @@ if($ModulePreviewNumber -eq -1) {
54
56
# Install module locally in order to specify it as a dependency for other modules down the generation pipeline.
55
57
# https://stackoverflow.com/questions/46216038/how-do-i-define-requiredmodules-in-a-powershell-module-manifest-psd1.
56
58
$ExistingAuthModule = Find-Module " Microsoft.Graph.Authentication" - Repository $RepositoryName - AllowPrerelease:$AllowPreRelease
57
- Write-Warning " Auth Module: $ExistingAuthModule .Name"
58
- Write-Warning " Auth Module: $ExistingAuthModule .Version"
59
+ Write-Host - ForegroundColor Green " Auth Module: $ ( $ExistingAuthModule.Name ) , $ ( $ExistingAuthModule.Version ) "
59
60
if (! (Get-Module - Name $ExistingAuthModule.Name - ListAvailable)) {
60
61
Install-Module $ExistingAuthModule.Name - Repository $RepositoryName - Force - AllowClobber - AllowPrerelease:$AllowPreRelease
61
62
}
@@ -83,7 +84,8 @@ $ModuleMapping.Keys | ForEach-Object -ThrottleLimit $ModuleMapping.Keys.Count -P
83
84
}
84
85
85
86
$ModuleName = $_
86
- Write-Warning " Generating $ModuleName "
87
+ $FullyQualifiedModuleName = " $using :ModulePrefix .$ModuleName "
88
+ Write-Host - ForegroundColor Green " Generating '$FullyQualifiedModuleName ' module..."
87
89
$ModuleProjectDir = Join-Path $Using :ModulesOutputDir " $ModuleName \$ModuleName "
88
90
89
91
# Copy AutoRest readme.md config is none exists.
@@ -98,37 +100,36 @@ $ModuleMapping.Keys | ForEach-Object -ThrottleLimit $ModuleMapping.Keys.Count -P
98
100
$ModuleVersion = & $Using :ReadModuleReadMePS1 - ReadMePath $ModuleLevelReadMePath - FieldToRead " module-version"
99
101
if ($ModuleVersion -eq $null ) {
100
102
# Module version not set in readme.md.
101
- Write-Error " Version number is not set on $Using :ModulePrefix . $ModuleName module. Please set 'module-version' in $ModuleLevelReadMePath ."
103
+ Write-Error " Version number is not set on $FullyQualifiedModuleName module. Please set 'module-version' in $ModuleLevelReadMePath ."
102
104
}
103
105
104
106
# Validate module version with the one on PSGallery.
105
- [VersionState ] $VersionState = & $Using :ValidateUpdatedModuleVersionPS1 - ModuleName " $Using :ModulePrefix . $ModuleName " - NextVersion $ModuleVersion - PSRepository RepositoryName - ModulePreviewNumber $ModulePreviewNumber
107
+ [VersionState ] $VersionState = & $Using :ValidateUpdatedModuleVersionPS1 - ModuleName " $FullyQualifiedModuleName " - NextVersion $ModuleVersion - PSRepository RepositoryName - ModulePreviewNumber $ModulePreviewNumber
106
108
107
109
if ($VersionState.Equals ([VersionState ]::Invalid) -and ! $Using :SkipVersionCheck ) {
108
- Write-Warning " The specified version in $Using :ModulePrefix . $ModuleName module is either higher or lower than what's on $Using :RepositoryName . Update the 'module-version' in $ModuleLevelReadMePath "
110
+ Write-Warning " The specified version in $FullyQualifiedModuleName module is either higher or lower than what's on $Using :RepositoryName . Update the 'module-version' in $ModuleLevelReadMePath "
109
111
}
110
112
elseif ($VersionState.Equals ([VersionState ]::EqualToFeed) -and ! $SkipVersionCheck ) {
111
- Write-Warning " $Using :ModulePrefix . $ModuleName module skipped. Version has not changed and is equal to what's on $Using :RepositoryName ."
113
+ Write-Warning " $FullyQualifiedModuleName module skipped. Version has not changed and is equal to what's on $Using :RepositoryName ."
112
114
}
113
115
elseif ($VersionState.Equals ([VersionState ]::Valid) -or $VersionState.Equals ([VersionState ]::NotOnFeed) -or $Using :SkipVersionCheck ) {
114
116
# Read release notes from readme.
115
117
$ModuleReleaseNotes = & $Using :ReadModuleReadMePS1 - ReadMePath $ModuleLevelReadMePath - FieldToRead " release-notes"
116
118
if ($ModuleReleaseNotes -eq $null ) {
117
119
# Release notes not set in readme.md.
118
- Write-Error " Release notes not set on $Using :ModulePrefix . $ModuleName module. Please set 'release-notes' in $ModuleLevelReadMePath ."
120
+ Write-Error " Release notes not set on $FullyQualifiedModuleName module. Please set 'release-notes' in $ModuleLevelReadMePath ."
119
121
}
120
122
121
123
try {
122
124
# Generate PowerShell modules.
123
- Write-Host - ForegroundColor Green " Generating '$Using :ModulePrefix .$ModuleName ' module..."
124
125
& autorest -- module- version:$ModuleVersion -- service- name:$ModuleName $ModuleLevelReadMePath -- verbose
125
126
if ($LASTEXITCODE ) {
126
127
Write-Error " Failed to generate '$ModuleName ' module."
127
128
}
128
- Write-Host - ForegroundColor Green " AutoRest generated '$Using :ModulePrefix . $ModuleName ' successfully."
129
+ Write-Host - ForegroundColor Green " AutoRest generated '$FullyQualifiedModuleName ' successfully."
129
130
130
131
# Manage generated module.
131
- Write-Host - ForegroundColor Green " Managing '$Using :ModulePrefix . $ModuleName ' module..."
132
+ Write-Host - ForegroundColor Green " Managing '$FullyQualifiedModuleName ' module..."
132
133
& $Using :ManageGeneratedModulePS1 - Module $ModuleName - ModulePrefix $Using :ModulePrefix
133
134
134
135
if ($Using :Build ) {
@@ -146,12 +147,12 @@ $ModuleMapping.Keys | ForEach-Object -ThrottleLimit $ModuleMapping.Keys.Count -P
146
147
$Profiles = Get-ChildItem - Path $ModuleExportsPath - Directory | % { $_.Name }
147
148
148
149
# Update module manifest wiht profiles.
149
- $ModuleManifestPath = Join-Path $ModuleProjectDir " $Using :ModulePrefix . $ModuleName .psd1"
150
+ $ModuleManifestPath = Join-Path $ModuleProjectDir " $FullyQualifiedModuleName .psd1"
150
151
[HashTable ]$PrivateData = @ { Profiles = $Profiles }
151
152
Update-ModuleManifest - Path $ModuleManifestPath - PrivateData $PrivateData
152
153
153
154
# Update module psm1 with Graph session profile name.
154
- $ModulePsm1 = Join-Path $ModuleProjectDir " /$Using :ModulePrefix . $ModuleName .psm1"
155
+ $ModulePsm1 = Join-Path $ModuleProjectDir " /$FullyQualifiedModuleName .psm1"
155
156
(Get-Content - Path $ModulePsm1 ) | ForEach-Object {
156
157
if ($_ -match ' \$instance = \[Microsoft.Graph.PowerShell.Module\]::Instance' ) {
157
158
# Update main psm1 with Graph session profile name and module name.
@@ -161,13 +162,15 @@ $ModuleMapping.Keys | ForEach-Object -ThrottleLimit $ModuleMapping.Keys.Count -P
161
162
# Rename all Azure instances in psm1 to `Microsoft Graph`.
162
163
$updatedLine = $_ -replace ' Azure' , ' Microsoft Graph'
163
164
# Replace all 'instance.Name' declarations with fully qualified module name.
164
- $updatedLine = $updatedLine -replace ' \$\(\$instance.Name\)' , " $ModulePrefix .$ModuleName "
165
+ $updatedLine = $updatedLine -replace ' \$\(\$instance.Name\)' , " $FullyQualifiedModuleName "
166
+ # Replace Write-Information with Write-Debug
167
+ $updatedLine = $updatedLine -replace ' Write\-Information' , ' Write-Debug'
165
168
$updatedLine
166
169
}
167
170
} | Set-Content $ModulePsm1
168
171
169
172
# Address AutoREST bug where it looks for exports in the wrong directory.
170
- $InternalModulePsm1 = Join-Path $ModuleProjectDir " /internal/$Using :ModulePrefix . $ModuleName .internal.psm1"
173
+ $InternalModulePsm1 = Join-Path $ModuleProjectDir " /internal/$FullyQualifiedModuleName .internal.psm1"
171
174
(Get-Content - Path $InternalModulePsm1 ) | ForEach-Object {
172
175
$updatedLine = $_
173
176
# Address AutoREST bug where it looks for exports in the wrong directory.
@@ -188,19 +191,22 @@ $ModuleMapping.Keys | ForEach-Object -ThrottleLimit $ModuleMapping.Keys.Count -P
188
191
}
189
192
}
190
193
194
+ if ($Using :Test ) {
195
+ & $Using :TestModulePS1 - ModulePath $ModuleProjectDir - ModuleName $FullyQualifiedModuleName
196
+ }
197
+
191
198
if ($Using :Pack ) {
192
199
# Pack generated module.
193
- & $Using :PackModulePS1 - Module $ModuleName - ArtifactsLocation $Using :ArtifactsLocation
200
+ . $Using :PackModulePS1 - Module $ModuleName - ArtifactsLocation $Using :ArtifactsLocation
194
201
}
195
202
}
196
203
catch {
197
- Write-Error $_.Exception
204
+ throw $_
198
205
}
199
- Write-Warning " Generating $ModuleName Completed"
206
+ Write-Host - ForeGroundColor Green " Generating $ModuleName Completed"
200
207
}
201
208
}
202
209
203
- Write-Host - ForeGroundColor Green " Requests: $RequestCount "
204
210
if ($Publish ) {
205
211
# Publish generated modules.
206
212
& $PublishModulePS1 - Modules $ModuleMapping.Keys - ModulePrefix $ModulePrefix - ArtifactsLocation $ArtifactsLocation - RepositoryName $RepositoryName - RepositoryApiKey $RepositoryApiKey
0 commit comments