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

Merged
merged 3 commits into from
Jan 10, 2025

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

@mtzguido mtzguido force-pushed the github_errs branch 3 times, most recently from dea4be6 to 168785d Compare January 10, 2025 07:18
@mtzguido
Copy link
Member Author

I removed the autodetection from this PR as I think it may need a bit more discussion, but I'm merging the rest so it can be used explicitly.

@mtzguido mtzguido enabled auto-merge January 10, 2025 16:21
@mtzguido mtzguido added this pull request to the merge queue Jan 10, 2025
Merged via the queue into FStarLang:master with commit bc1b12e Jan 10, 2025
11 checks passed
@mtzguido mtzguido deleted the github_errs branch January 10, 2025 17:33
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