forked from RIOT-OS/RIOT
-
Notifications
You must be signed in to change notification settings - Fork 0
Dist/tools/static test annotate #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MrKevinWeiss
wants to merge
11
commits into
master
Choose a base branch
from
dist/tools/static-test-annotate
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c504557
dist/tools/ci: add harness to annotate static tests in Github Actions
miri64 a447fbe
tools/whitespacecheck: annotate errors in Github Action
miri64 8bf64a6
dist/tools/ci: Add README.md
miri64 0aab760
REMOVE ME! just for testing
miri64 2063971
fixup! dist/tools/ci: add harness to annotate static tests in Github …
miri64 86172f6
fixup! dist/tools/ci: add harness to annotate static tests in Github …
miri64 472e7db
test
MrKevinWeiss 9df614a
test flake8 annotation
MrKevinWeiss e15988f
fixup! test flake8 annotation
MrKevinWeiss a0c8f24
fixup! fixup! test flake8 annotation
MrKevinWeiss 4d45f02
fixup! fixup! fixup! test flake8 annotation
MrKevinWeiss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| CI specific scripts | ||
| =================== | ||
|
|
||
| Static tests | ||
| ------------ | ||
|
|
||
| The [static_tests.sh] script runs all static tests and outputs them in a unified | ||
| output. You can also run this script by running `make static-test` in the base | ||
| directory. | ||
|
|
||
| To add a new static test, just write a `check.sh` script or call your static | ||
| checker directly and add it to the list of static tests in [static_tests.sh]: | ||
|
|
||
| ```sh | ||
| ENV1=foobar ENV2=snafu run <your test command> --args | ||
| ``` | ||
|
|
||
| Github annotations | ||
| ------------------ | ||
| Using [github_annotate.sh] you can generate [Github annotations] for your | ||
| tests. You can generate both warnings and errors. Before doing anything however, | ||
| you include [github_annotate.sh]\ (assuming `${RIOTTOOLS is set to}` [dist/tools/]) | ||
|
|
||
| ```sh | ||
| . "${RIOTTOOLS}"/ci/github_annotate.sh | ||
| ``` | ||
|
|
||
| and set-up the mechanism | ||
|
|
||
| ```sh | ||
| github_annotate_setup | ||
| ``` | ||
|
|
||
| If your tests generate output you now can pipe that to the file `${LOGFILE}` by | ||
| using `${LOG}`, e.g. | ||
|
|
||
| ```sh | ||
| my_awesome_test | ${LOG} | ||
| ``` | ||
|
|
||
| Don't worry, your test will function normal still, if you don't run it in a | ||
| Github Action! | ||
|
|
||
| Now you can use `github_annotate_error` and `github_annotate_warning` to | ||
| generate the actual errors and warnings. Both commands expect 3 parameters: | ||
| 1. `FILENAME`: The name of the file the warning or error occurred in, | ||
| 2. `LINENUM`: The number of the line the warning or error occurred in, and | ||
| 3. `DETAILS`: Some descriptive details or the message of your warning or error. | ||
|
|
||
| You can parse those from `${LOGFILE}` (e.g. using tools such as `grep`, `sed`, | ||
| or `awk`) or generate them on the fly, if your script allows for that. E.g. | ||
|
|
||
| ```sh | ||
| cat ${LOGFILE} | grep '^.*:[0-9]\+:' | while read error; do | ||
| github_annotate_error \ | ||
| $(echo "${error}" | cut -d: -f1) \ | ||
| $(echo "${error}" | cut -d: -f2) \ | ||
| $(echo "${error}" | cut -d: -f3-) | ||
| done | ||
| ``` | ||
|
|
||
| After all errors or warnings are annotated, call `github_annotate_teardown` to | ||
| finish annotations. | ||
|
|
||
| **Note:** `github_annotate_report_last_run` is called within [static_tests.sh] | ||
| to attach the actual annotations to your PR. You don't need to call it from | ||
| within your test if you are adding that test to [static_tests.sh]. | ||
|
|
||
| [static_tests.sh]: ./static_tests.sh | ||
| [Github annotations]: https://github.blog/2018-12-14-introducing-check-runs-and-annotations/ | ||
| [github_annotate.sh]: ./github_annotate.sh | ||
| [dist/tools]: ../ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # 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_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} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |||||
| # General Public License v2.1. See the file LICENSE in the top level | ||||||
| # directory for more details. | ||||||
| # | ||||||
| . "$(dirname "$0")/../ci/github_annotate.sh" | ||||||
| github_annotate_setup | ||||||
|
|
||||||
| FLAKE8_CMD="python3 -m flake8" | ||||||
|
|
||||||
|
|
@@ -43,7 +45,19 @@ ${FLAKE8_CMD} --version &> /dev/null || { | |||||
| exit 1 | ||||||
| } | ||||||
|
|
||||||
| ERRORS=$(${FLAKE8_CMD} --config="${RIOTTOOLS}"/flake8/flake8.cfg ${FILES}) | ||||||
| ERRORS=$(${FLAKE8_CMD} --config="${RIOTTOOLS}"/flake8/flake8.cfg ${FILES} | ${LOG}) | ||||||
|
|
||||||
| if github_annotate_is_on; then | ||||||
| grep "^.\+:[0-9]\+:" "${LOGFILE}" | while read line; do | ||||||
| FILENAME=$(echo "${line}" | cut -d: -f1) | ||||||
| LINENR=$(echo "${line}" | cut -d: -f2) | ||||||
| DETAILS=$(echo "${line}" | cut -d: -f3- | | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the output of the test annotation: I think
Suggested change
|
||||||
| sed -e 's/^[ \t]*//' -e 's/[ \t]*$//') | ||||||
| github_annotate_error "${FILENAME}" "${LINENR}" "${DETAILS}" | ||||||
| done | ||||||
| fi | ||||||
|
|
||||||
| github_annotate_teardown | ||||||
|
|
||||||
| if [ -n "${ERRORS}" ] | ||||||
| then | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I would just use the
ERRORSvariable instead of indirecting viaLOG, as I did in the doccheck