forked from microsoftgraph/msgraph-sdk-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerateAuthenticationModule.ps1
More file actions
93 lines (86 loc) · 4.35 KB
/
Copy pathGenerateAuthenticationModule.ps1
File metadata and controls
93 lines (86 loc) · 4.35 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
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Param(
[string] $RepositoryName = "PSGallery",
[string] $RepositoryApiKey,
[string] $ArtifactsLocation = (Join-Path $PSScriptRoot "..\artifacts\"),
[switch] $Build,
[switch] $Pack,
[switch] $Publish,
[switch] $EnableSigning,
[switch] $BuildWhenEqual,
[switch] $Test,
[switch] $Run,
[int] $ModulePreviewNumber = -1
)
enum VersionState {
Invalid
Valid
EqualToFeed
NotOnFeed
}
$ErrorActionPreference = 'Stop'
$LASTEXITCODE = $null
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.'
}
$ModulePrefix = "Microsoft.Graph"
$ModuleName = "Authentication"
$AuthModuleManifest = "Microsoft.Graph.Authentication.psd1"
$SigningKeyFile = "35MSSharedLib1024.snk"
$BuildModulePS1 = Join-Path $PSScriptRoot ".\BuildModule.ps1" -Resolve
$PackModulePS1 = Join-Path $PSScriptRoot ".\PackModule.ps1" -Resolve
$PublishModulePS1 = Join-Path $PSScriptRoot ".\PublishModule.ps1" -Resolve
$ValidateUpdatedModuleVersionPS1 = Join-Path $PSScriptRoot ".\ValidateUpdatedModuleVersion.ps1" -Resolve
$AuthSrcPath = Join-Path $PSScriptRoot "..\src\Authentication\"
$AuthModulePath = Join-Path $AuthSrcPath "Authentication" -Resolve
$TestModulePS1 = Join-Path $PSScriptRoot ".\TestModule.ps1" -Resolve
$RunModulePS1 = Join-Path $AuthModulePath ".\run-module.ps1" -Resolve
$AuthCoreCSProj = Join-Path $AuthSrcPath "$ModuleName.Core" "$ModulePrefix.$ModuleName.Core.csproj"
$CSProjHelperPS1 = Join-Path $PSScriptRoot "./CSProjHelper.ps1"
# Import scripts
. $CSProjHelperPS1
# Read ModuleVersion set on local auth module.
$ManifestContent = Import-LocalizedData -BaseDirectory $AuthModulePath -FileName $AuthModuleManifest
if ($null -eq $ManifestContent.ModuleVersion) {
# Module version not set in module manifest (psd1).
Write-Error "Version number is not set on $ModulePrefix.$ModuleName module. Please set 'ModuleVersion' in $AuthModulePath\$AuthModuleManifest."
}
$AllowPreRelease = $true
if ($ModulePreviewNumber -eq -1) {
$AllowPreRelease = $false
}
# Validate module version with the one on PSGallery.
[VersionState]$VersionState = & $ValidateUpdatedModuleVersionPS1 -ModuleName "$ModulePrefix.$ModuleName" -NextVersion $ManifestContent.ModuleVersion -PSRepository $RepositoryName -ModulePreviewNumber $ModulePreviewNumber
if ($VersionState.Equals([VersionState]::Invalid)) {
Write-Warning "The specified version in $ModulePrefix.$ModuleName module is either higher or lower than what's on $RepositoryName. Update 'ModuleVersion' in $AuthModulePath$AuthModuleManifest."
}
elseif ($VersionState.Equals([VersionState]::EqualToFeed) -and !$BuildWhenEqual) {
Write-Warning "$ModulePrefix.$ModuleName module skipped. Version has not changed and is equal to what's on $RepositoryName."
}
elseif ($VersionState.Equals([VersionState]::Valid) -or $VersionState.Equals([VersionState]::NotOnFeed) -or $BuildWhenEqual) {
$ModuleVersion = $ManifestContent.ModuleVersion
# Build and pack generated module.
if ($Build -or $Run) {
if ($EnableSigning) {
Set-CSProjValues -ModuleCsProj $AuthCoreCSProj -ModuleVersion $ModuleVersion -AssemblyOriginatorKeyFile $SigningKeyFile
& $BuildModulePS1 -Module $ModuleName -ModulePrefix $ModulePrefix -ModuleVersion $ModuleVersion -ModulePreviewNumber $ModulePreviewNumber -ReleaseNotes $ManifestContent.PrivateData.PSData.ReleaseNotes -EnableSigning
}
else {
Set-CSProjValues -ModuleCsProj $AuthCoreCSProj -ModuleVersion $ModuleVersion
& $BuildModulePS1 -Module $ModuleName -ModulePrefix $ModulePrefix -ModuleVersion $ModuleVersion -ModulePreviewNumber $ModulePreviewNumber -ReleaseNotes $ManifestContent.PrivateData.PSData.ReleaseNotes
}
}
if ($Test) {
& $TestModulePS1 -ModulePath (Join-Path $AuthModulePath "artifacts" ) -ModuleName "$ModulePrefix.$ModuleName" -ModuleTestsPath (Join-Path $AuthModulePath "test")
}
if ($Pack -or $Run) {
& $PackModulePS1 -Module $ModuleName -ArtifactsLocation $ArtifactsLocation
}
if ($Run) {
& $RunModulePS1 -ModuleName "$ModulePrefix.$ModuleName" -ArtifactLocation $ArtifactsLocation
}
if ($Publish) {
& $PublishModulePS1 -Modules $ModuleName -ModulePrefix $ModulePrefix -ArtifactsLocation $ArtifactsLocation -RepositoryName $RepositoryName -RepositoryApiKey $RepositoryApiKey
}
}