diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 42eb7cad8..48ec7dd65 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -1,11 +1,11 @@ # CI Validation -name: CI +name: Linter on: pull_request: - branches: [$default-branch] - + branches: [ main ] + jobs: build: name: Lint JSON & MD files @@ -23,3 +23,7 @@ jobs: VALIDATE_JSON: true VALIDATE_MD: true DEFAULT_BRANCH: ${{ github.base_ref }} + + - name: Checking shebang lines in MacOS and Ubuntu releases. + run: ./images.CI/shebang-linter.ps1 + shell: pwsh diff --git a/images.CI/shebang-linter.ps1 b/images.CI/shebang-linter.ps1 new file mode 100644 index 000000000..a3862f658 --- /dev/null +++ b/images.CI/shebang-linter.ps1 @@ -0,0 +1,43 @@ +$ErrorActionPreference = "Stop" + +function Validate-Scripts { + Param ( + [Parameter(Mandatory=$true)] + [string[]]$Path, + [Parameter(Mandatory=$true)] + [string]$ExpectedShebang + ) + $ScriptWithoutShebangLine = @() + Get-ChildItem $path -Recurse -File -Filter "*.sh" | ForEach-Object { + $relativePath = Resolve-Path $_.FullName -Relative + $shebangLine = Get-Content -Path $_.FullName | Select-Object -First 1 + if ($shebangLine -eq $ExpectedShebang) { + Write-Host "[+] '$relativePath'" + } + else { + Write-Host "[-] '$relativePath'" + $ScriptWithoutShebangLine += $relativePath + } + } + return $ScriptWithoutShebangLine +} + +$PathUbuntu = "./images/linux/scripts" +$PathMacOS = "./images/macos/provision" +$PatternUbuntu = "#!/bin/bash -e" +$PatternMacOS = "#!/bin/bash -e -o pipefail" +$ScriptsWithBrokenShebang = @() +$ScriptsWithBrokenShebang += Validate-Scripts -Path $PathUbuntu -ExpectedShebang $PatternUbuntu +$ScriptsWithBrokenShebang += Validate-Scripts -Path $PathMacOS -ExpectedShebang $PatternMacOS +if ($ScriptsWithBrokenShebang.Length -gt 0) { + Write-Host "`n`n`n##[error] The following scripts have incorrect shebang:" + $ScriptsWithBrokenShebang | ForEach-Object { + Write-Host "##[error] '$_'" + } + 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 { + Write-Host "All scripts have correct shebang." + } +} \ No newline at end of file diff --git a/images/linux/scripts/base/apt.sh b/images/linux/scripts/base/apt.sh index ff1a9271b..1efbb6721 100644 --- a/images/linux/scripts/base/apt.sh +++ b/images/linux/scripts/base/apt.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -e export DEBIAN_FRONTEND=noninteractive apt-get -yq update diff --git a/images/linux/scripts/base/repos.sh b/images/linux/scripts/base/repos.sh index 4ecd2028c..9005d32aa 100644 --- a/images/linux/scripts/base/repos.sh +++ b/images/linux/scripts/base/repos.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -e ################################################################################ ## File: repos.sh ## Desc: Installs official Microsoft package repos for the distribution diff --git a/images/linux/scripts/helpers/etc-environment.sh b/images/linux/scripts/helpers/etc-environment.sh index 24801723e..eba0ecc05 100644 --- a/images/linux/scripts/helpers/etc-environment.sh +++ b/images/linux/scripts/helpers/etc-environment.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -e ################################################################################ ## File: etc-environment.sh ## Desc: Helper functions for source and modify /etc/environment diff --git a/images/linux/scripts/helpers/install.sh b/images/linux/scripts/helpers/install.sh index bb1befe22..e42cd3194 100644 --- a/images/linux/scripts/helpers/install.sh +++ b/images/linux/scripts/helpers/install.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -e ################################################################################ ## File: install.sh ## Desc: Helper functions for installing tools diff --git a/images/linux/scripts/helpers/os.sh b/images/linux/scripts/helpers/os.sh index 9c30c811a..8bec86080 100644 --- a/images/linux/scripts/helpers/os.sh +++ b/images/linux/scripts/helpers/os.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -e ################################################################################ ## File: install-helpers.sh ## Desc: Helper functions for installing tools diff --git a/images/linux/scripts/installers/pipx-packages.sh b/images/linux/scripts/installers/pipx-packages.sh index 07e1427e3..3b625fe41 100644 --- a/images/linux/scripts/installers/pipx-packages.sh +++ b/images/linux/scripts/installers/pipx-packages.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -e ################################################################################ ## File: pipx-packages.sh ## Desc: Install tools via pipx diff --git a/images/macos/provision/bootstrap-provisioner/installNewProvisioner.sh b/images/macos/provision/bootstrap-provisioner/installNewProvisioner.sh index 79a3afdf2..e588c670c 100644 --- a/images/macos/provision/bootstrap-provisioner/installNewProvisioner.sh +++ b/images/macos/provision/bootstrap-provisioner/installNewProvisioner.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -e -o pipefail BOOTSTRAP_PATH="$1" ProvisionerPackageUri="$2" ProvisionerScriptUri="$3"