forked from kine/NVRAppDevOps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Compile-ALProjectTree.ps1
134 lines (119 loc) · 7.48 KB
/
Compile-ALProjectTree.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
129
130
131
132
133
134
<#
.SYNOPSIS
Compile all AL projects in the folder tree
.DESCRIPTION
Read all app.json files in the folder tree and compile the apps in order to fullfill dependencies of the apps.
Dependencies which are not stored as source code in the tree must be placed to output path first as app files.
.EXAMPLE
PS C:\> Read-ALConfiguration -Path <repopath> | Compile-ALProjectTree -OrderedApps (Get-ALAppOrder -Path <repopath>) -PackagesPath <outputpath> -CertPwd <certpwd> -CertPath <certpath>
Will read the configuration for the repo (container name etc.) and will create app files in <outputpath> for all apps inside the tree.
Apps will be signed by selected certificate with given password
.Parameter ContainerName
Name of the container to use during compilation to get alc.exe etc.
.Parameter CertPath
Path to certificate for signing the apps. If not defined, apps will not be signed
.Parameter CertPwd
Password for the signing certificate
.Parameter OrderedApps
Array of Apps Info objects in order of compilation. You can use Get-ALAppOrder function to get it
.Parameter PackagesPath
Path where resulting .app files will be stored and which includes dependencies necessary for compiling the apps.
.Parameter EnableCodeCop
Add this switch to Enable CodeCop to run
.Parameter Failon
Specify if you want Compilation to fail on Error or Warning (Works only if running under Azure DevOps pipeline - $env:TF_BUILD is true)
.Parameter AsmProbingPaths
Specify paths for Assembly probing when using Addins or external libraries
.Parameter RulesetFile
File with rulesets to use during compilation
#>
function Compile-ALProjectTree
{
Param (
[Parameter(ValueFromPipelineByPropertyName=$True)]
$ContainerName,
[Parameter(ValueFromPipelineByPropertyName=$True)]
$CertPath,
[Parameter(ValueFromPipelineByPropertyName=$True)]
$CertPwd,
$OrderedApps,
$PackagesPath,
[Parameter(ValueFromPipelineByPropertyName=$True)]
$Password='',
[Parameter(ValueFromPipelineByPropertyName=$True)]
$Username=$env:USERNAME,
[ValidateSet('Windows', 'NavUserPassword')]
[Parameter(ValueFromPipelineByPropertyName=$True)]
$Auth='Windows',
[Parameter(ValueFromPipelineByPropertyName=$True)]
[bool]$EnableCodeCop=$True,
[Parameter(ValueFromPipelineByPropertyName=$True)]
[bool]$EnableAppSourceCop=$True,
[Parameter(ValueFromPipelineByPropertyName=$True)]
[bool]$EnablePerTenantExtensionCop=$True,
[Parameter(ValueFromPipelineByPropertyName=$True)]
[bool]$EnableUICop=$True,
[ValidateSet('none','error','warning')]
[string]$FailOn = 'error',
[Parameter(ValueFromPipelineByPropertyName=$True)]
$AppDownloadScript,
[Parameter(ValueFromPipelineByPropertyName=$True)]
$RulesetFile,
[Parameter(ValueFromPipelineByPropertyName=$True)]
$AsmProbingPaths
)
if (-not $PackagesPath) {
$PackagesPath = Get-Location
}
foreach ($App in $OrderedApps) {
if ($App.AppPath) {
Write-Host "**** Compiling $($App.name) ****"
$AppPath = Split-Path -Path $App.AppPath
$AppFileName = (Join-Path $PackagesPath "$($App.publisher)_$($App.name)_$($App.version).app")
if ($RulesetFile) {
if (-not [System.IO.Path]::IsPathRooted($RulesetFile)) {
$NewRulesetFile = (Join-Path $AppPath $RulesetFile)
} else {
$NewRulesetFile = $RulesetFile
}
Write-Host "Using ruleset path $RulesetFile $NewRulesetFile ($([System.IO.Path]::IsPathRooted($RulesetFile)))"
} else {
}
if ($Auth -eq 'NavUserPassword') {
$PWord = ConvertTo-SecureString -String $Password -AsPlainText -Force
$User = $Username
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User,$PWord
if ($env:TF_BUILD) {
Compile-AppInBcContainer -containerName $ContainerName -appProjectFolder $AppPath -appOutputFolder $PackagesPath -appSymbolsFolder $PackagesPath -AzureDevOps -credential $credentials -EnableCodeCop:$EnableCodeCop -EnableAppSourceCop:$EnableAppSourceCop -EnablePerTenantExtensionCop:$EnablePerTenantExtensionCop -EnableUICop:$EnableUICop -FailOn $FailOn -rulesetFile $NewRulesetFile -assemblyProbingPaths $AsmProbingPaths| Out-Null
} else {
Compile-AppInBcContainer -containerName $ContainerName -appProjectFolder $AppPath -appOutputFolder $PackagesPath -appSymbolsFolder $PackagesPath -credential $credentials -EnableCodeCop:$EnableCodeCop -EnableAppSourceCop:$EnableAppSourceCop -EnablePerTenantExtensionCop:$EnablePerTenantExtensionCop -EnableUICop:$EnableUICop -FailOn $FailOn -rulesetFile $NewRulesetFile -assemblyProbingPaths $AsmProbingPaths| Out-Null
}
} else {
if ($env:TF_BUILD) {
Compile-AppInBcContainer -containerName $ContainerName -appProjectFolder $AppPath -appOutputFolder $PackagesPath -appSymbolsFolder $PackagesPath -AzureDevOps -EnableCodeCop:$EnableCodeCop -EnableAppSourceCop:$EnableAppSourceCop -EnablePerTenantExtensionCop:$EnablePerTenantExtensionCop -EnableUICop:$EnableUICop -FailOn $FailOn -rulesetFile $NewRulesetFile -assemblyProbingPaths $AsmProbingPaths | Out-Null
} else {
Compile-AppInBcContainer -containerName $ContainerName -appProjectFolder $AppPath -appOutputFolder $PackagesPath -appSymbolsFolder $PackagesPath -EnableCodeCop:$EnableCodeCop -EnableAppSourceCop:$EnableAppSourceCop -EnablePerTenantExtensionCop:$EnablePerTenantExtensionCop -EnableUICop:$EnableUICop -FailOn $FailOn -rulesetFile $NewRulesetFile -assemblyProbingPaths $AsmProbingPaths | Out-Null
}
}
if ($CertPath) {
if ($CertPwd) {
Write-Host "Signing the app with $CertPath and password inside container..."
#& $SignTool sign /f $CertPath /p $CertPwd /t http://timestamp.verisign.com/scripts/timestamp.dll $AppFileName
Sign-BCContainerApp -containerName $ContainerName -appFile $AppFileName -pfxFile $CertPath -pfxPassword (ConvertTo-SecureString -String $CertPwd -AsPlainText -Force)
} else {
if (Test-Path "C:\Program Files (x86)\Windows Kits\10\bin\*\x64\SignTool.exe") {
$SignTool = (get-item "C:\Program Files (x86)\Windows Kits\10\bin\*\x64\SignTool.exe").FullName
} else {
throw "Couldn't find SignTool.exe, please install Windows SDK from https://go.microsoft.com/fwlink/p/?LinkID=2023014"
}
Write-Host "Signing the app with $CertPath without password (account permissions inside certificate used)..."
& $SignTool sign /f $CertPath /t http://timestamp.verisign.com/scripts/timestamp.dll $AppFileName
}
}
} else { #App not found, download
if ($App.publisher -ne 'Microsoft') {
Download-ALApp -name $App.name -publisher $App.publisher -version $App.version -targetPath $PackagesPath -AppDownloadScript $AppDownloadScript
}
}
}
}