mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
dist/tools/ci: add harness to annotate static tests in Github Actions
This commit is contained in:
parent
2b110e3248
commit
019817d58b
1
.github/workflows/static-test.yml
vendored
1
.github/workflows/static-test.yml
vendored
@ -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
|
||||
|
83
dist/tools/ci/github_annotate.sh
vendored
Normal file
83
dist/tools/ci/github_annotate.sh
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
# Copyright 2020 Martine S. Lenders <m.lenders@fu-berlin.sh>
|
||||
#
|
||||
# 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 '\<bash\>'; 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}
|
||||
}
|
3
dist/tools/ci/static_tests.sh
vendored
3
dist/tools/ci/static_tests.sh
vendored
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user