Skip to content

Commit b90d0c5

Browse files
committed
fix: provide defaults for missing JOB values
As reported in Slack, if a value is missing, `jq` returns `null`. When run normally (e.g., `echo "${JOB}" | jq -r '.somekey'`), this becomes an empty string when the key is missing. However, when run within a subshell (e.g., when assigning to a variable, such as `VALUE=$(echo "${JOB}" | jq -r '.somekey')`), the string `null` is returned. Fortunately, `jq` allows specifying an alternative value if a value is missing or `false` or `null`, via the `//` operator. This patch adds alternatives everywhere `jq` is invoked when assigning a variable. Signed-off-by: Matthew Weier O'Phinney <[email protected]>
1 parent 1534dff commit b90d0c5

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

entrypoint.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ fi
110110
JOB=$1
111111
echo "Received job: ${JOB}"
112112

113-
COMMAND=$(echo "${JOB}" | jq -r '.command')
113+
COMMAND=$(echo "${JOB}" | jq -r '.command // ""')
114114

115115
if [[ "${COMMAND}" == "" ]];then
116116
echo "Command is empty; nothing to run"
117117
exit 0
118118
fi
119119

120-
PHP=$(echo "${JOB}" | jq -r '.php')
120+
PHP=$(echo "${JOB}" | jq -r '.php // ""')
121121
if [[ "${PHP}" == "" ]];then
122122
echo "Missing PHP version in job"
123123
help
@@ -137,9 +137,9 @@ if [ -x ".laminas-ci/pre-install.sh" ];then
137137
./.laminas-ci/pre-install.sh testuser "${PWD}" "${JOB}"
138138
fi
139139

140-
EXTENSIONS=$(echo "${JOB}" | jq -r ".extensions | map(\"php${PHP}-\"+.) | join(\" \")")
141-
INI=$(echo "${JOB}" | jq -r '.ini | join("\n")')
142-
DEPS=$(echo "${JOB}" | jq -r '.dependencies')
140+
EXTENSIONS=$(echo "${JOB}" | jq -r ".extensions // [] | map(\"php${PHP}-\"+.) | join(\" \")")
141+
INI=$(echo "${JOB}" | jq -r '.ini // [] | join("\n")')
142+
DEPS=$(echo "${JOB}" | jq -r '.dependencies // "locked"')
143143

144144
if [[ "${EXTENSIONS}" != "" ]];then
145145
ENABLE_SQLSRV=false

0 commit comments

Comments
 (0)