Skip to content

Commit f7c39d1

Browse files
committed
build(make): use POSIX-safe command detection during prerequisite checks
1 parent e47dfeb commit f7c39d1

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Makefile.toml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ rm -rf ${DOCS_FOLDER}/*
9898
[tasks.check-npx]
9999
description = "Check npx is installed"
100100
script = '''
101-
if ! which npx >/dev/null; then
101+
if ! command -v npx >/dev/null 2>&1; then
102102
echo "❌ npx could not be found"
103103
echo " Consider installing npx with: npm install -g npx"
104104
exit 1
@@ -108,7 +108,7 @@ fi
108108
[tasks.check-awk]
109109
description = "Check awk is installed"
110110
script = '''
111-
if ! which awk >/dev/null; then
111+
if ! command -v awk >/dev/null 2>&1; then
112112
echo "❌ awk could not be found"
113113
echo " Consider installing awk (usually pre-installed on Unix systems)"
114114
exit 1
@@ -118,7 +118,7 @@ fi
118118
[tasks.check-perl]
119119
description = "Check perl is installed"
120120
script = '''
121-
if ! which perl >/dev/null; then
121+
if ! command -v perl >/dev/null 2>&1; then
122122
echo "❌ perl could not be found"
123123
echo " Consider installing perl (usually pre-installed on Unix systems)"
124124
exit 1
@@ -128,23 +128,27 @@ fi
128128
[tasks.check-jq]
129129
description = "Check jq is installed (version 1.7 or higher, but below 2.0)"
130130
script = '''
131-
if ! which jq >/dev/null; then
131+
if ! command -v jq >/dev/null 2>&1; then
132132
echo "❌ jq could not be found"
133133
echo " Consider installing jq: brew install jq (macOS) or apt-get install jq (Linux)"
134134
exit 1
135135
fi
136136
137-
jq_version=$(jq --version 2>&1 | grep -oE '[0-9]+\.[0-9]+' | head -1)
138-
jq_major=$(echo "$jq_version" | cut -d. -f1)
139-
jq_minor=$(echo "$jq_version" | cut -d. -f2)
137+
jq_version=$(jq --version 2>/dev/null | sed -E 's/^jq-([0-9]+)\.([0-9]+).*/\1.\2/')
138+
if ! printf '%s' "$jq_version" | grep -Eq '^[0-9]+\.[0-9]+$'; then
139+
echo "❌ Could not determine jq version (got: '$jq_version')"
140+
exit 1
141+
fi
142+
jq_major=${jq_version%%.*}
143+
jq_minor=${jq_version#*.}
140144
141145
if [ "$jq_major" -lt 1 ] || ([ "$jq_major" -eq 1 ] && [ "$jq_minor" -lt 7 ]); then
142146
echo "❌ jq version $jq_version is too old (require >= 1.7)"
143147
exit 1
144148
fi
145149
146150
if [ "$jq_major" -ge 2 ]; then
147-
echo "⚠️ Warning: jq version $jq_version is untested (expected 1.7-1.x)"
151+
echo "⚠️ Warning: jq version $jq_version is untested (expected >= 1.7 and < 2.0)"
148152
fi
149153
'''
150154

0 commit comments

Comments
 (0)