Skip to content

Commit 45157ae

Browse files
authored
Enhance performance of DSC resource integration tests (#2143)
1 parent 72c7898 commit 45157ae

File tree

7 files changed

+463
-427
lines changed

7 files changed

+463
-427
lines changed

.build/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ resources and classes, then checks if any relevant files have been modified.
1818

1919
The script performs an optimized analysis by checking for changes in this order:
2020

21-
1. **Early Source Check**: First checks if any files under `source/` have changed
21+
1. **Early Source Check**: First checks if any files under the configured
22+
source path (`-SourcePath`, default `source/`) have changed
2223
- If no source changes, skips integration tests immediately
2324
1. **DSC Resources**: Files under `source/DSCResources/`
2425
1. **Classes**: Files under `source/Classes/`
@@ -42,7 +43,7 @@ flowchart TD
4243
GetChanges --> HasChanges{Any Changed<br/>Files?}
4344
HasChanges -->|No| RunTrue[Return TRUE<br/>Run integration tests]
4445
45-
HasChanges -->|Yes| CheckSource{Any Changes<br/>Under source/?}
46+
HasChanges -->|Yes| CheckSource{Any Changes<br/>Under SourcePath?}
4647
CheckSource -->|No| Skip[Return FALSE<br/>Skip integration tests]
4748
4849
CheckSource -->|Yes| Discover[Discover Public Commands<br/>Used by DSC Resources]

.build/Test-ShouldRunDscResourceIntegrationTests.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,8 @@ function Test-ShouldRunDscResourceIntegrationTests
460460
Write-Host ""
461461

462462
# Early optimization: Check if any changes are under the source folder
463-
$changedSourceFiles = $changedFiles | Where-Object -FilterScript { $_ -match '^source/' }
463+
$sourcePrefix = '^' + [regex]::Escape((($SourcePath -replace '\\','/') -replace '/+$','')) + '/'
464+
$changedSourceFiles = $changedFiles | Where-Object -FilterScript { $_ -match $sourcePrefix }
464465
if (-not $changedSourceFiles)
465466
{
466467
Write-Host "No changes detected under the source folder. DSC resource integration tests can be skipped."

.gitattributes

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
# Needed for publishing of examples, build worker defaults to core.autocrlf=input.
22
* text eol=crlf
33

4+
# YAML files should use LF (YAML standard)
5+
*.yml text eol=lf
6+
*.yaml text eol=lf
7+
8+
# Markdown files should use LF (cross-platform standard)
9+
*.md text eol=lf
10+
11+
# JSON files should use LF
12+
*.json text eol=lf
13+
14+
# Source control files should use LF
15+
.gitignore text eol=lf
16+
.gitattributes text eol=lf
17+
418
# Ensure any exe files are treated as binary
519
*.exe binary
620
*.jpg binary
Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,73 @@
1-
name: Code analysis (built module)
2-
3-
on:
4-
push:
5-
branches: [ main ]
6-
pull_request:
7-
branches: [ main ]
8-
workflow_dispatch:
9-
10-
# cSpell: ignore codeql SARIF
11-
jobs:
12-
pssa:
13-
name: PSScriptAnalyzer
14-
runs-on: windows-latest
15-
permissions:
16-
contents: read # for actions/checkout to fetch code
17-
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
18-
#actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
19-
steps:
20-
- name: Checkout code
21-
uses: actions/checkout@v5
22-
with:
23-
fetch-depth: 0
24-
- name: Install GitVersion
25-
shell: powershell
26-
run: |
27-
dotnet tool install --global GitVersion.Tool --version 5.*
28-
dotnet-gitversion
29-
- name: Run GitVersion
30-
shell: powershell
31-
run: |
32-
dotnet-gitversion | ConvertFrom-Json
33-
- name: Resolve dependencies
34-
shell: powershell
35-
run: |
36-
Write-Information -MessageData 'Resolving dependencies.' -InformationAction 'Continue'
37-
.\build.ps1 -ResolveDependency -Tasks 'noop'
38-
- name: Build Module
39-
shell: powershell
40-
run: |
41-
Write-Information -MessageData 'Module is being built.' -InformationAction 'Continue'
42-
.\build.ps1 -Tasks 'build'
43-
- name: Run PSScriptAnalyzer
44-
shell: powershell
45-
run: |
46-
Write-Information -MessageData 'Prepare the test pipeline.' -InformationAction 'Continue'
47-
.\build.ps1 -Tasks 'noop'
48-
49-
Write-Information -MessageData 'Load SMO stubs into session.' -InformationAction 'Continue'
50-
Add-Type -Path './tests/Unit/Stubs/SMO.cs'
51-
52-
Write-Information -MessageData 'Import module ConvertToSARIF into the session.' -InformationAction 'Continue'
53-
Import-Module -Name 'ConvertToSARIF' -Force
54-
55-
Write-Information -MessageData 'Import module PSScriptAnalyzer into the session.' -InformationAction 'Continue'
56-
Import-Module -Name 'PSScriptAnalyzer' -Force
57-
58-
$filesToScan = Get-ChildItem -Path './output/builtModule/SqlServerDsc/**/SqlServerDsc.psm1' -File
59-
Write-Information -MessageData ("Will scan the file:`t{0}." -f $filesToScan.FullName) -InformationAction 'Continue'
60-
61-
Write-Information -MessageData 'Running PSScriptAnalyzer on built module.' -InformationAction 'Continue'
62-
$pssaError = $filesToScan |
63-
Invoke-ScriptAnalyzer -Settings './.vscode/analyzersettings.psd1'
64-
65-
Write-Information -MessageData 'Converting PSScriptAnalyzer result to SARIF.' -InformationAction 'Continue'
66-
$pssaError |
67-
ConvertTo-SARIF -FilePath 'results.sarif'
68-
69-
Write-Information -MessageData 'Analyzing done.' -InformationAction 'Continue'
70-
- name: Upload SARIF results
71-
uses: github/codeql-action/upload-sarif@v3
72-
with:
73-
sarif_file: results.sarif
1+
name: Code analysis (built module)
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
# cSpell: ignore codeql SARIF
11+
jobs:
12+
pssa:
13+
name: PSScriptAnalyzer
14+
runs-on: windows-latest
15+
permissions:
16+
contents: read # for actions/checkout to fetch code
17+
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
18+
#actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v5
22+
with:
23+
fetch-depth: 0
24+
- name: Install GitVersion
25+
shell: powershell
26+
run: |
27+
dotnet tool install --global GitVersion.Tool --version 5.*
28+
dotnet-gitversion
29+
- name: Run GitVersion
30+
shell: powershell
31+
run: |
32+
dotnet-gitversion | ConvertFrom-Json
33+
- name: Resolve dependencies
34+
shell: powershell
35+
run: |
36+
Write-Information -MessageData 'Resolving dependencies.' -InformationAction 'Continue'
37+
.\build.ps1 -ResolveDependency -Tasks 'noop'
38+
- name: Build Module
39+
shell: powershell
40+
run: |
41+
Write-Information -MessageData 'Module is being built.' -InformationAction 'Continue'
42+
.\build.ps1 -Tasks 'build'
43+
- name: Run PSScriptAnalyzer
44+
shell: powershell
45+
run: |
46+
Write-Information -MessageData 'Prepare the test pipeline.' -InformationAction 'Continue'
47+
.\build.ps1 -Tasks 'noop'
48+
49+
Write-Information -MessageData 'Load SMO stubs into session.' -InformationAction 'Continue'
50+
Add-Type -Path './tests/Unit/Stubs/SMO.cs'
51+
52+
Write-Information -MessageData 'Import module ConvertToSARIF into the session.' -InformationAction 'Continue'
53+
Import-Module -Name 'ConvertToSARIF' -Force
54+
55+
Write-Information -MessageData 'Import module PSScriptAnalyzer into the session.' -InformationAction 'Continue'
56+
Import-Module -Name 'PSScriptAnalyzer' -Force
57+
58+
$filesToScan = Get-ChildItem -Path './output/builtModule/SqlServerDsc/**/SqlServerDsc.psm1' -File
59+
Write-Information -MessageData ("Will scan the file:`t{0}." -f $filesToScan.FullName) -InformationAction 'Continue'
60+
61+
Write-Information -MessageData 'Running PSScriptAnalyzer on built module.' -InformationAction 'Continue'
62+
$pssaError = $filesToScan |
63+
Invoke-ScriptAnalyzer -Settings './.vscode/analyzersettings.psd1'
64+
65+
Write-Information -MessageData 'Converting PSScriptAnalyzer result to SARIF.' -InformationAction 'Continue'
66+
$pssaError |
67+
ConvertTo-SARIF -FilePath 'results.sarif'
68+
69+
Write-Information -MessageData 'Analyzing done.' -InformationAction 'Continue'
70+
- name: Upload SARIF results
71+
uses: github/codeql-action/upload-sarif@v3
72+
with:
73+
sarif_file: results.sarif
Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,83 @@
1-
name: Code analysis (source)
2-
3-
on:
4-
push:
5-
branches: [ main ]
6-
pull_request:
7-
branches: [ main ]
8-
workflow_dispatch:
9-
10-
# cSpell: ignore codeql SARIF
11-
jobs:
12-
pssa:
13-
name: PSScriptAnalyzer
14-
runs-on: windows-latest
15-
permissions:
16-
contents: read # for actions/checkout to fetch code
17-
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
18-
#actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
19-
steps:
20-
- name: Checkout code
21-
uses: actions/checkout@v5
22-
with:
23-
fetch-depth: 0
24-
- name: Install GitVersion
25-
shell: powershell
26-
run: |
27-
dotnet tool install --global GitVersion.Tool --version 5.*
28-
dotnet-gitversion
29-
- name: Run GitVersion
30-
shell: powershell
31-
run: |
32-
dotnet-gitversion | ConvertFrom-Json
33-
- name: Resolve dependencies
34-
shell: powershell
35-
run: |
36-
Write-Information -MessageData 'Resolving dependencies.' -InformationAction 'Continue'
37-
.\build.ps1 -ResolveDependency -Tasks 'noop'
38-
- name: Build Module
39-
shell: powershell
40-
run: |
41-
Write-Information -MessageData 'Module is being built.' -InformationAction 'Continue'
42-
.\build.ps1 -Tasks 'build'
43-
- name: Run PSScriptAnalyzer
44-
shell: powershell
45-
run: |
46-
Write-Information -MessageData 'Prepare the test pipeline.' -InformationAction 'Continue'
47-
.\build.ps1 -Tasks 'noop'
48-
49-
Write-Information -MessageData 'Load SMO stubs into session.' -InformationAction 'Continue'
50-
Add-Type -Path './tests/Unit/Stubs/SMO.cs'
51-
52-
Write-Information -MessageData 'Import module ConvertToSARIF into the session.' -InformationAction 'Continue'
53-
Import-Module -Name 'ConvertToSARIF' -Force
54-
55-
Write-Information -MessageData 'Import module PSScriptAnalyzer into the session.' -InformationAction 'Continue'
56-
Import-Module -Name 'PSScriptAnalyzer' -Force
57-
58-
$filesToScan = Get-ChildItem -Path './source/' -Recurse -Include @('*.psm1', '*.ps1') -File
59-
Write-Information -MessageData ("Will scan the files:`n`r`t{0}." -f ($filesToScan.FullName -join "`n`r`t")) -InformationAction 'Continue'
60-
61-
Write-Information -MessageData 'Running PSScriptAnalyzer.' -InformationAction 'Continue'
62-
$pssaError = $filesToScan |
63-
Invoke-ScriptAnalyzer -Settings './.vscode/analyzersettings.psd1'
64-
65-
$parseErrorTypes = @(
66-
'TypeNotFound'
67-
'RequiresModuleInvalid'
68-
)
69-
Write-Information -MessageData ('Filter out reported parse errors that is unable to be resolved in source files: {0}' -f ($parseErrorTypes -join ', ')) -InformationAction 'Continue'
70-
$pssaError = $pssaError |
71-
Where-Object -FilterScript {
72-
$_.RuleName -notin $parseErrorTypes
73-
}
74-
75-
Write-Information -MessageData 'Converting PSScriptAnalyzer result to SARIF.' -InformationAction 'Continue'
76-
$pssaError |
77-
ConvertTo-SARIF -FilePath 'results.sarif'
78-
79-
Write-Information -MessageData 'Analyzing done.' -InformationAction 'Continue'
80-
- name: Upload SARIF results
81-
uses: github/codeql-action/upload-sarif@v3
82-
with:
83-
sarif_file: results.sarif
1+
name: Code analysis (source)
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
workflow_dispatch:
9+
10+
# cSpell: ignore codeql SARIF
11+
jobs:
12+
pssa:
13+
name: PSScriptAnalyzer
14+
runs-on: windows-latest
15+
permissions:
16+
contents: read # for actions/checkout to fetch code
17+
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
18+
#actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v5
22+
with:
23+
fetch-depth: 0
24+
- name: Install GitVersion
25+
shell: powershell
26+
run: |
27+
dotnet tool install --global GitVersion.Tool --version 5.*
28+
dotnet-gitversion
29+
- name: Run GitVersion
30+
shell: powershell
31+
run: |
32+
dotnet-gitversion | ConvertFrom-Json
33+
- name: Resolve dependencies
34+
shell: powershell
35+
run: |
36+
Write-Information -MessageData 'Resolving dependencies.' -InformationAction 'Continue'
37+
.\build.ps1 -ResolveDependency -Tasks 'noop'
38+
- name: Build Module
39+
shell: powershell
40+
run: |
41+
Write-Information -MessageData 'Module is being built.' -InformationAction 'Continue'
42+
.\build.ps1 -Tasks 'build'
43+
- name: Run PSScriptAnalyzer
44+
shell: powershell
45+
run: |
46+
Write-Information -MessageData 'Prepare the test pipeline.' -InformationAction 'Continue'
47+
.\build.ps1 -Tasks 'noop'
48+
49+
Write-Information -MessageData 'Load SMO stubs into session.' -InformationAction 'Continue'
50+
Add-Type -Path './tests/Unit/Stubs/SMO.cs'
51+
52+
Write-Information -MessageData 'Import module ConvertToSARIF into the session.' -InformationAction 'Continue'
53+
Import-Module -Name 'ConvertToSARIF' -Force
54+
55+
Write-Information -MessageData 'Import module PSScriptAnalyzer into the session.' -InformationAction 'Continue'
56+
Import-Module -Name 'PSScriptAnalyzer' -Force
57+
58+
$filesToScan = Get-ChildItem -Path './source/' -Recurse -Include @('*.psm1', '*.ps1') -File
59+
Write-Information -MessageData ("Will scan the files:`n`r`t{0}." -f ($filesToScan.FullName -join "`n`r`t")) -InformationAction 'Continue'
60+
61+
Write-Information -MessageData 'Running PSScriptAnalyzer.' -InformationAction 'Continue'
62+
$pssaError = $filesToScan |
63+
Invoke-ScriptAnalyzer -Settings './.vscode/analyzersettings.psd1'
64+
65+
$parseErrorTypes = @(
66+
'TypeNotFound'
67+
'RequiresModuleInvalid'
68+
)
69+
Write-Information -MessageData ('Filter out reported parse errors that is unable to be resolved in source files: {0}' -f ($parseErrorTypes -join ', ')) -InformationAction 'Continue'
70+
$pssaError = $pssaError |
71+
Where-Object -FilterScript {
72+
$_.RuleName -notin $parseErrorTypes
73+
}
74+
75+
Write-Information -MessageData 'Converting PSScriptAnalyzer result to SARIF.' -InformationAction 'Continue'
76+
$pssaError |
77+
ConvertTo-SARIF -FilePath 'results.sarif'
78+
79+
Write-Information -MessageData 'Analyzing done.' -InformationAction 'Continue'
80+
- name: Upload SARIF results
81+
uses: github/codeql-action/upload-sarif@v3
82+
with:
83+
sarif_file: results.sarif

0 commit comments

Comments
 (0)