diff --git a/images.CI/lint-shebang.ps1 b/images.CI/lint-shebang.ps1 new file mode 100644 index 000000000..6a2789f53 --- /dev/null +++ b/images.CI/lint-shebang.ps1 @@ -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 + ) + $ScriptsWithBrokenShebang = @() + Get-ChildItem $path | ForEach-Object { + if (Get-Content -Path $($_.FullName) | Select-Object -First 1 | Select-String -Pattern $Pattern -Quiet) { + Write-Host "Pattern '$Pattern' found in '$($_.FullName)'" + } + else { + Write-Host "Pattern '$Pattern' not found in '$($_.FullName)'" + $ScriptsWithBrokenShebang += $($_.FullName) + } + } + return $ScriptsWithBrokenShebang +} + +$ScriptsWithBrokenShebang = Validate-Scripts -Path $path -Pattern "#!/bin/bash -e" +if ($ScriptsWithBrokenShebang.Length -gt 0) { + $ScriptsWithBrokenShebang | ForEach-Object { + Write-Warning "The following script does not contain shebang: '$_'" + } + exit 1 +} \ No newline at end of file diff --git a/images.CI/linux-and-win/lint_ubuntu.ps1 b/images.CI/linux-and-win/lint_ubuntu.ps1 deleted file mode 100644 index 7adcf70b9..000000000 --- a/images.CI/linux-and-win/lint_ubuntu.ps1 +++ /dev/null @@ -1,34 +0,0 @@ -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 -} \ No newline at end of file