diff --git a/.github/workflows/static-test.yml b/.github/workflows/static-test.yml index 7d17466598..4529dc39dc 100644 --- a/.github/workflows/static-test.yml +++ b/.github/workflows/static-test.yml @@ -29,6 +29,7 @@ jobs: run: | docker run --rm \ -e CI_BASE_BRANCH=master_upstream \ + -e GITHUB_RUN_ID=${GITHUB_RUN_ID} \ -v $(pwd):/data/riotbuild \ riot/riotbuild:latest \ make static-test diff --git a/dist/tools/ci/github_annotate.sh b/dist/tools/ci/github_annotate.sh new file mode 100644 index 0000000000..9af96cc5e8 --- /dev/null +++ b/dist/tools/ci/github_annotate.sh @@ -0,0 +1,83 @@ +# Copyright 2020 Martine S. Lenders +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. + +LOG=cat +LOGFILE= +OUTFILE=github_annotate_outfile.log +ECHO_ESC=echo + +if ps -p $$ | grep -q '\'; then + # workaround when included in bash to escape newlines and carriage returns + # properly in _escape + ECHO_ESC='echo -e' +fi + +github_annotate_setup() { + if [ -n "${GITHUB_RUN_ID}" ]; then + LOGFILE=run-${GITHUB_RUN_ID}.log + LOG="tee -a ${LOGFILE}" + fi +} + +github_annotate_is_on() { + test -n "${LOGFILE}" + return $? +} + +_escape() { + # see https://stackoverflow.com/a/1252191/11921757 + ${ECHO_ESC} "$1" | sed -e ':a' -e 'N' -e '$!ba' \ + -e 's/%/%25/g' -e 's/\r/%0D/g' -e 's/\n/%0A/g' +} + +github_annotate_error() { + if [ -n "${GITHUB_RUN_ID}" ]; then + FILENAME="${1}" + LINENUM="${2}" + DETAILS="$(_escape "${3}")" + echo "::error file=${FILENAME},line=${LINENUM}::${DETAILS}" >> ${OUTFILE} + fi +} + +github_annotate_warning() { + if [ -n "${GITHUB_RUN_ID}" ]; then + FILENAME="${1}" + LINENUM="${2}" + DETAILS="$(_escape "${3}")" + echo "::warning file=${FILENAME},line=${LINENUM}::${DETAILS}" >> ${OUTFILE} + fi +} + +github_annotate_parse_log_default() { + ANNOTATE_FUNC="${1:-github_annotate_error}" + + if github_annotate_is_on; then + PATTERN='^.\+:[0-9]\+:' + + grep "${PATTERN}" "${LOGFILE}" | while read line; do + FILENAME=$(echo "${line}" | cut -d: -f1) + LINENUM=$(echo "${line}" | cut -d: -f2) + DETAILS=$(echo "${line}" | cut -d: -f3- | + sed -e 's/^[ \t]*//' -e 's/[ \t]*$//') + ${ANNOTATE_FUNC} "${FILENAME}" "${LINENUM}" "${DETAILS}" + done + fi +} + +github_annotate_teardown() { + if [ -n "${LOGFILE}" ]; then + rm -f ${LOGFILE} + LOGFILE= + fi +} + +github_annotate_report_last_run() { + if [ -n "${GITHUB_RUN_ID}" -a -f "${OUTFILE}" ]; then + # de-duplicate errors + sort -u ${OUTFILE} >&2 + fi + rm -f ${OUTFILE} +} diff --git a/dist/tools/ci/static_tests.sh b/dist/tools/ci/static_tests.sh index 09a6a3e9e7..cfaccd69e4 100755 --- a/dist/tools/ci/static_tests.sh +++ b/dist/tools/ci/static_tests.sh @@ -10,6 +10,8 @@ # directory for more details. # +. $(dirname "$0")/github_annotate.sh + function print_result { local RED="\033[0;31m" local GREEN="\033[0;32m" @@ -47,6 +49,7 @@ function run { (printf "%s\n" "$OUT" | while IFS= read -r line; do printf "\t%s\n" "$line"; done) echo "" fi + github_annotate_report_last_run } RESULT=0