dist/tools/ci/github_annotate.sh: allow annotations without files

This commit is contained in:
Martine Lenders 2020-12-17 15:57:19 +01:00
parent 6eb8e17861
commit 20350edebb
No known key found for this signature in database
GPG Key ID: CCD317364F63286F
2 changed files with 32 additions and 3 deletions

View File

@ -71,6 +71,14 @@ github_annotate_parse_log_default github_annotate_warning
does the same as the last example snippet, but uses `github_annotate_warning`
instead.
If you do not need to provide a file with your error or warning, you can also
use `github_annotate_error_no_file` or `github_annotate_warning_no_file`,
respectively. Both take a just message as single parameter:
```sh
github_annotate_error_no_file "Something is wrong!"
```
After all errors or warnings are annotated, call `github_annotate_teardown` to
finish annotations.

View File

@ -33,12 +33,26 @@ _escape() {
-e 's/%/%25/g' -e 's/\r/%0D/g' -e 's/\n/%0A/g'
}
_github_annotate() {
MESSAGE="$(_escape "${1}")"
LEVEL="${2:-error}"
OPTS="${3:-}"
echo "::${LEVEL} ${OPTS}::${DETAILS}" >> ${OUTFILE}
}
github_annotate_error() {
if [ -n "${GITHUB_RUN_ID}" ]; then
FILENAME="${1}"
LINENUM="${2}"
DETAILS="$(_escape "${3}")"
echo "::error file=${FILENAME},line=${LINENUM}::${DETAILS}" >> ${OUTFILE}
DETAILS="${3}"
_github_annotate "${DETAILS}" error "file=${FILENAME},line=${LINENUM}"
fi
}
github_annotate_error_no_file() {
if [ -n "${GITHUB_RUN_ID}" ]; then
DETAILS="${1}"
_github_annotate "${DETAILS}" error
fi
}
@ -47,7 +61,14 @@ github_annotate_warning() {
FILENAME="${1}"
LINENUM="${2}"
DETAILS="$(_escape "${3}")"
echo "::warning file=${FILENAME},line=${LINENUM}::${DETAILS}" >> ${OUTFILE}
_github_annotate "${DETAILS}" warning "file=${FILENAME},line=${LINENUM}"
fi
}
github_annotate_warning_no_file() {
if [ -n "${GITHUB_RUN_ID}" ]; then
DETAILS="${1}"
_github_annotate "${DETAILS}" warning
fi
}