Skip to content

Commit

Permalink
fix: don't fail the workflow if sort --version-sort doesn't exist (#174)
Browse files Browse the repository at this point in the history
`sort --version-sort` doesn't exist on some systems, so adding in a
check for its return value before depending on the result.
  • Loading branch information
puzzler7 committed Aug 3, 2023
1 parent 896a55e commit 883e222
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
12 changes: 7 additions & 5 deletions all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ elif [[ ${INPUT_CHECK_ALL_MODE} == "hold-the-line" ]]; then
upload_id_arg="--upload-id ${INPUT_UPLOAD_ID}"
trunk_version="$(${TRUNK_PATH} version)"
# trunk-ignore-begin(shellcheck/SC2312): the == will fail if anything inside the $() fails
if [[ "$(printf "%s\n%s\n" "${MINIMUM_UPLOAD_ID_VERSION}" "${trunk_version}" |
sort --version-sort |
head -n 1)" == "${trunk_version}"* ]]; then
echo "::error::Please update your CLI to ${MINIMUM_UPLOAD_ID_VERSION} or higher (current version ${trunk_version})."
exit 1
if sort_result=$(printf "%s\n%s\n" "${MINIMUM_UPLOAD_ID_VERSION}" "${trunk_version}" | sort --version-sort); then
if [[ $(echo "${sort_result}" | head -n 1) == "${trunk_version}" ]]; then
echo "::error::Please update your CLI to ${MINIMUM_UPLOAD_ID_VERSION} or higher (current version ${trunk_version})."
exit 1
fi
else
echo "::warning::sort --version-sort failed - continuing without checking CLI version"
fi
# trunk-ignore-end(shellcheck/SC2312)
else
Expand Down
12 changes: 7 additions & 5 deletions pull_request.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ fi
if [[ -n ${INPUT_CHECK_RUN_ID} ]]; then
trunk_version="$(${TRUNK_PATH} version)"
# trunk-ignore-begin(shellcheck/SC2312): the == will fail if anything inside the $() fails
if [[ "$(printf "%s\n%s\n" "${MINIMUM_CHECK_RUN_ID_VERSION}" "${trunk_version}" |
sort --version-sort |
head -n 1)" == "${trunk_version}"* ]]; then
echo "::error::Please update your CLI to ${MINIMUM_CHECK_RUN_ID_VERSION} or higher (current version ${trunk_version})."
exit 1
if sort_result=$(printf "%s\n%s\n" "${MINIMUM_CHECK_RUN_ID_VERSION}" "${trunk_version}" | sort --version-sort); then
if [[ $(echo "${sort_result}" | head -n 1) == "${trunk_version}" ]]; then
echo "::error::Please update your CLI to ${MINIMUM_CHECK_RUN_ID_VERSION} or higher (current version ${trunk_version})."
exit 1
fi
else
echo "::warning::sort --version-sort failed - continuing without checking CLI version"
fi
# trunk-ignore-end(shellcheck/SC2312)
annotation_argument=--trunk-annotate=${INPUT_CHECK_RUN_ID}
Expand Down
12 changes: 7 additions & 5 deletions trunk_merge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ echo "Detected merge queue commit, using HEAD^1 (${upstream}) as upstream and HE
if [[ -n ${INPUT_CHECK_RUN_ID} ]]; then
trunk_version="$(${TRUNK_PATH} version)"
# trunk-ignore-begin(shellcheck/SC2312): the == will fail if anything inside the $() fails
if [[ "$(printf "%s\n%s\n" "${MINIMUM_CHECK_RUN_ID_VERSION}" "${trunk_version}" |
sort --version-sort |
head -n 1)" == "${trunk_version}"* ]]; then
echo "::error::Please update your CLI to ${MINIMUM_CHECK_RUN_ID_VERSION} or higher (current version ${trunk_version})."
exit 1
if sort_result=$(printf "%s\n%s\n" "${MINIMUM_CHECK_RUN_ID_VERSION}" "${trunk_version}" | sort --version-sort); then
if [[ $(echo "${sort_result}" | head -n 1) == "${trunk_version}" ]]; then
echo "::error::Please update your CLI to ${MINIMUM_CHECK_RUN_ID_VERSION} or higher (current version ${trunk_version})."
exit 1
fi
else
echo "::warning::sort --version-sort failed - continuing without checking CLI version"
fi
# trunk-ignore-end(shellcheck/SC2312)
annotation_argument=--trunk-annotate=${INPUT_CHECK_RUN_ID}
Expand Down

0 comments on commit 883e222

Please sign in to comment.