Skip to content
Merged
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
5 changes: 3 additions & 2 deletions .build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ resources and classes, then checks if any relevant files have been modified.

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

1. **Early Source Check**: First checks if any files under `source/` have changed
1. **Early Source Check**: First checks if any files under the configured
source path (`-SourcePath`, default `source/`) have changed
- If no source changes, skips integration tests immediately
1. **DSC Resources**: Files under `source/DSCResources/`
1. **Classes**: Files under `source/Classes/`
Expand All @@ -42,7 +43,7 @@ flowchart TD
GetChanges --> HasChanges{Any Changed<br/>Files?}
HasChanges -->|No| RunTrue[Return TRUE<br/>Run integration tests]

HasChanges -->|Yes| CheckSource{Any Changes<br/>Under source/?}
HasChanges -->|Yes| CheckSource{Any Changes<br/>Under SourcePath?}
CheckSource -->|No| Skip[Return FALSE<br/>Skip integration tests]

CheckSource -->|Yes| Discover[Discover Public Commands<br/>Used by DSC Resources]
Expand Down
3 changes: 2 additions & 1 deletion .build/Test-ShouldRunDscResourceIntegrationTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ function Test-ShouldRunDscResourceIntegrationTests
Write-Host ""

# Early optimization: Check if any changes are under the source folder
$changedSourceFiles = $changedFiles | Where-Object -FilterScript { $_ -match '^source/' }
$sourcePrefix = '^' + [regex]::Escape((($SourcePath -replace '\\','/') -replace '/+$','')) + '/'
$changedSourceFiles = $changedFiles | Where-Object -FilterScript { $_ -match $sourcePrefix }
if (-not $changedSourceFiles)
{
Write-Host "No changes detected under the source folder. DSC resource integration tests can be skipped."
Expand Down
14 changes: 14 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# Needed for publishing of examples, build worker defaults to core.autocrlf=input.
* text eol=crlf

# YAML files should use LF (YAML standard)
*.yml text eol=lf
*.yaml text eol=lf

# Markdown files should use LF (cross-platform standard)
*.md text eol=lf

# JSON files should use LF
*.json text eol=lf

# Source control files should use LF
.gitignore text eol=lf
.gitattributes text eol=lf

# Ensure any exe files are treated as binary
*.exe binary
*.jpg binary
Expand Down
146 changes: 73 additions & 73 deletions .github/workflows/code-analysis-built-module.yml
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
name: Code analysis (built module)
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
# cSpell: ignore codeql SARIF
jobs:
pssa:
name: PSScriptAnalyzer
runs-on: windows-latest
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
#actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Install GitVersion
shell: powershell
run: |
dotnet tool install --global GitVersion.Tool --version 5.*
dotnet-gitversion
- name: Run GitVersion
shell: powershell
run: |
dotnet-gitversion | ConvertFrom-Json
- name: Resolve dependencies
shell: powershell
run: |
Write-Information -MessageData 'Resolving dependencies.' -InformationAction 'Continue'
.\build.ps1 -ResolveDependency -Tasks 'noop'
- name: Build Module
shell: powershell
run: |
Write-Information -MessageData 'Module is being built.' -InformationAction 'Continue'
.\build.ps1 -Tasks 'build'
- name: Run PSScriptAnalyzer
shell: powershell
run: |
Write-Information -MessageData 'Prepare the test pipeline.' -InformationAction 'Continue'
.\build.ps1 -Tasks 'noop'
Write-Information -MessageData 'Load SMO stubs into session.' -InformationAction 'Continue'
Add-Type -Path './tests/Unit/Stubs/SMO.cs'
Write-Information -MessageData 'Import module ConvertToSARIF into the session.' -InformationAction 'Continue'
Import-Module -Name 'ConvertToSARIF' -Force
Write-Information -MessageData 'Import module PSScriptAnalyzer into the session.' -InformationAction 'Continue'
Import-Module -Name 'PSScriptAnalyzer' -Force
$filesToScan = Get-ChildItem -Path './output/builtModule/SqlServerDsc/**/SqlServerDsc.psm1' -File
Write-Information -MessageData ("Will scan the file:`t{0}." -f $filesToScan.FullName) -InformationAction 'Continue'
Write-Information -MessageData 'Running PSScriptAnalyzer on built module.' -InformationAction 'Continue'
$pssaError = $filesToScan |
Invoke-ScriptAnalyzer -Settings './.vscode/analyzersettings.psd1'
Write-Information -MessageData 'Converting PSScriptAnalyzer result to SARIF.' -InformationAction 'Continue'
$pssaError |
ConvertTo-SARIF -FilePath 'results.sarif'
Write-Information -MessageData 'Analyzing done.' -InformationAction 'Continue'
- name: Upload SARIF results
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif
name: Code analysis (built module)

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

# cSpell: ignore codeql SARIF
jobs:
pssa:
name: PSScriptAnalyzer
runs-on: windows-latest
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
#actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Install GitVersion
shell: powershell
run: |
dotnet tool install --global GitVersion.Tool --version 5.*
dotnet-gitversion
- name: Run GitVersion
shell: powershell
run: |
dotnet-gitversion | ConvertFrom-Json
- name: Resolve dependencies
shell: powershell
run: |
Write-Information -MessageData 'Resolving dependencies.' -InformationAction 'Continue'
.\build.ps1 -ResolveDependency -Tasks 'noop'
- name: Build Module
shell: powershell
run: |
Write-Information -MessageData 'Module is being built.' -InformationAction 'Continue'
.\build.ps1 -Tasks 'build'
- name: Run PSScriptAnalyzer
shell: powershell
run: |
Write-Information -MessageData 'Prepare the test pipeline.' -InformationAction 'Continue'
.\build.ps1 -Tasks 'noop'

Write-Information -MessageData 'Load SMO stubs into session.' -InformationAction 'Continue'
Add-Type -Path './tests/Unit/Stubs/SMO.cs'

Write-Information -MessageData 'Import module ConvertToSARIF into the session.' -InformationAction 'Continue'
Import-Module -Name 'ConvertToSARIF' -Force

Write-Information -MessageData 'Import module PSScriptAnalyzer into the session.' -InformationAction 'Continue'
Import-Module -Name 'PSScriptAnalyzer' -Force

$filesToScan = Get-ChildItem -Path './output/builtModule/SqlServerDsc/**/SqlServerDsc.psm1' -File
Write-Information -MessageData ("Will scan the file:`t{0}." -f $filesToScan.FullName) -InformationAction 'Continue'

Write-Information -MessageData 'Running PSScriptAnalyzer on built module.' -InformationAction 'Continue'
$pssaError = $filesToScan |
Invoke-ScriptAnalyzer -Settings './.vscode/analyzersettings.psd1'

Write-Information -MessageData 'Converting PSScriptAnalyzer result to SARIF.' -InformationAction 'Continue'
$pssaError |
ConvertTo-SARIF -FilePath 'results.sarif'

Write-Information -MessageData 'Analyzing done.' -InformationAction 'Continue'
- name: Upload SARIF results
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif
166 changes: 83 additions & 83 deletions .github/workflows/code-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
name: Code analysis (source)
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
# cSpell: ignore codeql SARIF
jobs:
pssa:
name: PSScriptAnalyzer
runs-on: windows-latest
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
#actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Install GitVersion
shell: powershell
run: |
dotnet tool install --global GitVersion.Tool --version 5.*
dotnet-gitversion
- name: Run GitVersion
shell: powershell
run: |
dotnet-gitversion | ConvertFrom-Json
- name: Resolve dependencies
shell: powershell
run: |
Write-Information -MessageData 'Resolving dependencies.' -InformationAction 'Continue'
.\build.ps1 -ResolveDependency -Tasks 'noop'
- name: Build Module
shell: powershell
run: |
Write-Information -MessageData 'Module is being built.' -InformationAction 'Continue'
.\build.ps1 -Tasks 'build'
- name: Run PSScriptAnalyzer
shell: powershell
run: |
Write-Information -MessageData 'Prepare the test pipeline.' -InformationAction 'Continue'
.\build.ps1 -Tasks 'noop'
Write-Information -MessageData 'Load SMO stubs into session.' -InformationAction 'Continue'
Add-Type -Path './tests/Unit/Stubs/SMO.cs'
Write-Information -MessageData 'Import module ConvertToSARIF into the session.' -InformationAction 'Continue'
Import-Module -Name 'ConvertToSARIF' -Force
Write-Information -MessageData 'Import module PSScriptAnalyzer into the session.' -InformationAction 'Continue'
Import-Module -Name 'PSScriptAnalyzer' -Force
$filesToScan = Get-ChildItem -Path './source/' -Recurse -Include @('*.psm1', '*.ps1') -File
Write-Information -MessageData ("Will scan the files:`n`r`t{0}." -f ($filesToScan.FullName -join "`n`r`t")) -InformationAction 'Continue'
Write-Information -MessageData 'Running PSScriptAnalyzer.' -InformationAction 'Continue'
$pssaError = $filesToScan |
Invoke-ScriptAnalyzer -Settings './.vscode/analyzersettings.psd1'
$parseErrorTypes = @(
'TypeNotFound'
'RequiresModuleInvalid'
)
Write-Information -MessageData ('Filter out reported parse errors that is unable to be resolved in source files: {0}' -f ($parseErrorTypes -join ', ')) -InformationAction 'Continue'
$pssaError = $pssaError |
Where-Object -FilterScript {
$_.RuleName -notin $parseErrorTypes
}
Write-Information -MessageData 'Converting PSScriptAnalyzer result to SARIF.' -InformationAction 'Continue'
$pssaError |
ConvertTo-SARIF -FilePath 'results.sarif'
Write-Information -MessageData 'Analyzing done.' -InformationAction 'Continue'
- name: Upload SARIF results
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif
name: Code analysis (source)

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

# cSpell: ignore codeql SARIF
jobs:
pssa:
name: PSScriptAnalyzer
runs-on: windows-latest
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
#actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Install GitVersion
shell: powershell
run: |
dotnet tool install --global GitVersion.Tool --version 5.*
dotnet-gitversion
- name: Run GitVersion
shell: powershell
run: |
dotnet-gitversion | ConvertFrom-Json
- name: Resolve dependencies
shell: powershell
run: |
Write-Information -MessageData 'Resolving dependencies.' -InformationAction 'Continue'
.\build.ps1 -ResolveDependency -Tasks 'noop'
- name: Build Module
shell: powershell
run: |
Write-Information -MessageData 'Module is being built.' -InformationAction 'Continue'
.\build.ps1 -Tasks 'build'
- name: Run PSScriptAnalyzer
shell: powershell
run: |
Write-Information -MessageData 'Prepare the test pipeline.' -InformationAction 'Continue'
.\build.ps1 -Tasks 'noop'

Write-Information -MessageData 'Load SMO stubs into session.' -InformationAction 'Continue'
Add-Type -Path './tests/Unit/Stubs/SMO.cs'

Write-Information -MessageData 'Import module ConvertToSARIF into the session.' -InformationAction 'Continue'
Import-Module -Name 'ConvertToSARIF' -Force

Write-Information -MessageData 'Import module PSScriptAnalyzer into the session.' -InformationAction 'Continue'
Import-Module -Name 'PSScriptAnalyzer' -Force

$filesToScan = Get-ChildItem -Path './source/' -Recurse -Include @('*.psm1', '*.ps1') -File
Write-Information -MessageData ("Will scan the files:`n`r`t{0}." -f ($filesToScan.FullName -join "`n`r`t")) -InformationAction 'Continue'

Write-Information -MessageData 'Running PSScriptAnalyzer.' -InformationAction 'Continue'
$pssaError = $filesToScan |
Invoke-ScriptAnalyzer -Settings './.vscode/analyzersettings.psd1'

$parseErrorTypes = @(
'TypeNotFound'
'RequiresModuleInvalid'
)
Write-Information -MessageData ('Filter out reported parse errors that is unable to be resolved in source files: {0}' -f ($parseErrorTypes -join ', ')) -InformationAction 'Continue'
$pssaError = $pssaError |
Where-Object -FilterScript {
$_.RuleName -notin $parseErrorTypes
}

Write-Information -MessageData 'Converting PSScriptAnalyzer result to SARIF.' -InformationAction 'Continue'
$pssaError |
ConvertTo-SARIF -FilePath 'results.sarif'

Write-Information -MessageData 'Analyzing done.' -InformationAction 'Continue'
- name: Upload SARIF results
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif
Loading
Loading