-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathprepmsg.sh
executable file
·40 lines (33 loc) · 1.2 KB
/
prepmsg.sh
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
#!/bin/bash
# Prepare message for Telegram notification
set -ex
die() { echo "$0: error: $*" >&2; exit 1; }
[ $# -ne 2 ] && die "Expected 1 input and 1 output files, got $#"
[ ! -f "$1" ] && die "Input file $1 not found, skipping."
[ -z "${PYDOC_REPO}" ] && die "PYDOC_REPO is empty."
[ -z "${PYDOC_VERSION}" ] && die "PYDOC_VERSION is empty."
[ -z "${GITHUB_RUN_ID}" ] && die "GITHUB_RUN_ID is empty."
[ -z "${GITHUB_JOB}" ] && die "GITHUB_JOB is empty."
URL="${PYDOC_REPO}/actions/runs/${GITHUB_RUN_ID}"
input="$1"
output="$2"
touch aux
if [[ "${GITHUB_JOB}" == "build" ]]; then
grep 'cpython/Doc/.*WARNING:' "$input" | \
sed 's|.*/cpython/Doc/||' | \
uniq | \
sed 's|^|```\n|;s|$|\n```\n|' \
> aux
elif [[ "${GITHUB_JOB}" == "lint" ]]; then
grep -P '^.*\.po:\d+:\s+.*\(.*\)$' "$input" | \
sed 's|.*/cpython/Doc/||' | \
sort -u | \
sed 's|^|```\n|;s|$|\n```\n|' \
> aux
else
die "Unexpected job name ${GITHUB_JOB}"
fi
[[ $(cat aux) == "" ]] && die "Unexpected empty output message."
echo "❌ *${PYDOC_VERSION} ${GITHUB_JOB}* (ID [${GITHUB_RUN_ID}]($URL)):" > "$output";
{ echo ""; cat aux; echo ""; } >> "$output"
rm aux