Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 30 additions & 5 deletions .github/workflows/SubmitStabilityJobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ name: Submit Stability Job On Official Branches
on:
workflow_dispatch:
schedule:
- cron: "0 04 * * *" # Run at 04:00 UTC every day
- cron: "0 0 * * 1" # Run all supported branches at 00:00 UTC on Monday
- cron: "0 0 * * 0,2-6" # Run main and .x branches at 00:00 UTC Tuesday through Sunday

permissions: read-all

Expand All @@ -15,11 +16,26 @@ jobs:
outputs:
officialBranches: ${{ steps.getOfficialBranches.outputs.branchesJson }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Select branch scope
id: branchScope
env:
SCHEDULE: ${{ github.event.schedule }}
shell: bash
run: |
if [[ "$SCHEDULE" == "0 0 * * 0,2-6" ]]; then
echo 'include=["main", "releases/*.x"]' >> "$GITHUB_OUTPUT"
else
echo 'include=["main", "releases/*"]' >> "$GITHUB_OUTPUT"
fi

- name: Get Official Branches
id: getOfficialBranches
uses: microsoft/BCApps/.github/actions/GetGitBranches@main
uses: ./.github/actions/GetGitBranches
with:
include: "['releases/*']"
include: ${{ steps.branchScope.outputs.include }}

SubmitStabilityJobs:
name: "[${{ matrix.branch }}] Submit Stability Job"
Expand All @@ -32,10 +48,19 @@ jobs:
branch: ${{ fromJson(needs.GetBranches.outputs.officialBranches) }}
fail-fast: false
steps:
- uses: actions/create-github-app-token@f418cff399f7aef4c2f0ad47e25ca7a6abbdd6fc # v3.4.0
id: app-token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}

- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Submit Stability Job
env:
GH_TOKEN: ${{ secrets.GHTOKENWORKFLOW }}
uses: microsoft/BCApps/.github/actions/RunAutomation@main
GH_TOKEN: ${{ steps.app-token.outputs.token }}
uses: ./.github/actions/RunAutomation
with:
automations: SubmitStabilityJob
targetBranch: ${{ matrix.branch }}
10 changes: 8 additions & 2 deletions .github/workflows/UpdateALGoOnOfficialBranches.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ jobs:
with:
egress-policy: audit

- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Get Official Branches
id: getOfficialBranches
uses: microsoft/BCApps/.github/actions/GetGitBranches@main
uses: ./.github/actions/GetGitBranches
with:
include: "['main', 'releases/*']"

Expand All @@ -42,10 +45,13 @@ jobs:
with:
egress-policy: audit

- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Update AL-Go System Files
env:
GH_TOKEN: ${{ secrets.GHTOKENWORKFLOW }}
uses: microsoft/BCApps/.github/actions/RunAutomation@main
uses: ./.github/actions/RunAutomation
Comment thread
mazhelez marked this conversation as resolved.
Resolved
with:
automations: UpdateALGo
targetBranch: ${{ matrix.branch }}
30 changes: 23 additions & 7 deletions .github/workflows/UpdateBCArtifactVersion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ jobs:
updateBranches: ${{ steps.getOfficialBranches.outputs.branchesJson }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
with:
egress-policy: audit

- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Get Official Branches
id: getOfficialBranches
uses: microsoft/BCApps/.github/actions/GetGitBranches@main

uses: ./.github/actions/GetGitBranches
with:
include: "['main', 'releases/*']"

Expand All @@ -45,15 +47,29 @@ jobs:
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ matrix.branch }}

- uses: actions/create-github-app-token@f418cff399f7aef4c2f0ad47e25ca7a6abbdd6fc # v3.4.0
id: app-token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}

- name: Checkout actions
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
path: _actions
sparse-checkout: |
.github/actions
build/scripts

- name: Update BC Artifact Version
env:
GH_TOKEN: ${{ secrets.GHTOKENWORKFLOW }}
uses: microsoft/BCApps/.github/actions/RunAutomation@main
GH_TOKEN: ${{ steps.app-token.outputs.token }}
uses: ./_actions/.github/actions/RunAutomation

with:
automations: UpdateBCArtifact
automations: UpdateBCArtifact,UpdatePlatformVersion
targetBranch: ${{ matrix.branch }}
27 changes: 22 additions & 5 deletions .github/workflows/UpdatePackageVersions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ jobs:
updateBranches: ${{ steps.getOfficialBranches.outputs.branchesJson }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0
uses: step-security/harden-runner@aebdcf6156ab6691adf63218240e476564a1ed4c # v2.23.0
with:
egress-policy: audit

- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Get Official Branches
id: getOfficialBranches
uses: microsoft/BCApps/.github/actions/GetGitBranches@main
uses: ./.github/actions/GetGitBranches
with:
include: "['main', 'releases/*']"

Expand All @@ -44,14 +47,28 @@ jobs:
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ matrix.branch }}

- uses: actions/create-github-app-token@f418cff399f7aef4c2f0ad47e25ca7a6abbdd6fc # v3.4.0
id: app-token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}

- name: Checkout actions
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
path: _actions
sparse-checkout: |
.github/actions
build/scripts

- name: Update Package Versions
env:
GH_TOKEN: ${{ secrets.GHTOKENWORKFLOW }}
uses: microsoft/BCApps/.github/actions/RunAutomation@main
GH_TOKEN: ${{ steps.app-token.outputs.token }}
uses: ./_actions/.github/actions/RunAutomation
with:
automations: UpdateAppBaselines,UpdateAppTranslations
targetBranch: ${{ matrix.branch }}
2 changes: 1 addition & 1 deletion .github/workflows/VerifyAppChanges.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
with:
ref: ${{ github.sha }}

- uses: microsoft/BCApps/.github/actions/TestPreprocessorSymbols@main
- uses: ./.github/actions/TestPreprocessorSymbols
17 changes: 10 additions & 7 deletions build/scripts/TestPreprocessorSymbols.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
This script checks the preprocessor symbols in an AL file.

.DESCRIPTION
Uses the native text reader to select lines containing '#', retaining original
line numbers. All '#' lines, including inline occurrences, use the same checks.
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.
Expand Down Expand Up @@ -46,6 +48,11 @@ function Test-PreprocessorSymbols {
return $null
}

$matchingLines = Select-String -LiteralPath $filePath -Pattern '#' -SimpleMatch -ErrorAction Stop
if ($null -eq $matchingLines) {
return $null
}

# Define the regex pattern for disallowing a space after #
$noSpaceAfterHashPattern = "^#\s"
$lowercasePattern = "^#(if|elseif|else\b|endif)"
Expand All @@ -70,18 +77,14 @@ function Test-PreprocessorSymbols {
$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
foreach ($match in $matchingLines) {
$line = $match.Line
$lineNumber = $match.LineNumber

# Check for space after #
if ($line -cmatch $noSpaceAfterHashPattern) {
Expand Down
57 changes: 41 additions & 16 deletions build/scripts/tests/TestPreprocessorSymbols.Test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,39 @@ Describe "Test-PreprocessorSymbols" {
Import-Module "$PSScriptRoot\..\..\..\build\scripts\TestPreprocessorSymbols.psm1" -Force
}

It 'preserves line numbers and inline stem checks when skipping ordinary lines' {
$path = Join-Path $TestDrive 'inline[1].al'
$lines = @('codeunit 123 Example', '{', '', '// #if clean2', '#IF CLEAN1', '}')
Set-Content -LiteralPath $path -Value ($lines -join "`r`n") -NoNewline

$result = Test-PreprocessorSymbols -filePath $path -symbolConfigs @(@{stem = 'CLEAN'; lowerBound = 1; upperBound = 5})

$result.invalidStemSymbols | Should -Be @("${path}:4: // #if clean2")
$result.invalidLowercaseSymbols | Should -Be @("${path}:5: #IF CLEAN1")
$result.invalidPatternSymbols.Count | Should -Be 0
}

It 'checks a single directive without a trailing newline' {
$path = Join-Path $TestDrive 'single.al'
Set-Content -LiteralPath $path -Value '#IF CLEAN1' -NoNewline

$result = Test-PreprocessorSymbols -filePath $path -symbolConfigs @(@{stem = 'CLEAN'; lowerBound = 1; upperBound = 5})

$result.invalidLowercaseSymbols | Should -Be @("${path}:1: #IF CLEAN1")
}

It 'accepts empty files and files without hashes' {
$path = Join-Path $TestDrive 'ordinary.al'
foreach ($content in @('', "codeunit 123 Example`n{`n}")) {
Set-Content -LiteralPath $path -Value $content -NoNewline
Test-PreprocessorSymbols -filePath $path -symbolConfigs @(@{stem = 'CLEAN'; lowerBound = 1; upperBound = 5}) | Should -BeNullOrEmpty
}
}

It 'surfaces file read errors' {
{ Test-PreprocessorSymbols -filePath (Join-Path $TestDrive 'missing.al') -symbolConfigs @(@{stem = 'CLEAN'; lowerBound = 1; upperBound = 5}) } | Should -Throw
}

It 'returns $null when the filepath extension is not .al' {
$result = Test-PreprocessorSymbols -filePath 'Dummy.txt' -symbolConfigs @(@{'stem' = "CLEAN"; 'lowerBound' = 1; 'upperBound' = 1})
$result | Should -Be $null
Expand All @@ -26,8 +59,7 @@ Describe "Test-PreprocessorSymbols" {
#elseif CLEAN5
#endif
}')
Set-Content -Path TestDrive:\Dummy.al -Value $alcontent
Mock -CommandName Get-Content { return Get-Content TestDrive:\dummy.al}
Set-Content -Path TestDrive:\dummy.al -Value $alcontent

$result = Test-PreprocessorSymbols -filePath 'TestDrive:\dummy.al' -symbolConfigs @(@{'stem' = "CLEAN"; 'lowerBound' = 1; 'upperBound' = 5})

Expand All @@ -48,8 +80,7 @@ Describe "Test-PreprocessorSymbols" {
#else
#endif
}')
Set-Content -Path TestDrive:\Dummy.al -Value $alcontent
Mock -CommandName Get-Content { return Get-Content TestDrive:\dummy.al}
Set-Content -Path TestDrive:\dummy.al -Value $alcontent

$symbolConfigs = @(
@{stem="CLEAN"; lowerBound=1; upperBound=3},
Expand Down Expand Up @@ -86,8 +117,7 @@ Describe "Test-PreprocessorSymbols" {
#Else
#EndIf
}')
Set-Content -Path TestDrive:\Dummy.al -Value $alcontent
Mock -CommandName Get-Content { return Get-Content TestDrive:\dummy.al}
Set-Content -Path TestDrive:\dummy.al -Value $alcontent

$result = Test-PreprocessorSymbols -filePath 'TestDrive:\dummy.al' -symbolConfigs @(@{'stem' = "CLEAN"; 'lowerBound' = 1; 'upperBound' = 7})

Expand Down Expand Up @@ -128,8 +158,7 @@ Describe "Test-PreprocessorSymbols" {
#if CLEAN7
#endif
}')
Set-Content -Path TestDrive:\Dummy.al -Value $alcontent
Mock -CommandName Get-Content { return Get-Content TestDrive:\dummy.al}
Set-Content -Path TestDrive:\dummy.al -Value $alcontent

$result = Test-PreprocessorSymbols -filePath 'TestDrive:\dummy.al' -symbolConfigs @(@{'stem' = "CLEAN"; 'lowerBound' = 1; 'upperBound' = 7})

Expand Down Expand Up @@ -174,8 +203,7 @@ Describe "Test-PreprocessorSymbols" {
#endif

}')
Set-Content -Path TestDrive:\Dummy.al -Value $alcontent
Mock -CommandName Get-Content { return Get-Content TestDrive:\dummy.al}
Set-Content -Path TestDrive:\dummy.al -Value $alcontent

$result = Test-PreprocessorSymbols -filePath 'TestDrive:\dummy.al' -symbolConfigs @(@{'stem' = "CLEAN"; 'lowerBound' = 5; 'upperBound' = 11})

Expand Down Expand Up @@ -215,8 +243,7 @@ Describe "Test-PreprocessorSymbols" {
#if not RELEASE12
#endif
}')
Set-Content -Path TestDrive:\Dummy.al -Value $alcontent
Mock -CommandName Get-Content { return Get-Content TestDrive:\dummy.al}
Set-Content -Path TestDrive:\dummy.al -Value $alcontent

$result = Test-PreprocessorSymbols -filePath 'TestDrive:\dummy.al' -symbolConfigs @(@{'stem' = "CLEAN"; 'lowerBound' = 5; 'upperBound' = 11})

Expand Down Expand Up @@ -248,8 +275,7 @@ Describe "Test-PreprocessorSymbols" {
#elseif CleaN5
#endif
}')
Set-Content -Path TestDrive:\Dummy.al -Value $alcontent
Mock -CommandName Get-Content { return Get-Content TestDrive:\dummy.al}
Set-Content -Path TestDrive:\dummy.al -Value $alcontent

$result = Test-PreprocessorSymbols -filePath 'TestDrive:\dummy.al' -symbolConfigs @(@{'stem' = "CLEAN"; 'lowerBound' = 1; 'upperBound' = 5})

Expand Down Expand Up @@ -282,8 +308,7 @@ Describe "Test-PreprocessorSymbols" {
#elseif CLEANSCHEMA34
#endif
}')
Set-Content -Path TestDrive:\Dummy.al -Value $alcontent
Mock -CommandName Get-Content { return Get-Content TestDrive:\dummy.al}
Set-Content -Path TestDrive:\dummy.al -Value $alcontent

$symbolConfigs = @(
@{stem = "CLEAN"; lowerBound = 22; upperBound = 26},
Expand Down
Loading