Repository navigation
Expand file tree
/
Copy pathCreateApp.ps1
More file actions
143 lines (128 loc) · 6.58 KB
/
Copy pathCreateApp.ps1
File metadata and controls
143 lines (128 loc) · 6.58 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
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
135
136
137
138
139
140
141
142
143
Param(
[Parameter(HelpMessage = "The GitHub actor running the action", Mandatory = $false)]
[string] $actor,
[Parameter(HelpMessage = "The GitHub token running the action", Mandatory = $false)]
[string] $token,
[Parameter(HelpMessage = "Project name if the repository is setup for multiple projects", Mandatory = $false)]
[string] $project = '.',
[ValidateSet("PTE", "AppSource App" , "Test App", "Performance Test App")]
[Parameter(HelpMessage = "Type of app to add (PTE, AppSource App, Test App)", Mandatory = $true)]
[string] $type,
[Parameter(HelpMessage = "App Name", Mandatory = $true)]
[string] $name,
[Parameter(HelpMessage = "Publisher", Mandatory = $true)]
[string] $publisher,
[Parameter(HelpMessage = "ID range", Mandatory = $true)]
[string] $idrange,
[Parameter(HelpMessage = "Include Sample Code?", Mandatory = $false)]
[bool] $sampleCode,
[Parameter(HelpMessage = "Include Sample BCPT Suite?", Mandatory = $false)]
[bool] $sampleSuite,
[Parameter(HelpMessage = "Set the branch to update", Mandatory = $false)]
[string] $updateBranch,
[Parameter(HelpMessage = "Direct Commit?", Mandatory = $false)]
[bool] $directCommit
)
. (Join-Path -Path $PSScriptRoot -ChildPath "..\AL-Go-Helper.ps1" -Resolve)
$tmpFolder = Join-Path (GetTemporaryPath) ([Guid]::NewGuid().ToString())
try {
$serverUrl, $branch = CloneIntoNewFolder -actor $actor -token $token -updateBranch $updateBranch -DirectCommit $directCommit -newBranchPrefix "create-$($type.replace(' ','-').ToLowerInvariant())"
$baseFolder = (Get-Location).Path
DownloadAndImportBcContainerHelper -baseFolder $baseFolder
import-module (Join-Path -path $PSScriptRoot -ChildPath "AppHelper.psm1" -Resolve)
Write-Host "Template type : $type"
# Check parameters
if (-not $publisher) {
throw "A publisher must be specified."
}
if (-not $name) {
throw "An extension name must be specified."
}
$ids = ConfirmIdRanges -templateType $type -idrange $idrange
CheckAndCreateProjectFolder -project $project
$projectFolder = (Get-Location).Path
if ($type -eq "Performance Test App") {
try {
$settings = ReadSettings -baseFolder $baseFolder -project $project
$settings = AnalyzeRepo -settings $settings -baseFolder $baseFolder -project $project -doNotIssueWarnings
$folders = Download-Artifacts -artifactUrl $settings.artifact -includePlatform
$sampleApp = Join-Path $folders[0] "Applications.*\Microsoft_Performance Toolkit Samples_*.app"
if (Test-Path $sampleApp) {
$sampleApp = (Get-Item -Path $sampleApp).FullName
}
else {
# Narrow the search to the Applications subdirectory if present, to avoid traversing the entire artifact tree
$searchRoot = Get-ChildItem -Path $folders[1] -Directory -ErrorAction SilentlyContinue | Where-Object { $_.Name -ieq 'Applications' } | Select-Object -First 1 -ExpandProperty FullName
if (!$searchRoot) { $searchRoot = $folders[1] }
$sampleApp = Get-ChildItem -Path $searchRoot -Filter "Microsoft_Performance Toolkit Samples.app" -File -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
}
if (!$sampleApp -or !(Test-Path -Path $sampleApp)) {
throw "Could not locate 'Microsoft_Performance Toolkit Samples.app' under '$($folders[1])'"
}
Extract-AppFileToFolder -appFilename $sampleApp -generateAppJson -appFolder $tmpFolder
}
catch {
throw "Unable to create performance test app. Error was $($_.Exception.Message)"
}
}
$orgfolderName = $name.Split([System.IO.Path]::getInvalidFileNameChars()) -join ""
$folderName = GetUniqueFolderName -baseFolder $projectFolder -folderName $orgfolderName
if ($folderName -ne $orgfolderName) {
OutputWarning -message "Folder $orgFolderName already exists in the repo, folder name $folderName will be used instead."
}
# Modify .AL-Go\settings.json
try {
$settingsJsonFile = Join-Path $projectFolder $ALGoSettingsFile
$SettingsJson = Get-Content $settingsJsonFile -Encoding UTF8 | ConvertFrom-Json
'appFolders','testFolders','bcptTestFolders' | ForEach-Object {
if (-not ($settingsJson.PSObject.Properties.Name -eq $_)) {
$SettingsJson | Add-Member -MemberType NoteProperty -Name $_ -Value @()
}
}
if (@($settingsJson.appFolders)+@($settingsJson.testFolders)+@($settingsJson.bcptTestFolders)) {
if ($type -eq "Performance Test App") {
if ($SettingsJson.bcptTestFolders -notcontains $foldername) {
$SettingsJson.bcptTestFolders += @($folderName)
}
}
elseif ($type -eq "Test App") {
if ($SettingsJson.testFolders -notcontains $foldername) {
$SettingsJson.testFolders += @($folderName)
}
}
else {
if ($SettingsJson.appFolders -notcontains $foldername) {
$SettingsJson.appFolders += @($folderName)
}
}
$SettingsJson | Set-JsonContentLF -Path $settingsJsonFile
}
}
catch {
throw "A malformed $ALGoSettingsFile is encountered.$([environment]::Newline) $($_.Exception.Message)"
}
$appVersion = "1.0.0.0"
if ($settingsJson.PSObject.Properties.Name -eq "AppVersion") {
$appVersion = "$($settingsJson.AppVersion).0.0"
}
if ($type -eq "Performance Test App") {
NewSamplePerformanceTestApp -destinationPath (Join-Path $projectFolder $folderName) -name $name -publisher $publisher -version $appVersion -sampleCode $sampleCode -sampleSuite $sampleSuite -idrange $ids -appSourceFolder $tmpFolder
}
elseif ($type -eq "Test App") {
NewSampleTestApp -destinationPath (Join-Path $projectFolder $folderName) -name $name -publisher $publisher -version $appVersion -sampleCode $sampleCode -idrange $ids
}
else {
NewSampleApp -destinationPath (Join-Path $projectFolder $folderName) -name $name -publisher $publisher -version $appVersion -sampleCode $sampleCode -idrange $ids
}
UpdateWorkspaces -projectFolder $projectFolder -appName $folderName
Set-Location $baseFolder
CommitFromNewFolder -serverUrl $serverUrl -commitMessage "New $type ($Name)" -branch $branch | Out-Null
}
catch {
throw
}
finally {
if (Test-Path $tmpFolder) {
Remove-Item $tmpFolder -Recurse -Force
}
}