mirror of
https://github.com/rlespinasse/shortify-git-revision.git
synced 2026-07-17 16:02:07 +00:00
feat: add short-on-error input
This commit is contained in:
committed by
Romain Lespinasse
parent
512ffd9023
commit
ef0d40cdf6
26
shortify.sh
26
shortify.sh
@@ -12,27 +12,37 @@ fi
|
||||
REVISION=${INPUT_REVISION:-${!NAME}}
|
||||
|
||||
SHORT_LENGTH=""
|
||||
if [ "$INPUT_LENGTH" != "" ]; then
|
||||
if [ "$INPUT_LENGTH" -eq "$INPUT_LENGTH" ] 2>/dev/null; then
|
||||
if [ "${INPUT_LENGTH}" != "" ]; then
|
||||
if [ "${INPUT_LENGTH}" -eq "${INPUT_LENGTH}" ] 2>/dev/null; then
|
||||
SHORT_LENGTH="=${INPUT_LENGTH}"
|
||||
elif [ "${INPUT_CONTINUE_ON_ERROR}" == "false" ]; then
|
||||
echo "::error ::Invalid length: $INPUT_LENGTH, should be a number"
|
||||
echo "::error ::Invalid length: ${INPUT_LENGTH}, should be a number"
|
||||
exit 1
|
||||
else
|
||||
echo "::warning ::Invalid length: $INPUT_LENGTH, the default length will be used."
|
||||
echo "::warning ::Invalid length: ${INPUT_LENGTH}, the default length will be used."
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$REVISION" ]; then
|
||||
if [ -z "${REVISION}" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$(git cat-file -e "$REVISION" 2>&1)" == "" ]; then
|
||||
if [ "$(git cat-file -e "${REVISION}" 2>&1)" == "" ]; then
|
||||
{
|
||||
echo "${PREFIX}${NAME}=${REVISION}"
|
||||
echo "${PREFIX}${NAME}_SHORT=$(git rev-parse --short"${SHORT_LENGTH}" "$REVISION")"
|
||||
echo "${PREFIX}${NAME}_SHORT=$(git rev-parse --short"${SHORT_LENGTH}" "${REVISION}")"
|
||||
} >>"$GITHUB_ENV"
|
||||
elif [ "${INPUT_SHORT_ON_ERROR}" == "true" ]; then
|
||||
if [ -n "${INPUT_LENGTH}" ]; then
|
||||
{
|
||||
echo "${PREFIX}${NAME}=${REVISION}"
|
||||
echo "${PREFIX}${NAME}_SHORT=$(cut -c1-"${INPUT_LENGTH}" <<<"${REVISION}")"
|
||||
} >>"$GITHUB_ENV"
|
||||
else
|
||||
echo "::error ::The input 'lenght' is mandatory with 'short-on-error' set to 'true'"
|
||||
exit 1
|
||||
fi
|
||||
elif [ "${INPUT_CONTINUE_ON_ERROR}" == "false" ]; then
|
||||
echo "::error ::Invalid revision: $REVISION from $NAME"
|
||||
echo "::error ::Invalid revision: ${REVISION} from ${NAME}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user