mirror of
https://github.com/actions/runner-images.git
synced 2025-12-12 20:26:49 +00:00
added linter for ubuntu
This commit is contained in:
34
images.CI/linux-and-win/lint_ubuntu.ps1
Normal file
34
images.CI/linux-and-win/lint_ubuntu.ps1
Normal file
@@ -0,0 +1,34 @@
|
||||
param(
|
||||
[Parameter(Mandatory)] [string] $path,
|
||||
[Parameter(Mandatory)] [string] $pattern
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Validate-Scripts {
|
||||
Param (
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string[]]$Path,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]$Pattern
|
||||
)
|
||||
$WrongScript = New-Object System.Collections.Generic.List[System.Object]
|
||||
Get-ChildItem $path | ForEach-Object {
|
||||
if (Select-String -Path $($_.FullName) -Pattern $Pattern -Quiet) {
|
||||
Write-Host "Pattern '$pattern' found in '$($_.FullName)'"
|
||||
}
|
||||
else {
|
||||
Write-Host "Pattern '$pattern' not found in '$($_.FullName)'"
|
||||
$WrongScript += $($_.FullName)
|
||||
}
|
||||
}
|
||||
return $WrongScript
|
||||
}
|
||||
|
||||
$FailedScripts = Validate-Scripts -Path $path -Pattern "#/bin/bash -e"
|
||||
if ($FailedScripts.Length -gt 0) {
|
||||
$FailedScripts | ForEach-Object {
|
||||
Write-Warning "The following script does not contain shebang: '$_'"
|
||||
}
|
||||
exit 1
|
||||
}
|
||||
Reference in New Issue
Block a user