Skip to content

Commit

Permalink
Fix PS errors and warnings (#352)
Browse files Browse the repository at this point in the history
<!-- Thank you for submitting a Pull Request. If you're new to
contributing to BCApps please read our pull request guideline below
* https://github.com/microsoft/BCApps/Contributing.md
-->
#### Summary <!-- Provide a general summary of your changes -->
Fix errors/warning in the PS scripts after PSScriptAnalyzer was enabled.

#### Work Item(s) <!-- Add the issue number here after the #. The issue
needs to be open and approved. Submitting PRs with no linked issues or
unapproved issues is highly discouraged. -->
Fixes AB#491803
  • Loading branch information
mazhelez authored Nov 17, 2023
1 parent 4ffbc31 commit 9e7133f
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/powershell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
with:
path: .\
recurse: true
excludeRule: '"PSAvoidUsingInvokeExpression", "PSUseShouldProcessForStateChangingFunctions", "PSAvoidUsingWriteHost", "PSAvoidUsingCmdletAliases"'
excludeRule: '"PSAvoidUsingInvokeExpression", "PSUseShouldProcessForStateChangingFunctions", "PSAvoidUsingWriteHost", "PSAvoidUsingCmdletAliases", "PSUseSingularNouns"'
output: results.sarif

# Upload the SARIF file generated in the previous step
Expand Down
4 changes: 3 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ if (-not (Get-Module -ListAvailable -Name "BCContainerHelper")) {
if ($AutoFill) {
Add-Type -AssemblyName System.Web

$credential = New-Object pscredential admin, (ConvertTo-SecureString -String ([System.Web.Security.Membership]::GeneratePassword(20, 5)) -AsPlainText -Force)
$password = [System.Web.Security.Membership]::GeneratePassword(20, 5)
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', Justification = 'local build')]
$credential = New-Object -TypeName pscredential -ArgumentList admin, ConvertTo-SecureString -String $password -AsPlainText -Force
$licenseFileUrl = 'none'
$containerName = "bcserver"
$auth = "UserPassword"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'parameters', Justification = 'The parameter is not used, but it''s script needs to match this format')]
Param(
[hashtable] $parameters
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'parameters', Justification = 'The parameter is not used, but it''s script needs to match this format')]
Param(
[hashtable] $parameters
)
Expand Down
4 changes: 1 addition & 3 deletions build/projects/System Application/.AL-Go/PreCompileApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ Param(
)

$scriptPath = Join-Path $PSScriptRoot "../../../scripts/PreCompileApp.ps1" -Resolve
$projectFolder = Join-Path $PSScriptRoot "../../System Application"

. $scriptPath -parameters $compilationParams -currentProjectFolder $projectFolder -appType $appType
. $scriptPath -parameters $compilationParams -appType $appType
4 changes: 1 addition & 3 deletions build/projects/Test Framework/.AL-Go/PreCompileApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ Param(
)

$scriptPath = Join-Path $PSScriptRoot "../../../scripts/PreCompileApp.ps1" -Resolve
$projectFolder = Join-Path $PSScriptRoot "../../Test Framework"

. $scriptPath -parameters $compilationParams -currentProjectFolder $projectFolder -appType $appType
. $scriptPath -parameters $compilationParams -appType $appType
4 changes: 1 addition & 3 deletions build/projects/Test Stability Tools/.AL-Go/PreCompileApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ Param(
)

$scriptPath = Join-Path $PSScriptRoot "../../../scripts/PreCompileApp.ps1" -Resolve
$projectFolder = Join-Path $PSScriptRoot "../../Test Stability Tools"

. $scriptPath -parameters $compilationParams -currentProjectFolder $projectFolder -appType $appType
. $scriptPath -parameters $compilationParams -appType $appType
18 changes: 10 additions & 8 deletions build/scripts/AppTranslations.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,26 @@ function Restore-TranslationsForApp {
# Translations need to be restored in the Translations folder in the app folder
$appTranslationsFolder = Join-Path $AppProjectFolder "Translations"
New-Directory -Path "$appTranslationsFolder" -ForceEmpty

$appName = (Get-ChildItem -Path $AppProjectFolder -Filter "app.json" | Get-Content | ConvertFrom-Json).name

Write-Host "Restoring translations for app $appName in $appTranslationsFolder"

$translationsOutputFolder = Join-Path (Get-BaseFolder) "out/translations/"
$translationPackagePath = Install-PackageFromConfig -PackageName "Microsoft.Dynamics.BusinessCentral.Translations" -OutputPath $translationsOutputFolder
$tranlationsPath = Join-Path $translationPackagePath "Translations"

$translationsFound = $false

# Copy the translations from the package to the app folder
Get-ChildItem $tranlationsPath -Filter *-* -Directory | ForEach-Object {
$localeFolder = $_.FullName
$locale = $_.Name

$translationFolders = Get-ChildItem $tranlationsPath -Filter *-* -Directory

foreach($translationFolder in $translationFolders) {
$localeFolder = $translationFolder.FullName
$locale = $translationFolder.Name

# Translations are located in the ExtensionsV2 folder
$translationFilePath = Join-Path $localeFolder "ExtensionsV2/$appName.$locale.xlf"
$translationFilePath = Join-Path $localeFolder "ExtensionsV2/$appName.$locale.xlf"
if(Test-Path $translationFilePath) {
Write-Host "Using translation for $appName in locale $locale."
$translationsFound = $true
Expand Down
4 changes: 2 additions & 2 deletions build/scripts/AutomatedSubmission.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ function New-TopicBranchIfNeeded
[string] $PullRequestTitle
)
$openPullRequests = gh api "/repos/$Repository/pulls" --method GET -f state=open | ConvertFrom-Json

$openPullRequests = $openPullRequests | Where-Object { $_.head.ref -match $Category }
if ($PullRequestTitle) {
$openPullRequests = $openPullRequests | Where-Object { $_.title -eq $PullRequestTitle }
}

$existingPullRequest = $openPullRequests | Select-Object -First 1

if ($existingPullRequest) {
$BranchName = $existingPullRequest.head.ref
git fetch origin $BranchName
Expand Down
4 changes: 1 addition & 3 deletions build/scripts/CompileAppInBcContainer.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Param(
[Parameter(Mandatory=$true)]
[string] $currentProjectFolder,
[Hashtable] $parameters
)

Expand All @@ -13,7 +11,7 @@ $appType = switch ($true) {
}

$PreCompileApp = (Get-Command "$PSScriptRoot\PreCompileApp.ps1" | Select-Object -ExpandProperty ScriptBlock)
Invoke-Command -ScriptBlock $PreCompileApp -ArgumentList $currentProjectFolder, $appType, ([ref] $parameters)
Invoke-Command -ScriptBlock $PreCompileApp -ArgumentList $appType, ([ref] $parameters)

$appFile = Compile-AppInBcContainer @parameters

Expand Down
2 changes: 1 addition & 1 deletion build/scripts/GitHub/GitHubPullRequest.class.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class GitHubPullRequest {
$githubMilestone = $allMilestones | Where-Object { $_.title -eq $Milestone }
if (-not $githubMilestone) {
Write-Host "::Warning:: Milestone '$Milestone' not found"
return
return
}
$milestoneNumber = $githubMilestone.number
gh api "/repos/$($this.Repository)/issues/$($this.PRNumber)" -H ([GitHubAPI]::AcceptJsonHeader) -H ([GitHubAPI]::GitHubAPIHeader) -F milestone=$milestoneNumber | ConvertFrom-Json
Expand Down
9 changes: 9 additions & 0 deletions build/scripts/PSScriptAnalyzerSettings.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@{
ExcludeRules = @(
"PSAvoidUsingInvokeExpression",
"PSUseShouldProcessForStateChangingFunctions",
"PSAvoidUsingWriteHost",
"PSAvoidUsingCmdletAliases",
"PSUseSingularNouns"
)
}
2 changes: 0 additions & 2 deletions build/scripts/PreCompileApp.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Param(
[Parameter(Mandatory=$true)]
[string] $currentProjectFolder,
[ValidateSet('app', 'testApp', 'bcptApp')]
[string] $appType = 'app',
[ref] $parameters
Expand Down
4 changes: 2 additions & 2 deletions build/scripts/SyncMirror.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ if ($Branch) {
Write-Host "Checking out $Branch from $SourceRepository"
RunAndCheck git checkout upstream/$Branch --track
}

# Merge changes from upstream
RunAndCheck git pull upstream $Branch

# Push to origin
Write-Host "Pushing $Branch to $TargetRepository"
RunAndCheck git push origin $Branch
Expand Down

0 comments on commit 9e7133f

Please sign in to comment.