Skip to content

Commit 8ec6169

Browse files
authored
Update AL-Go Telemetry Module (#1049)
- Log telemetry without needing bccontainerhelper - Remove parentTelemetryScopeJson inputs to AL-Go actions - Add a bit more GitHub context to telemetry
1 parent 1655697 commit 8ec6169

File tree

108 files changed

+1429
-1624
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+1429
-1624
lines changed

Actions/AL-Go-Helper.ps1

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ $defaultCICDPushBranches = @( 'main', 'release/*', 'feature/*' )
1919
$defaultCICDPullRequestBranches = @( 'main' )
2020
$runningLocal = $local.IsPresent
2121
$defaultBcContainerHelperVersion = "preview" # Must be double quotes. Will be replaced by BcContainerHelperVersion if necessary in the deploy step - ex. "https://github.com/organization/navcontainerhelper/archive/refs/heads/branch.zip"
22-
$microsoftTelemetryConnectionString = "InstrumentationKey=84bd9223-67d4-4378-8590-9e4a46023be2;IngestionEndpoint=https://westeurope-1.in.applicationinsights.azure.com/"
2322
$notSecretProperties = @("Scopes","TenantId","BlobName","ContainerName","StorageAccountName","ServerUrl","ppUserName")
2423

2524
$runAlPipelineOverrides = @(
@@ -631,7 +630,7 @@ function ReadSettings {
631630
"cacheImageName" = "my"
632631
"cacheKeepDays" = 3
633632
"alwaysBuildAllProjects" = $false
634-
"microsoftTelemetryConnectionString" = $microsoftTelemetryConnectionString
633+
"microsoftTelemetryConnectionString" = "InstrumentationKey=cd2cc63e-0f37-4968-b99a-532411a314b8;IngestionEndpoint=https://northeurope-2.in.applicationinsights.azure.com/"
635634
"partnerTelemetryConnectionString" = ""
636635
"sendExtendedTelemetryToMicrosoft" = $false
637636
"environments" = @()

Actions/AddExistingApp/AddExistingApp.ps1

+103-119
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
[string] $actor,
44
[Parameter(HelpMessage = "The GitHub token running the action", Mandatory = $false)]
55
[string] $token,
6-
[Parameter(HelpMessage = "Specifies the parent telemetry scope for the telemetry signal", Mandatory = $false)]
7-
[string] $parentTelemetryScopeJson = '7b7d',
86
[Parameter(HelpMessage = "Project name if the repository is setup for multiple projects", Mandatory = $false)]
97
[string] $project = '.',
108
[Parameter(HelpMessage = "Direct Download Url of .app or .zip file", Mandatory = $true)]
@@ -78,149 +76,135 @@ function expandfile {
7876
}
7977
}
8078

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
8283

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
8884

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+
}
9891

99-
CheckAndCreateProjectFolder -project $project
100-
$projectFolder = (Get-Location).path
92+
CheckAndCreateProjectFolder -project $project
93+
$projectFolder = (Get-Location).path
10194

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)
110103

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+
}
118111

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+
}
126119

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"
138130
}
139131
}
132+
}
140133

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"
147139
}
148140
}
141+
}
149142

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+
}
153146

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+
}
159152

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+
}
165158

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
169162

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', ' ')
174166
}
167+
}
175168

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)
186178
}
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)
191183
}
192-
$SettingsJson | Set-JsonContentLF -Path $settingsJsonFile
193184
}
185+
$SettingsJson | Set-JsonContentLF -Path $settingsJsonFile
194186
}
195-
catch {
196-
throw "$ALGoSettingsFile is malformed. Error: $($_.Exception.Message)"
197-
}
187+
}
188+
catch {
189+
throw "$ALGoSettingsFile is malformed. Error: $($_.Exception.Message)"
190+
}
198191

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 })
212200
}
201+
$workspace | Set-JsonContentLF -Path $workspaceFile
202+
}
203+
catch {
204+
throw "$workspaceFileName is malformed.$([environment]::Newline) $($_.Exception.Message)"
213205
}
214206
}
215207
}
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
226208
}
209+
Set-Location $baseFolder
210+
CommitFromNewFolder -serverUrl $serverUrl -commitMessage "Add existing apps ($($appNames -join ', '))" -branch $branch | Out-Null

Actions/AddExistingApp/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ none
1515
| shell | | The shell (powershell or pwsh) in which the PowerShell script in this action should run | powershell |
1616
| actor | | The GitHub actor running the action | github.actor |
1717
| token | | The GitHub token running the action | github.token |
18-
| parentTelemetryScopeJson | | Specifies the parent telemetry scope for the telemetry signal | {} |
1918
| project | | Project name if the repository is setup for multiple projects | . |
2019
| url | Yes | Direct Download Url of .app or .zip file to add to the repository | |
2120
| updateBranch | | Which branch should the app be added to | github.ref_name |

Actions/AddExistingApp/action.yaml

+2-12
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ inputs:
1616
description: The GitHub token running the action
1717
required: false
1818
default: ${{ github.token }}
19-
parentTelemetryScopeJson:
20-
description: Specifies the parent telemetry scope for the telemetry signal
21-
required: false
22-
default: '7b7d'
2319
project:
2420
description: Project name if the repository is setup for multiple projects
2521
required: false
@@ -43,19 +39,13 @@ runs:
4339
env:
4440
_actor: ${{ inputs.actor }}
4541
_token: ${{ inputs.token }}
46-
_parentTelemetryScopeJson: ${{ inputs.parentTelemetryScopeJson }}
4742
_project: ${{ inputs.project }}
4843
_url: ${{ inputs.url }}
4944
_updateBranch: ${{ inputs.updateBranch }}
5045
_directCommit: ${{ inputs.directCommit }}
5146
run: |
52-
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
53-
try {
54-
${{ github.action_path }}/AddExistingApp.ps1 -actor $ENV:_actor -token $ENV:_token -parentTelemetryScopeJson $ENV:_parentTelemetryScopeJson -project $ENV:_project -url $ENV:_url -updateBranch $ENV:_updateBranch -directCommit ($ENV:_directCommit -eq 'true')
55-
}
56-
catch {
57-
Write-Host "::ERROR::Unexpected error when running action. Error Message: $($_.Exception.Message.Replace("`r",'').Replace("`n",' ')), StackTrace: $($_.ScriptStackTrace.Replace("`r",'').Replace("`n",' <- '))";
58-
exit 1
47+
${{ github.action_path }}/../Invoke-AlGoAction.ps1 -ActionName "AddExistingApp" -Action {
48+
${{ github.action_path }}/AddExistingApp.ps1 -actor $ENV:_actor -token $ENV:_token -project $ENV:_project -url $ENV:_url -updateBranch $ENV:_updateBranch -directCommit ($ENV:_directCommit -eq 'true')
5949
}
6050
branding:
6151
icon: terminal

0 commit comments

Comments
 (0)