mirror of
https://github.com/actions/runner-images.git
synced 2025-12-17 15:20:11 +00:00
Merge pull request #1795 from Darleev/v-danurg/lint_shebang_ubuntu
Shebang lint for Ubuntu/MacOS
This commit is contained in:
8
.github/workflows/linter.yml
vendored
8
.github/workflows/linter.yml
vendored
@@ -1,10 +1,10 @@
|
|||||||
# CI Validation
|
# CI Validation
|
||||||
|
|
||||||
name: CI
|
name: Linter
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [$default-branch]
|
branches: [ main ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -23,3 +23,7 @@ jobs:
|
|||||||
VALIDATE_JSON: true
|
VALIDATE_JSON: true
|
||||||
VALIDATE_MD: true
|
VALIDATE_MD: true
|
||||||
DEFAULT_BRANCH: ${{ github.base_ref }}
|
DEFAULT_BRANCH: ${{ github.base_ref }}
|
||||||
|
|
||||||
|
- name: Checking shebang lines in MacOS and Ubuntu releases.
|
||||||
|
run: ./images.CI/shebang-linter.ps1
|
||||||
|
shell: pwsh
|
||||||
|
|||||||
43
images.CI/shebang-linter.ps1
Normal file
43
images.CI/shebang-linter.ps1
Normal file
@@ -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."
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash -e
|
||||||
|
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
apt-get -yq update
|
apt-get -yq update
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash -e
|
||||||
################################################################################
|
################################################################################
|
||||||
## File: repos.sh
|
## File: repos.sh
|
||||||
## Desc: Installs official Microsoft package repos for the distribution
|
## Desc: Installs official Microsoft package repos for the distribution
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash -e
|
||||||
################################################################################
|
################################################################################
|
||||||
## File: etc-environment.sh
|
## File: etc-environment.sh
|
||||||
## Desc: Helper functions for source and modify /etc/environment
|
## Desc: Helper functions for source and modify /etc/environment
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash -e
|
||||||
################################################################################
|
################################################################################
|
||||||
## File: install.sh
|
## File: install.sh
|
||||||
## Desc: Helper functions for installing tools
|
## Desc: Helper functions for installing tools
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash -e
|
||||||
################################################################################
|
################################################################################
|
||||||
## File: install-helpers.sh
|
## File: install-helpers.sh
|
||||||
## Desc: Helper functions for installing tools
|
## Desc: Helper functions for installing tools
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash -e
|
||||||
################################################################################
|
################################################################################
|
||||||
## File: pipx-packages.sh
|
## File: pipx-packages.sh
|
||||||
## Desc: Install tools via pipx
|
## Desc: Install tools via pipx
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash -e -o pipefail
|
||||||
BOOTSTRAP_PATH="$1"
|
BOOTSTRAP_PATH="$1"
|
||||||
ProvisionerPackageUri="$2"
|
ProvisionerPackageUri="$2"
|
||||||
ProvisionerScriptUri="$3"
|
ProvisionerScriptUri="$3"
|
||||||
|
|||||||
Reference in New Issue
Block a user