Repository navigation
Expand file tree
/
Copy pathutils.sh
More file actions
83 lines (67 loc) · 1.77 KB
/
Copy pathutils.sh
File metadata and controls
83 lines (67 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
DEBUG=${DEBUG:-0}
# The function `run` will exit the script if the given command fails.
# The command itself is not printed, as it may contain repository names.
run () {
local status=0
"$@" || status=$?
if [ $status -ne 0 ]; then
echo "ERROR: Encountered error (${status}) at line ${BASH_LINENO[0]} of file $0. Aborting." >&2
exit $status
fi
}
# The function `quiet` runs a command and shows its stderr only if it fails.
quiet () {
local status=0 log
log=$(mktemp)
"$@" 2> "$log" || status=$?
if [ $status -ne 0 ]; then
sed 's/^/ /' "$log" >&2
fi
rm -f "$log"
return $status
}
# The function `mask` hides the given value from GitHub Actions logs.
mask () {
if [ "${GITHUB_ACTIONS:-}" == "true" ] && [ -n "$1" ]; then
echo "::add-mask::$1"
fi
}
debug () {
NOW=$(date +"%Y-%m-%d %H:%M:%S")
echo -e "🔹 $NOW [DEBUG] $1"
}
info () {
NOW=$(date +"%Y-%m-%d %H:%M:%S")
echo -e "🔸 $NOW [INFO] $1"
}
warning () {
NOW=$(date +"%Y-%m-%d %H:%M:%S")
echo -e "🔸 $NOW [WARNING] $1"
}
success () {
NOW=$(date +"%Y-%m-%d %H:%M:%S")
echo -e "👍 $NOW [SUCCESS] $1"
slack "$1" ":white_check_mark:"
}
error () {
NOW=$(date +"%Y-%m-%d %H:%M:%S")
echo -e "🔺 $NOW [ERROR] $1"
slack "$1" ":warning:"
}
slack () {
# Slack hook is added as ENV variable
SLACK_HOOK="${SLACK_HOOK:-""}"
if [ "$DEBUG" == "1" ]
then
debug "Not flooding Slack in debug mode: $1"
return 0
elif [ -z "${SLACK_HOOK}" ]
then
info "No Slack webhook supplied. You need to give Slack webhook as an ENV variable SLACK_HOOK."
return 0
fi
jq -n --arg text "$2 $1" '{text: $text}' \
| curl -s -o /dev/null -X POST -H 'Content-type: application/json' --data @- "$SLACK_HOOK" \
|| warning "Could not send Slack notification"
}