diff --git a/dist/tools/ci/README.md b/dist/tools/ci/README.md index 1648c04bd3..7236afe395 100644 --- a/dist/tools/ci/README.md +++ b/dist/tools/ci/README.md @@ -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. diff --git a/dist/tools/ci/github_annotate.sh b/dist/tools/ci/github_annotate.sh index 9af96cc5e8..41acd65461 100644 --- a/dist/tools/ci/github_annotate.sh +++ b/dist/tools/ci/github_annotate.sh @@ -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 }