dep_status_check 1.22 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/bin/bash

pkgBuildDir="${1}"
outDir="$(pwd)/out"
reportFile="${outDir}/dep_status"

mkdir -p "${outDir}"
cd "${pkgBuildDir}"

dep status -v -old -json > "${reportFile}"

if [ "$(cat "${reportFile}")" == "[]" ] ; then
    exit 0
fi

jq -C . "${reportFile}"
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

#
# Borrowed from https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/support/notify_slack.sh
# and adjusted for our needs:)
#
if [[ -z "${CI_DEP_STATUS_NOTIFY_CHANNEL}" ]] || [[ -z "${CI_DEP_STATUS_NOTIFY_SLACK_WEBHOOK}" ]]; then
    echo "Variables CI_DEP_STATUS_NOTIFY_CHANNEL and CI_DEP_STATUS_NOTIFY_SLACK_WEBHOOK are not defined"
    echo "Will not send slack notification"
else
    messageTmpFile="$(mktemp)"

    cat > "${messageTmpFile}" << EOS
\`dep status\` check for <${CI_PROJECT_URL}> failed. Some dependencies should be updated:
\`\`\`
$(jq -M . "${reportFile}")
\`\`\`
See <${CI_JOB_URL}>
EOS

    message=$(sed -e ':a' -e 'N' -e '$!ba' -e "s/\n/\\\n/g" "${messageTmpFile}")
    payload='payload={"channel": "'"${CI_DEP_STATUS_NOTIFY_CHANNEL}"'", "username": "GitLab Runner Dep Status Check", "text": "'"${message//\"/\\\"}"'", "icon_emoji": ":mantelpiece_clock:"}'
    curl -X POST -s -L --data-urlencode "${payload}" "${CI_DEP_STATUS_NOTIFY_SLACK_WEBHOOK}"
fi

41
exit 1