-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- 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 --> draft of CLEANSCHEMA symbols #### 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#549296](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/549296) --------- Co-authored-by: mazhelez <[email protected]> Co-authored-by: Maria Zhelezova <[email protected]>
- Loading branch information
1 parent
7c9f076
commit 7429883
Showing
28 changed files
with
599 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Current path is .github/actions/VerifyAppChanges | ||
|
||
Import-Module "$PSScriptRoot\..\..\..\build\scripts\EnlistmentHelperFunctions.psm1" -DisableNameChecking | ||
Import-Module "$PSScriptRoot\..\..\..\build\scripts\GuardingV2ExtensionsHelper.psm1" -DisableNameChecking | ||
Import-Module "$PSScriptRoot\..\..\..\build\scripts\TestPreprocessorSymbols.psm1" -Force | ||
|
||
# Get the major build version from the main branch | ||
$mainVersion = Get-MaxAllowedObsoleteVersion | ||
|
||
# Get the major build version from the current branch | ||
$currentVersion = (Get-ConfigValue -Key "repoVersion" -ConfigType AL-Go) -split '\.' | Select-Object -First 1 | ||
|
||
# CLEANSCHEMA is on a 5y cycle starting from 26 | ||
if ($CurrentVersion -le 26) { | ||
$schemaLowerBound = 15 | ||
} else { | ||
$schemaLowerBound = ([math]::Floor(($CurrentVersion - 2) / 5) * 5) - 2 # makes a series: 23, 28, 33, 38, 43 etc. This is the version is which we clean up (26, 31, 36, etc.) - 3. | ||
} | ||
|
||
# Define the preprocessor symbols to check for | ||
$symbolConfigs = @( | ||
@{stem = "CLEAN"; lowerBound = ($CurrentVersion - 4); upperBound = $mainVersion}, | ||
@{stem = "CLEANSCHEMA"; lowerBound = $schemaLowerBound; upperBound = $mainVersion + 3} # next lowerbound, after cleanup should be 25, then | ||
) | ||
|
||
Write-Host "Checking preprocessor symbols with $symbolConfigs" | ||
|
||
#initialize arrays to store any invalid preprocessor symbols with line numbers | ||
$invalidLowercaseSymbols = @() | ||
$invalidPatternSymbols = @() | ||
$invalidStemSymbols = @() | ||
|
||
$alfiles = (Get-ChildItem -Filter '*.al' -Recurse) | Select-Object -ExpandProperty FullName | ||
foreach ($file in $alfiles) { | ||
# Call the Test-PreprocessorSymbols function with the file path and calculated version bounds | ||
$result = Test-PreprocessorSymbols -filePath $file -symbolConfigs $symbolConfigs | ||
if ($null -ne $result) { | ||
$invalidLowercaseSymbols += $result.invalidLowercaseSymbols | ||
$invalidPatternSymbols += $result.invalidPatternSymbols | ||
$invalidStemSymbols += $result.invalidStemSymbols | ||
} | ||
} | ||
|
||
$symbolErrors = $invalidLowercaseSymbols + $invalidPatternSymbols + $invalidStemSymbols | ||
if ($symbolErrors.Count -gt 0) { | ||
throw "Errors found in preprocessor symbols:`n $symbolErrors" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: Test Preprocessor Symbols | ||
author: Microsoft Corporation | ||
description: Verifies the preprocessor symbols on .al files | ||
runs: | ||
using: composite | ||
steps: | ||
- name: Test Preprocessor Symbols | ||
shell: pwsh | ||
run: | | ||
${{ github.action_path }}/action.ps1 | ||
branding: | ||
icon: terminal | ||
color: blue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: 'Verify App Changes' | ||
|
||
on: | ||
pull_request: | ||
branches: [ 'main', 'releases/*'] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
VerifyAppChanges: | ||
runs-on: windows-latest | ||
name: Verify App Changes | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
with: | ||
ref: ${{ github.sha }} | ||
|
||
- uses: microsoft/BCApps/.github/actions/TestPreprocessorSymbols@cedb78a7972da09fcdaf9ccaa86aef0ded2b5da7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<# | ||
.SYNOPSIS | ||
This script checks the preprocessor symbols in an AL file. | ||
.DESCRIPTION | ||
This script checks the preprocessor symbols in an AL file for the following: | ||
- Ensures there is no space after the '#' character. | ||
- Ensures preprocessor symbols have uppercase stems. | ||
- Ensures preprocessor symbols are within a specified range. | ||
- Ensures preprocessor symbols are in the correct format. | ||
- Ensures preprocessor symbols are not in lowercase. | ||
.PARAMETER filePath | ||
The path to the file to be checked. | ||
.PARAMETER symbolConfigs | ||
An array of objects where each entry has a stem, an upper, and a lower bound. | ||
.EXAMPLE | ||
$alfiles = Get-ChildItem -Recurse -Filter *.al -Path .\App\ | ||
foreach ($alfile in $alfiles) { | ||
$symbolConfigs = @( | ||
@{stem="CLEAN"; lowerBound=22; upperBound=26}, | ||
@{stem="CLEANSCHEMA"; lowerBound=22; upperBound=26} | ||
) | ||
Test-PreprocessorSymbols -filePath $alfile.FullName -symbolConfigs $symbolConfigs | ||
} | ||
.NOTES | ||
Author: Gert Robyns | ||
Date: 2024-09-03 | ||
Updated by: Gert Robyns | ||
Date: 2024-09-20 | ||
#> | ||
function Test-PreprocessorSymbols { | ||
param ( | ||
[Parameter(Mandatory=$true)] | ||
[string]$filePath, | ||
[Parameter(Mandatory=$true)] | ||
[hashtable[]]$symbolConfigs | ||
) | ||
|
||
# check if extension is .al, else return $null | ||
if ('.al' -ne [system.io.path]::GetExtension($filePath)) { | ||
return $null | ||
} | ||
|
||
# Define the regex pattern for disallowing a space after # | ||
$noSpaceAfterHashPattern = "^#\s" | ||
$lowercasePattern = "^#(if|elseif|else\b|endif)" | ||
$lowercaseNotPattern = "^#if not " | ||
$symbolPattern = @() | ||
|
||
foreach ($config in $symbolConfigs) { | ||
$stem = $config.stem | ||
$lowerBound = $config.lowerBound | ||
$upperBound = $config.upperBound | ||
|
||
# Generate the regex pattern for the SymbolStem range | ||
$rangePattern = "$($lowerBound..$upperBound -join '|')" | ||
|
||
$upperStem = $stem.ToUpper() | ||
$symbolPattern += "^#if\s${upperStem}($rangePattern)" | ||
$symbolPattern += "^#if\snot\s${upperStem}($rangePattern)" | ||
$symbolPattern += "^#elseif\s${upperStem}($rangePattern)" | ||
} | ||
|
||
# Add #endif to the symbol pattern but not to the strict pattern | ||
$symbolPattern += "#else\b" | ||
$symbolPattern += "#endif" | ||
|
||
# Read the content of the file | ||
$content = Get-Content -Path $filePath | ||
|
||
# Initialize lists to store any invalid preprocessor symbols with line numbers | ||
$invalidLowercaseSymbols = @() | ||
$invalidPatternSymbols = @() | ||
$invalidStemSymbols = @() | ||
|
||
# Iterate through each line in the file content with line numbers | ||
for ($i = 0; $i -lt $content.Count; $i++) { | ||
$line = $content[$i] | ||
$lineNumber = $i + 1 | ||
|
||
# Check for space after # | ||
if ($line -cmatch $noSpaceAfterHashPattern) { | ||
$invalidPatternSymbols += "${filePath}:${lineNumber}: $line" | ||
} | ||
|
||
# Check for lowercase | ||
if (($line -match $lowercasePattern) -and ($line -cnotmatch $lowercasePattern)) { | ||
$invalidLowercaseSymbols += "${filePath}:${lineNumber}: $line" | ||
} | ||
|
||
# Check for lowercase not | ||
if (($line -match $lowercaseNotPattern) -and ($line -cnotmatch $lowercaseNotPattern)) { | ||
$invalidLowercaseSymbols += "${filePath}:${lineNumber}: $line" | ||
} | ||
|
||
# Check for strict pattern match | ||
$isValidPattern = $false | ||
foreach ($pattern in $symbolPattern) { | ||
if ($line -match $pattern) { | ||
$isValidPattern = $true | ||
break | ||
} | ||
} | ||
if ($line -match $lowercasePattern -and -not $isValidPattern -and $line -notmatch "^#endif") { | ||
$invalidPatternSymbols += "${filePath}:${lineNumber}: $line" | ||
} | ||
|
||
# Check for uppercase stem | ||
foreach ($config in $symbolConfigs) { | ||
$stem = $config.stem | ||
$upperStem = $stem.ToUpper() | ||
if ($line -match "#(if|if not|elseif)\s+${stem}($rangePattern)" -and $line -cnotmatch "#((?i)(if|if not|elseif))\s+${upperStem}($rangePattern)") { | ||
$invalidStemSymbols += "${filePath}:${lineNumber}: $line" | ||
} | ||
} | ||
} | ||
|
||
if (($invalidLowercaseSymbols.Count -gt 0) -or ($invalidPatternSymbols -gt 0) -or ($invalidStemSymbols -gt 0)) { | ||
return @{ "invalidLowercaseSymbols" = $invalidLowercaseSymbols; "invalidPatternSymbols" = $invalidPatternSymbols; "invalidStemSymbols" = $invalidStemSymbols } | ||
} else { | ||
return $null | ||
} | ||
} | ||
|
||
Export-ModuleMember -Function Test-PreprocessorSymbols |
Oops, something went wrong.