From 955aec5bef2a3bddc1fcf1a300463672a874e88b Mon Sep 17 00:00:00 2001 From: Darii Nurgaleev Date: Tue, 13 Oct 2020 21:32:58 +0700 Subject: [PATCH] added new linter --- images.CI/shebang-linter.ps1 | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/images.CI/shebang-linter.ps1 b/images.CI/shebang-linter.ps1 index 26248e269..34f952001 100644 --- a/images.CI/shebang-linter.ps1 +++ b/images.CI/shebang-linter.ps1 @@ -9,17 +9,16 @@ function Validate-Scripts { ) $ScriptWithoutShebangLine = @() Get-ChildItem $path -Recurse -File -Filter "*.sh" | ForEach-Object { - $shebangLine = Get-Content -Path $($_.FullName)| Select-Object -First 1 + $relativePath = Resolve-Path $_.FullName -Relative + $shebangLine = Get-Content -Path $.FullName | Select-Object -First 1 if ($shebangLine -eq $ExpectedShebang) { - Write-Host "[+] '$($_.FullName)'" + Write-Host "[+] '$relativePath'" } else { - Write-Host "[-] '$($_.FullName)'" - $ScriptWithoutShebangLine += $($_.FullName) + Write-Host "[-] 'relativePath'" + $ScriptWithoutShebangLine += $relativePath } } - return $ScriptWithoutShebangLine -} $PathUbuntu = "./images/linux/scripts" $PathMacOS = "./images/macos/provision" @@ -29,11 +28,11 @@ $ScriptsWithBrokenShebang = @() $ScriptsWithBrokenShebang += Validate-Scripts -Path $PathUbuntu -ExpectedShebang $PatternUbuntu $ScriptsWithBrokenShebang += Validate-Scripts -Path $PathMacOS -ExpectedShebang $PatternMacOS if ($ScriptsWithBrokenShebang.Length -gt 0) { - Write-Host "The following scripts have incorrect shebang:" + Write-Host "`n`n`n##[error] The following scripts have incorrect shebang:" $ScriptsWithBrokenShebang | ForEach-Object { - Write-Host "##[error] - '$_'" + Write-Host "##[error] '$_'" } - Write-Host "##[error] Expected shebang for scripts in 'images/linux' folder is '$PatternUbuntu'" + Write-Host "`n`n##[error] Expected shebang for scripts in 'images/linux' folder is '$PatternUbuntu'" Write-Host "##[error] Expected shebang for scripts in 'images/macos' folder is '$PatternMacOS'" exit 1 else {