Skip to content
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

Errors: Introducing '--message_format github', for github actions #3553

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

mtzguido
Copy link
Member

Inspired by @W95Psp 's PR #3491, I thought this could be a nice addition. By setting this flag the warnings and errors look like this:

::warning file=/home/guido/r/fstar/github/ulib/FStar.UInt.fsti,line=435,endLine=435::(271) Pattern uses these theory symbols or terms that should not be in an SMT pattern:   Prims.op_Subtraction

And are automatically picked up by Github actions to be displayed differently in the run log and also tallied at the end of a run

In log:
image

In workflow page:
image

In fact, we can also auto-detect if we're running in a Github actions environment by looking for GITHUB_ENV, and default to this format if so. This may be more controversial so I'm separating the patches.

Another option is using --message_format json and piping all output through this filter.

#!/bin/bash

set -eu

# Call this with no arguments and feeding a build log to stdin,
# or with arguments that are filenames to buildogs.

grep '^{' "$@" | while IFS= read -r msg; do
  echo "$msg" # Always echo everything back
  level=$(jq -r .level <<< $msg)
  file=$(jq -r .range.def.file_name <<< $msg)
  # -m: do not fail if file does not exist
  file=$(realpath -m --relative-to=. "${file}")
  line=$(jq -r .range.def.start_pos.line <<< $msg)
  endLine=$(jq -r .range.def.end_pos.line <<< $msg)
  body=$(cat <<< "$msg" | jq -r '.msg | join ("; ")')
  body=$(tr '\n' ' ' <<< $body)
  if [ "${level}" == "Error" ]; then
    glevel=error
  elif [ "${level}" == "Warning" ]; then
    glevel=warning
  else
    # Info message, probably
    continue
  fi
  echo "::${glevel} file=$file,line=$line,endLine=$endLine::$body"
done

This also works fine.. but wouldn't be surprised if it's broken in some edge cases.

@mtzguido
Copy link
Member Author

I thought I could point to the CI run here to show it working, but running inside docker means we don't get GITHUB_ENV.

@mtzguido
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant