Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLEANSCHEMA symbols #2065

Merged
merged 25 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a2418a2
add CLEANSCHEMA symbols
grobyns Sep 19, 2024
2199b34
Merge branch 'main' of https://github.com/microsoft/BCApps into featu…
grobyns Sep 19, 2024
eac961b
Port the gate for testing app clean symbols
mazhelez Sep 19, 2024
4eda538
Fix typo
mazhelez Sep 19, 2024
b7d4605
Merge branch 'main' of https://github.com/microsoft/BCApps into mazhe…
mazhelez Sep 20, 2024
ce43d16
Adapt script to BCApps (#2072)
mazhelez Sep 20, 2024
1deb205
Merge branch 'main' of https://github.com/microsoft/BCApps into featu…
grobyns Sep 20, 2024
f2f1782
Merge branch 'mazhelez/add-verifyappchanges-check' of https://github.…
grobyns Sep 20, 2024
8fe9f6b
script changes
grobyns Sep 20, 2024
18003a3
review comment
grobyns Sep 20, 2024
bd00fbe
fix whitespace
grobyns Sep 20, 2024
0913524
comments
grobyns Sep 20, 2024
0b1c1b9
cuz maria said so
grobyns Sep 20, 2024
9e3000a
review comment
grobyns Sep 20, 2024
e97ff84
move pester tests
grobyns Sep 20, 2024
8095f7b
Add job to run PS tests
mazhelez Sep 20, 2024
c9fb219
Merge branch 'features/549296' of https://github.com/microsoft/BCApps…
mazhelez Sep 20, 2024
8fa24f1
Add runTests.ps1
mazhelez Sep 20, 2024
c22aad0
Fix failing tests
mazhelez Sep 20, 2024
3e3f7f0
review comments
grobyns Sep 23, 2024
1550886
let's see if this works
grobyns Sep 23, 2024
cedb78a
Rename action folder
mazhelez Sep 23, 2024
07fac42
Use SHA for action ref (to be changed to main afterwards)
mazhelez Sep 23, 2024
a35a643
Rename workflow
mazhelez Sep 23, 2024
9119ba3
Merge branch 'main' of https://github.com/microsoft/BCApps into featu…
mazhelez Sep 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/actions/VerifyAppChanges/TestPreprocessorSymbols.ps1
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
Fixed Show fixed Hide fixed

# Get the major build version from the main branch
Fixed Show fixed Hide fixed
$mainVersion = Get-MaxAllowedObsoleteVersion

# Get the major build version from the current branch
Fixed Show fixed Hide fixed
$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
grobyns marked this conversation as resolved.
Show resolved Hide resolved
}

# Define the preprocessor symbols to check for
$symbolConfigs = @(
@{stem = "CLEAN"; lowerBound = ($CurrentVersion - 4); upperBound = $mainVersion},
aholstrup1 marked this conversation as resolved.
Show resolved Hide resolved
@{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"
}
13 changes: 13 additions & 0 deletions .github/actions/VerifyAppChanges/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Verify App Changes
grobyns marked this conversation as resolved.
Show resolved Hide resolved
author: Microsoft Corporation
description: Verifies the changes on AL files changed in a PR
grobyns marked this conversation as resolved.
Show resolved Hide resolved
runs:
using: composite
steps:
- name: Test Preprocessor Symbols
shell: pwsh
run: |
${{ github.action_path }}/TestPreprocessorSymbols.ps1
branding:
icon: terminal
color: blue
21 changes: 21 additions & 0 deletions .github/workflows/VerifyAppChanges.yaml
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@v4
grobyns marked this conversation as resolved.
Show resolved Hide resolved
with:
ref: ${{ github.sha }}

- uses: mazhelez/BCApps/.github/actions/VerifyAppChanges@main
4 changes: 2 additions & 2 deletions build/scripts/GuardingV2ExtensionsHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function Update-AppSourceCopVersion

# All major versions greater than current but less or equal to main should be allowed
$currentBuildVersion = [int] $buildVersion.Split('.')[0]
$maxAllowedObsoleteVersion = [int] (GetMaxAllowedObsoleteVersion)
$maxAllowedObsoleteVersion = [int] (Get-MaxAllowedObsoleteVersion)
$obsoleteTagAllowedVersions = @()

# Add 3 versions for tasks built with CLEANpreProcessorSymbols
Expand Down Expand Up @@ -257,7 +257,7 @@ function Test-IsStrictModeEnabled
return $false
}

function GetMaxAllowedObsoleteVersion() {
function Get-MaxAllowedObsoleteVersion() {
git fetch origin main
$alGoSettings = $(git show origin/main:.github/AL-Go-Settings.json) | ConvertFrom-Json
if (-not $alGoSettings.repoVersion) {
Expand Down
122 changes: 122 additions & 0 deletions build/scripts/TestPreprocessorSymbols.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<#
- Ensures preprocessor symbols have uppercase stems.
- Ensures there is no space after the '#' character.

.PARAMETER filePath
The path to the file to be checked.

.PARAMETER symbolConfigs
An array of hash tables 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 {
Fixed Show fixed Hide fixed
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
}
Fixed Show fixed Hide fixed

# 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"
}

Fixed Show fixed Hide fixed
# 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
}
Fixed Show fixed Hide fixed
}

Export-ModuleMember -Function Test-PreprocessorSymbols
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ tableextension 230 ObsoleteSourceCodeExt extends "Source Code"
MovedTo = '437dbf0e-84ff-417a-965d-ed2bb9650972';
ObsoleteTag = '25.0';
}
#if not CLEANSCHEMA15
field(10620; "SAFT Source Code"; Code[9])
{
Caption = 'SAF-T Source Code';
Expand All @@ -28,6 +29,7 @@ tableextension 230 ObsoleteSourceCodeExt extends "Source Code"
ObsoleteTag = '15.0';
#pragma warning restore AS0072
}
#endif
field(28160; Simulation; Boolean)
{
Caption = 'Simulation';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ tableextension 242 ObsoleteSourceCodeSetupExt extends "Source Code Setup"
ObsoleteTag = '25.0';
MovedTo = '437dbf0e-84ff-417a-965d-ed2bb9650972';
}
#if not CLEANSCHEMA15
field(11200; "Inward Registration"; Code[10])
{
Caption = 'Inward Registration';
Expand All @@ -849,6 +850,7 @@ tableextension 242 ObsoleteSourceCodeSetupExt extends "Source Code Setup"
ObsoleteTag = '15.0';
#pragma warning restore AS0072
}
#endif
field(11307; "Financial Journal"; Code[10])
{
Caption = 'Financial Journal';
Expand Down Expand Up @@ -879,6 +881,7 @@ tableextension 242 ObsoleteSourceCodeSetupExt extends "Source Code Setup"
ObsoleteTag = '25.0';
MovedTo = '437dbf0e-84ff-417a-965d-ed2bb9650972';
}
#if not CLEANSCHEMA20
field(11760; "Purchase VAT Delay"; Code[10])
{
Caption = 'Purchase VAT Delay';
Expand All @@ -901,6 +904,8 @@ tableextension 242 ObsoleteSourceCodeSetupExt extends "Source Code Setup"
ObsoleteTag = '20.0';
#pragma warning restore AS0072
}
#endif
#if not CLEANSCHEMA18
field(11762; "VAT Coefficient"; Code[10])
{
Caption = 'VAT Coefficient';
Expand All @@ -912,6 +917,8 @@ tableextension 242 ObsoleteSourceCodeSetupExt extends "Source Code Setup"
ObsoleteTag = '18.0';
#pragma warning restore AS0072
}
#endif
#if not CLEANSCHEMA22
field(11764; "Close Balance Sheet"; Code[10])
{
Caption = 'Close Balance Sheet';
Expand All @@ -934,6 +941,8 @@ tableextension 242 ObsoleteSourceCodeSetupExt extends "Source Code Setup"
ObsoleteTag = '22.0';
#pragma warning restore AS0072
}
#endif
#if not CLEANSCHEMA20
field(11766; "Cash Desk"; Code[10])
{
Caption = 'Cash Desk';
Expand All @@ -945,6 +954,7 @@ tableextension 242 ObsoleteSourceCodeSetupExt extends "Source Code Setup"
ObsoleteTag = '20.0';
#pragma warning restore AS0072
}
#endif
field(12400; "Advance Statements"; Code[10])
{
Caption = 'Advance Statements';
Expand Down Expand Up @@ -1065,6 +1075,7 @@ tableextension 242 ObsoleteSourceCodeSetupExt extends "Source Code Setup"
ObsoleteTag = '25.0';
MovedTo = '437dbf0e-84ff-417a-965d-ed2bb9650972';
}
#if not CLEANSCHEMA21
field(12450; "Item Receipt"; Code[10])
{
Caption = 'Item Receipt';
Expand All @@ -1087,6 +1098,7 @@ tableextension 242 ObsoleteSourceCodeSetupExt extends "Source Code Setup"
ObsoleteTag = '21.0';
#pragma warning restore AS0072
}
#endif
field(12470; "FA Release"; Code[10])
{
Caption = 'FA Release';
Expand Down Expand Up @@ -1147,6 +1159,7 @@ tableextension 242 ObsoleteSourceCodeSetupExt extends "Source Code Setup"
ObsoleteTag = '25.0';
MovedTo = '437dbf0e-84ff-417a-965d-ed2bb9650972';
}
#if not CLEANSCHEMA18
field(31041; "Maintenance Adjustment"; Code[10])
{
Caption = 'Maintenance Adjustment';
Expand All @@ -1158,6 +1171,8 @@ tableextension 242 ObsoleteSourceCodeSetupExt extends "Source Code Setup"
ObsoleteTag = '18.0';
#pragma warning restore AS0072
}
#endif
#if not CLEANSCHEMA21
field(31050; Credit; Code[10])
{
Caption = 'Credit';
Expand All @@ -1169,6 +1184,7 @@ tableextension 242 ObsoleteSourceCodeSetupExt extends "Source Code Setup"
ObsoleteTag = '21.0';
#pragma warning restore AS0072
}
#endif
#pragma warning disable AS0013
field(2000020; "Domiciliation Journal"; Code[10])
{
Expand All @@ -1190,6 +1206,7 @@ tableextension 242 ObsoleteSourceCodeSetupExt extends "Source Code Setup"
ObsoleteTag = '25.0';
MovedTo = '437dbf0e-84ff-417a-965d-ed2bb9650972';
}
#if not CLEANSCHEMA24
field(5005350; "Phys. Invt. Order"; Code[10])
{
Caption = 'Phys. Invt. Order';
Expand All @@ -1201,6 +1218,7 @@ tableextension 242 ObsoleteSourceCodeSetupExt extends "Source Code Setup"
ObsoleteTag = '24.0';
#pragma warning restore AS0072
}
#endif
field(7000000; "Cartera Journal"; Code[10])
{
Caption = 'Cartera Journal';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if not CLEANSCHEMA27
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
Expand Down Expand Up @@ -183,4 +184,5 @@ tableextension 309 NoSeriesLineObsolete extends "No. Series Line"
end;
#endif

}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if not CLEANSCHEMA27
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
Expand Down Expand Up @@ -149,3 +150,4 @@ table 12146 "No. Series Line Purchase"
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if not CLEANSCHEMA27
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
Expand Down Expand Up @@ -149,3 +150,4 @@ table 12145 "No. Series Line Sales"
}
}
}
#endif
Loading
Loading