Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
30 changes: 30 additions & 0 deletions .github/shell_check.bsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

# docker run -it --rm -v "${VSI_COMMON_DIR}:/code:ro" registry.gitlab.com/pipeline-components/shellcheck:latest /code/.github/shell_check.bsh

set -eu

SHELLCHECK_ARGS=(
# no fancy args with spaces, won't work because of how I pass array below
-f json
# -S error
# -e ...
)

cd "${GITHUB_WORKSPACE-/code}"

git config --global --add safe.directory /src/external/terra/external/vsi_common

git ls-files -z |
xargs -0 -n1 sh -c '[ -f "${1}" ] && \
head -n 1 "$1" | \
grep -qE "^#!.*(bash|false)" \
&& echo "$1"' _ | \
grep -v '\.simplecov' | \
xargs -n10 -P "$(nproc)" bash -c 'shellcheck '"${SHELLCHECK_ARGS[*]}"' "${@}" > /tmp/results.$$; for x in "${@}"; do echo "${x}" processed.; done' _
# process 10 at a time, because 50 at a time causes it to hang. 49 worked

mkdir -p /tmp/results
jq -s add /tmp/results.* > /tmp/results/shellcheck.json

jq -r '.[] | select(.level == "error" or .level == "warning") | "::\(.level) file=\(.file),line=\(.line),endLine=\(.endLine),col=\(.column),endColumn=\(.endColumn),title=ShellCheck::\(.message)"' /tmp/results/shellcheck.json
27 changes: 27 additions & 0 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Shellcheck linting

# This is required
on:
push:

jobs:
shellcheck:
runs-on: ubuntu-latest
container:
image: registry.gitlab.com/pipeline-components/shellcheck:latest
steps:
- name: Preinstall
run: |
apk add --no-cache git jq
git config --global --add safe.directory '*'
- name: Checkout repository
uses: actions/checkout@v4 # This step will also run inside the container
with:
submodules: false
- name: Run ShellCheck
run: "${GITHUB_WORKSPACE}/.github/shell_check.bsh"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ShellCheck-results
path: /tmp/results/shellcheck.json
2 changes: 2 additions & 0 deletions linux/common_source.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env false

#*# linux/common_source

# Use the sh POSIX compliant version of source_once
Expand Down
1 change: 1 addition & 0 deletions setup.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env false
test -f ./linux/check_shell && ./linux/check_shell bash zsh
export JUST_SETUP_SCRIPT="$(basename "${BASH_SOURCE[0]}")"
source "$(dirname "${BASH_SOURCE[0]}")/env.bsh"
Expand Down
1 change: 1 addition & 0 deletions tests/test_colors.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env false

#*# tests/test_colors

Expand Down
2 changes: 2 additions & 0 deletions vsi_common.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env false

JUST_PROJECT_PREFIX=VSI_COMMON
source "${VSI_COMMON_DIR}/linux/just_files/just_version.bsh"

Expand Down
Loading