|
3 | 3 | [string] $actor,
|
4 | 4 | [Parameter(HelpMessage = "The GitHub token running the action", Mandatory = $false)]
|
5 | 5 | [string] $token,
|
6 |
| - [Parameter(HelpMessage = "Specifies the parent telemetry scope for the telemetry signal", Mandatory = $false)] |
7 |
| - [string] $parentTelemetryScopeJson = '7b7d', |
8 | 6 | [Parameter(HelpMessage = "Project name if the repository is setup for multiple projects", Mandatory = $false)]
|
9 | 7 | [string] $project = '.',
|
10 | 8 | [Parameter(HelpMessage = "Direct Download Url of .app or .zip file", Mandatory = $true)]
|
@@ -78,149 +76,135 @@ function expandfile {
|
78 | 76 | }
|
79 | 77 | }
|
80 | 78 |
|
81 |
| -$telemetryScope = $null |
| 79 | +. (Join-Path -Path $PSScriptRoot -ChildPath "..\AL-Go-Helper.ps1" -Resolve) |
| 80 | +$serverUrl, $branch = CloneIntoNewFolder -actor $actor -token $token -updateBranch $updateBranch -DirectCommit $directCommit -newBranchPrefix 'add-existing-app' |
| 81 | +$baseFolder = (Get-Location).path |
| 82 | +DownloadAndImportBcContainerHelper -baseFolder $baseFolder |
82 | 83 |
|
83 |
| -try { |
84 |
| - . (Join-Path -Path $PSScriptRoot -ChildPath "..\AL-Go-Helper.ps1" -Resolve) |
85 |
| - $serverUrl, $branch = CloneIntoNewFolder -actor $actor -token $token -updateBranch $updateBranch -DirectCommit $directCommit -newBranchPrefix 'add-existing-app' |
86 |
| - $baseFolder = (Get-Location).path |
87 |
| - DownloadAndImportBcContainerHelper -baseFolder $baseFolder |
88 | 84 |
|
89 |
| - import-module (Join-Path -path $PSScriptRoot -ChildPath "..\TelemetryHelper.psm1" -Resolve) |
90 |
| - $telemetryScope = CreateScope -eventId 'DO0070' -parentTelemetryScopeJson $parentTelemetryScopeJson |
91 |
| - |
92 |
| - $type = "PTE" |
93 |
| - Write-Host "Reading $RepoSettingsFile" |
94 |
| - $settingsJson = Get-Content $RepoSettingsFile -Encoding UTF8 | ConvertFrom-Json |
95 |
| - if ($settingsJson.PSObject.Properties.Name -eq "type") { |
96 |
| - $type = $settingsJson.type |
97 |
| - } |
| 85 | +$type = "PTE" |
| 86 | +Write-Host "Reading $RepoSettingsFile" |
| 87 | +$settingsJson = Get-Content $RepoSettingsFile -Encoding UTF8 | ConvertFrom-Json |
| 88 | +if ($settingsJson.PSObject.Properties.Name -eq "type") { |
| 89 | + $type = $settingsJson.type |
| 90 | +} |
98 | 91 |
|
99 |
| - CheckAndCreateProjectFolder -project $project |
100 |
| - $projectFolder = (Get-Location).path |
| 92 | +CheckAndCreateProjectFolder -project $project |
| 93 | +$projectFolder = (Get-Location).path |
101 | 94 |
|
102 |
| - $appNames = @() |
103 |
| - getfiles -url $url | ForEach-Object { |
104 |
| - $appFolder = $_ |
105 |
| - "?Content_Types?.xml", "MediaIdListing.xml", "navigation.xml", "NavxManifest.xml", "DocComments.xml", "SymbolReference.json" | ForEach-Object { |
106 |
| - Remove-Item (Join-Path $appFolder $_) -Force -ErrorAction SilentlyContinue |
107 |
| - } |
108 |
| - $appJson = Get-Content (Join-Path $appFolder "app.json") -Encoding UTF8 | ConvertFrom-Json |
109 |
| - $appNames += @($appJson.Name) |
| 95 | +$appNames = @() |
| 96 | +getfiles -url $url | ForEach-Object { |
| 97 | + $appFolder = $_ |
| 98 | + "?Content_Types?.xml", "MediaIdListing.xml", "navigation.xml", "NavxManifest.xml", "DocComments.xml", "SymbolReference.json" | ForEach-Object { |
| 99 | + Remove-Item (Join-Path $appFolder $_) -Force -ErrorAction SilentlyContinue |
| 100 | + } |
| 101 | + $appJson = Get-Content (Join-Path $appFolder "app.json") -Encoding UTF8 | ConvertFrom-Json |
| 102 | + $appNames += @($appJson.Name) |
110 | 103 |
|
111 |
| - $ranges = @() |
112 |
| - if ($appJson.PSObject.Properties.Name -eq "idRanges") { |
113 |
| - $ranges += $appJson.idRanges |
114 |
| - } |
115 |
| - if ($appJson.PSObject.Properties.Name -eq "idRange") { |
116 |
| - $ranges += @($appJson.idRange) |
117 |
| - } |
| 104 | + $ranges = @() |
| 105 | + if ($appJson.PSObject.Properties.Name -eq "idRanges") { |
| 106 | + $ranges += $appJson.idRanges |
| 107 | + } |
| 108 | + if ($appJson.PSObject.Properties.Name -eq "idRange") { |
| 109 | + $ranges += @($appJson.idRange) |
| 110 | + } |
118 | 111 |
|
119 |
| - # Determine whether the app is PTE or AppSource App based on one of the id ranges (the first) |
120 |
| - if ($ranges[0].from -lt 100000 -and $ranges[0].to -lt 100000) { |
121 |
| - $ttype = "PTE" |
122 |
| - } |
123 |
| - else { |
124 |
| - $ttype = "AppSource App" |
125 |
| - } |
| 112 | + # Determine whether the app is PTE or AppSource App based on one of the id ranges (the first) |
| 113 | + if ($ranges[0].from -lt 100000 -and $ranges[0].to -lt 100000) { |
| 114 | + $ttype = "PTE" |
| 115 | + } |
| 116 | + else { |
| 117 | + $ttype = "AppSource App" |
| 118 | + } |
126 | 119 |
|
127 |
| - if ($appJson.PSObject.Properties.Name -eq "dependencies") { |
128 |
| - foreach($dependency in $appJson.dependencies) { |
129 |
| - if ($dependency.PSObject.Properties.Name -eq "AppId") { |
130 |
| - $id = $dependency.AppId |
131 |
| - } |
132 |
| - else { |
133 |
| - $id = $dependency.Id |
134 |
| - } |
135 |
| - if ($testRunnerApps.Contains($id)) { |
136 |
| - $ttype = "Test App" |
137 |
| - } |
| 120 | + if ($appJson.PSObject.Properties.Name -eq "dependencies") { |
| 121 | + foreach($dependency in $appJson.dependencies) { |
| 122 | + if ($dependency.PSObject.Properties.Name -eq "AppId") { |
| 123 | + $id = $dependency.AppId |
| 124 | + } |
| 125 | + else { |
| 126 | + $id = $dependency.Id |
| 127 | + } |
| 128 | + if ($testRunnerApps.Contains($id)) { |
| 129 | + $ttype = "Test App" |
138 | 130 | }
|
139 | 131 | }
|
| 132 | + } |
140 | 133 |
|
141 |
| - if ($ttype -ne "Test App") { |
142 |
| - foreach($appName in (Get-ChildItem -Path $appFolder -Filter "*.al" -Recurse).FullName) { |
143 |
| - $alContent = (Get-Content -Path $appName -Encoding UTF8) -join "`n" |
144 |
| - if ($alContent -like "*codeunit*subtype*=*test*[test]*") { |
145 |
| - $ttype = "Test App" |
146 |
| - } |
| 134 | + if ($ttype -ne "Test App") { |
| 135 | + foreach($appName in (Get-ChildItem -Path $appFolder -Filter "*.al" -Recurse).FullName) { |
| 136 | + $alContent = (Get-Content -Path $appName -Encoding UTF8) -join "`n" |
| 137 | + if ($alContent -like "*codeunit*subtype*=*test*[test]*") { |
| 138 | + $ttype = "Test App" |
147 | 139 | }
|
148 | 140 | }
|
| 141 | + } |
149 | 142 |
|
150 |
| - if ($ttype -ne "Test App" -and $ttype -ne $type) { |
151 |
| - OutputWarning -message "According to settings, repository is for apps of type $type. The app you are adding seams to be of type $ttype" |
152 |
| - } |
| 143 | + if ($ttype -ne "Test App" -and $ttype -ne $type) { |
| 144 | + OutputWarning -message "According to settings, repository is for apps of type $type. The app you are adding seams to be of type $ttype" |
| 145 | + } |
153 | 146 |
|
154 |
| - $appFolders = Get-ChildItem -Path $appFolder | Where-Object { $_.PSIsContainer -and (Test-Path (Join-Path $_.FullName 'app.json')) } |
155 |
| - if (-not $appFolders) { |
156 |
| - $appFolders = @($appFolder) |
157 |
| - # TODO: What to do about the über app.json - another workspace? another setting? |
158 |
| - } |
| 147 | + $appFolders = Get-ChildItem -Path $appFolder | Where-Object { $_.PSIsContainer -and (Test-Path (Join-Path $_.FullName 'app.json')) } |
| 148 | + if (-not $appFolders) { |
| 149 | + $appFolders = @($appFolder) |
| 150 | + # TODO: What to do about the über app.json - another workspace? another setting? |
| 151 | + } |
159 | 152 |
|
160 |
| - $orgfolderName = $appJson.name.Split([System.IO.Path]::getInvalidFileNameChars()) -join "" |
161 |
| - $folderName = GetUniqueFolderName -baseFolder $projectFolder -folderName $orgfolderName |
162 |
| - if ($folderName -ne $orgfolderName) { |
163 |
| - OutputWarning -message "$orgFolderName already exists as a folder in the repo, using $folderName instead" |
164 |
| - } |
| 153 | + $orgfolderName = $appJson.name.Split([System.IO.Path]::getInvalidFileNameChars()) -join "" |
| 154 | + $folderName = GetUniqueFolderName -baseFolder $projectFolder -folderName $orgfolderName |
| 155 | + if ($folderName -ne $orgfolderName) { |
| 156 | + OutputWarning -message "$orgFolderName already exists as a folder in the repo, using $folderName instead" |
| 157 | + } |
165 | 158 |
|
166 |
| - Move-Item -Path $appFolder -Destination $projectFolder -Force |
167 |
| - Rename-Item -Path ([System.IO.Path]::GetFileName($appFolder)) -NewName $folderName |
168 |
| - $appFolder = Join-Path $projectFolder $folderName |
| 159 | + Move-Item -Path $appFolder -Destination $projectFolder -Force |
| 160 | + Rename-Item -Path ([System.IO.Path]::GetFileName($appFolder)) -NewName $folderName |
| 161 | + $appFolder = Join-Path $projectFolder $folderName |
169 | 162 |
|
170 |
| - Get-ChildItem $appFolder -Filter '*.*' -Recurse | ForEach-Object { |
171 |
| - if ($_.Name.Contains('%20')) { |
172 |
| - Rename-Item -Path $_.FullName -NewName $_.Name.Replace('%20', ' ') |
173 |
| - } |
| 163 | + Get-ChildItem $appFolder -Filter '*.*' -Recurse | ForEach-Object { |
| 164 | + if ($_.Name.Contains('%20')) { |
| 165 | + Rename-Item -Path $_.FullName -NewName $_.Name.Replace('%20', ' ') |
174 | 166 | }
|
| 167 | + } |
175 | 168 |
|
176 |
| - $appFolders | ForEach-Object { |
177 |
| - # Modify .AL-Go\settings.json |
178 |
| - try { |
179 |
| - $settingsJsonFile = Join-Path $projectFolder $ALGoSettingsFile |
180 |
| - $SettingsJson = Get-Content $settingsJsonFile -Encoding UTF8 | ConvertFrom-Json |
181 |
| - if (@($settingsJson.appFolders) + @($settingsJson.testFolders)) { |
182 |
| - if ($ttype -eq "Test App") { |
183 |
| - if ($SettingsJson.testFolders -notcontains $foldername) { |
184 |
| - $SettingsJson.testFolders += @($folderName) |
185 |
| - } |
| 169 | + $appFolders | ForEach-Object { |
| 170 | + # Modify .AL-Go\settings.json |
| 171 | + try { |
| 172 | + $settingsJsonFile = Join-Path $projectFolder $ALGoSettingsFile |
| 173 | + $SettingsJson = Get-Content $settingsJsonFile -Encoding UTF8 | ConvertFrom-Json |
| 174 | + if (@($settingsJson.appFolders) + @($settingsJson.testFolders)) { |
| 175 | + if ($ttype -eq "Test App") { |
| 176 | + if ($SettingsJson.testFolders -notcontains $foldername) { |
| 177 | + $SettingsJson.testFolders += @($folderName) |
186 | 178 | }
|
187 |
| - else { |
188 |
| - if ($SettingsJson.appFolders -notcontains $foldername) { |
189 |
| - $SettingsJson.appFolders += @($folderName) |
190 |
| - } |
| 179 | + } |
| 180 | + else { |
| 181 | + if ($SettingsJson.appFolders -notcontains $foldername) { |
| 182 | + $SettingsJson.appFolders += @($folderName) |
191 | 183 | }
|
192 |
| - $SettingsJson | Set-JsonContentLF -Path $settingsJsonFile |
193 | 184 | }
|
| 185 | + $SettingsJson | Set-JsonContentLF -Path $settingsJsonFile |
194 | 186 | }
|
195 |
| - catch { |
196 |
| - throw "$ALGoSettingsFile is malformed. Error: $($_.Exception.Message)" |
197 |
| - } |
| 187 | + } |
| 188 | + catch { |
| 189 | + throw "$ALGoSettingsFile is malformed. Error: $($_.Exception.Message)" |
| 190 | + } |
198 | 191 |
|
199 |
| - # Modify workspace |
200 |
| - Get-ChildItem -Path $projectFolder -Filter "*.code-workspace" | ForEach-Object { |
201 |
| - try { |
202 |
| - $workspaceFileName = $_.Name |
203 |
| - $workspaceFile = $_.FullName |
204 |
| - $workspace = Get-Content $workspaceFile -Encoding UTF8 | ConvertFrom-Json |
205 |
| - if (-not ($workspace.folders | Where-Object { $_.Path -eq $foldername })) { |
206 |
| - $workspace.folders += @(@{ "path" = $foldername }) |
207 |
| - } |
208 |
| - $workspace | Set-JsonContentLF -Path $workspaceFile |
209 |
| - } |
210 |
| - catch { |
211 |
| - throw "$workspaceFileName is malformed.$([environment]::Newline) $($_.Exception.Message)" |
| 192 | + # Modify workspace |
| 193 | + Get-ChildItem -Path $projectFolder -Filter "*.code-workspace" | ForEach-Object { |
| 194 | + try { |
| 195 | + $workspaceFileName = $_.Name |
| 196 | + $workspaceFile = $_.FullName |
| 197 | + $workspace = Get-Content $workspaceFile -Encoding UTF8 | ConvertFrom-Json |
| 198 | + if (-not ($workspace.folders | Where-Object { $_.Path -eq $foldername })) { |
| 199 | + $workspace.folders += @(@{ "path" = $foldername }) |
212 | 200 | }
|
| 201 | + $workspace | Set-JsonContentLF -Path $workspaceFile |
| 202 | + } |
| 203 | + catch { |
| 204 | + throw "$workspaceFileName is malformed.$([environment]::Newline) $($_.Exception.Message)" |
213 | 205 | }
|
214 | 206 | }
|
215 | 207 | }
|
216 |
| - Set-Location $baseFolder |
217 |
| - CommitFromNewFolder -serverUrl $serverUrl -commitMessage "Add existing apps ($($appNames -join ', '))" -branch $branch | Out-Null |
218 |
| - |
219 |
| - TrackTrace -telemetryScope $telemetryScope |
220 |
| -} |
221 |
| -catch { |
222 |
| - if (Get-Module BcContainerHelper) { |
223 |
| - TrackException -telemetryScope $telemetryScope -errorRecord $_ |
224 |
| - } |
225 |
| - throw |
226 | 208 | }
|
| 209 | +Set-Location $baseFolder |
| 210 | +CommitFromNewFolder -serverUrl $serverUrl -commitMessage "Add existing apps ($($appNames -join ', '))" -branch $branch | Out-Null |
0 commit comments