mirror of
https://github.com/coreos/fedora-coreos-config.git
synced 2026-02-05 09:45:30 +01:00
committed by
Jonathan Lebon
parent
8433d0fc39
commit
9c3a2d16af
24
.github/workflows/shellcheck.yml
vendored
Normal file
24
.github/workflows/shellcheck.yml
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# Template generated by https://github.com/coreos/repo-templates; do not edit downstream
|
||||
|
||||
name: ShellCheck
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [testing-devel]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
shellcheck:
|
||||
name: Shellcheck
|
||||
runs-on: ubuntu-latest
|
||||
container: quay.io/coreos-assembler/fcos-buildroot:testing-devel
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
# https://github.com/actions/checkout/issues/760
|
||||
- name: Mark git checkout as safe
|
||||
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
||||
- name: Run ShellCheck
|
||||
run: ci/shellcheck
|
||||
35
ci/shellcheck
Executable file
35
ci/shellcheck
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
# Template generated by https://github.com/coreos/repo-templates; do not edit downstream
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
main() {
|
||||
local found_errors="false"
|
||||
# Let's start with error, then we can do warning, info, style
|
||||
local -r severity="error"
|
||||
|
||||
while IFS= read -r -d '' f; do
|
||||
# Skip non-text files that are very unlikely to be shell scripts
|
||||
if [[ "$(file -b --mime-type "${f}" | sed 's|/.*||')" != "text" ]]; then
|
||||
continue
|
||||
fi
|
||||
shebang="$(head -1 "${f}")"
|
||||
if [[ "${f}" == *.sh ]] || \
|
||||
[[ ${shebang} =~ ^#!/.*/bash.* ]] || \
|
||||
[[ ${shebang} =~ ^#!/.*/env\ bash ]]; then
|
||||
echo "[+] Checking ${f}"
|
||||
shellcheck --external-sources --shell bash --severity="${severity}" "${f}" || found_errors="true"
|
||||
bash -n "${f}" || found_errors="true"
|
||||
fi
|
||||
done< <(find . -path "./.git" -prune -o -type f -print0)
|
||||
|
||||
if [[ "${found_errors}" != "false" ]]; then
|
||||
echo "[+] Found errors with ShellCheck"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[+] No error found with ShellCheck"
|
||||
exit 0
|
||||
}
|
||||
|
||||
main "${@}"
|
||||
Reference in New Issue
Block a user