Skip to content
Open
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
35 changes: 35 additions & 0 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Shell scripts

on:
push:
branches: [main]
pull_request:

jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Find shell scripts
id: find
run: |
files=$(find . -name '*.sh' -not -path './node_modules/*')
echo "files<<EOF" >> "$GITHUB_OUTPUT"
echo "$files" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"

- name: bash -n syntax check
run: |
while IFS= read -r f; do
[ -z "$f" ] && continue
echo "checking $f"
bash -n "$f"
done <<< "${{ steps.find.outputs.files }}"

- name: shellcheck
run: |
while IFS= read -r f; do
[ -z "$f" ] && continue
shellcheck --severity=error "$f"
done <<< "${{ steps.find.outputs.files }}"
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ declare -A PM_PATTERNS=(

ECO=""
PM=""
MATCHED=""
for key in "${!PM_PATTERNS[@]}"; do
pat="${PM_PATTERNS[$key]}"
if [[ "$CMD" =~ $pat ]]; then
ECO="${key%%:*}"
PM="${key##*:}"
MATCHED="${BASH_REMATCH[0]}"
break
fi
done
Expand All @@ -78,10 +80,12 @@ fi
log "package install detected: ecosystem=$ECO pm=$PM"

# ---- Extract package names from the command ----
# Strip the package-manager prefix and flags. This is heuristic; we err on the
# side of catching extra tokens (which then get filtered by the validity check).
TAIL="$(printf '%s' "$CMD" \
| sed -E "s/.*${PM}[[:space:]]+(install|i|add|require|get|package)[[:space:]]+//" \
# Strip the package-manager prefix and flags, using the exact text the
# detection regex matched (not a reconstructed "$PM install" guess — that
# guess never matches "pip3 install" or "go get", since PM is "pip"/"goget",
# leaving the whole command unstripped and "pip3"/"go"/"get" treated as
# package names). This is heuristic; extra tokens get filtered below anyway.
TAIL="$(printf '%s' "${CMD#*"$MATCHED"}" \
| tr ' ' '\n' \
| grep -E -v '^(-|--)' \
| grep -E -v '^(install|add|i|--save|--save-dev|--dev|-D|-g|--global)$' \
Expand Down Expand Up @@ -154,11 +158,18 @@ print(dp[n])
# Strip version specifiers and scope prefix for matching
clean_pkg() {
local p="$1"
# strip @scope/ prefix temporarily for distance check; keep for blocklist
p="${p%@*}" # strip @version (npm: react@18 -> react; scoped @scope/x stays)
p="${p%[[<>=!~^]*}" # strip pip/cargo specifiers like ==1.0
local scope=""
# pull off @scope/ first — otherwise the leading @ of a scoped, unversioned
# package (e.g. "@types/node") gets misread as a version separator below
# and clean_pkg returns "", silently skipping the package entirely.
if [[ "$p" == @*/* ]]; then
scope="${p%%/*}/"
p="${p#*/}"
fi
p="${p%@*}" # strip @version (react@18 -> react)
p="${p%%[[<>=!~^]*}" # strip pip/cargo specifiers like ==1.0 (longest match, else trailing "=" remains)
p="${p%:*}" # strip composer vendor:
printf '%s' "$p"
printf '%s' "${scope}${p}"
}

is_blocklisted() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ declare -A PM_PATTERNS=(

ECO=""
PM=""
MATCHED=""
for key in "${!PM_PATTERNS[@]}"; do
pat="${PM_PATTERNS[$key]}"
if [[ "$CMD" =~ $pat ]]; then
ECO="${key%%:*}"
PM="${key##*:}"
MATCHED="${BASH_REMATCH[0]}"
break
fi
done
Expand All @@ -78,10 +80,12 @@ fi
log "package install detected: ecosystem=$ECO pm=$PM"

# ---- Extract package names from the command ----
# Strip the package-manager prefix and flags. This is heuristic; we err on the
# side of catching extra tokens (which then get filtered by the validity check).
TAIL="$(printf '%s' "$CMD" \
| sed -E "s/.*${PM}[[:space:]]+(install|i|add|require|get|package)[[:space:]]+//" \
# Strip the package-manager prefix and flags, using the exact text the
# detection regex matched (not a reconstructed "$PM install" guess — that
# guess never matches "pip3 install" or "go get", since PM is "pip"/"goget",
# leaving the whole command unstripped and "pip3"/"go"/"get" treated as
# package names). This is heuristic; extra tokens get filtered below anyway.
TAIL="$(printf '%s' "${CMD#*"$MATCHED"}" \
| tr ' ' '\n' \
| grep -E -v '^(-|--)' \
| grep -E -v '^(install|add|i|--save|--save-dev|--dev|-D|-g|--global)$' \
Expand Down Expand Up @@ -154,11 +158,18 @@ print(dp[n])
# Strip version specifiers and scope prefix for matching
clean_pkg() {
local p="$1"
# strip @scope/ prefix temporarily for distance check; keep for blocklist
p="${p%@*}" # strip @version (npm: react@18 -> react; scoped @scope/x stays)
p="${p%[[<>=!~^]*}" # strip pip/cargo specifiers like ==1.0
local scope=""
# pull off @scope/ first — otherwise the leading @ of a scoped, unversioned
# package (e.g. "@types/node") gets misread as a version separator below
# and clean_pkg returns "", silently skipping the package entirely.
if [[ "$p" == @*/* ]]; then
scope="${p%%/*}/"
p="${p#*/}"
fi
p="${p%@*}" # strip @version (react@18 -> react)
p="${p%%[[<>=!~^]*}" # strip pip/cargo specifiers like ==1.0 (longest match, else trailing "=" remains)
p="${p%:*}" # strip composer vendor:
printf '%s' "$p"
printf '%s' "${scope}${p}"
}

is_blocklisted() {
Expand Down
Binary file not shown.