Using Github problem matchers to catch warnings early

Github semi-recently introduced a new feature to Action workflows that allows you to install little regex handlers for logs that create pull request review comments for matches. These are called problem matchers and are great for prominently surfacing things like linter failures, warnings and other issues that won’t necessarily fail the build. They seem to be a port of an existing feature in VSCode extensions: https://code.visualstudio.com/docs/editor/tasks#_processing-task-output-with-problem-matchers

I’m particularly excited about the compiler warnings matchers since they seem to sneak in and then every once in a while someone makes a pull request to remove them. People that develop on Linux don’t tend to check the Windows warnings and vica-versa, and as long as the CI results are green no one really digs into the logs. This would allow them to be caught early in the review process.

@csabella suggested I post about this to gauge interest and make it more discover-able. I’ve created three pull requests with problem matchers for:

Sphinx

Catches errors and warnings from sphinx documentation builds. As a bonus this allows for a workflow whereby people making and reviewing documentation pull requests can fully work entirely from Github. Between this problem matcher and the netlify doc preview, we can be fairly sure the changes are good to go. (This one is not as important since https://github.com/python/cpython/commit/6aabb63d96845b3cb207d28d40bf0b78e171be75 which adds -W, warnings-as-errors to the sphinx build but still provides errors in a more convenient place).

GCC

Catches warnings and errors generated from gcc. This is a straight forward port from the vscode-cpptools matcher.

MSVC

This catches warnings and errors generated by our Windows builds. It is pulled straight out vscode itself.

Implementation

I’ve created three Github workflow actions on the marketplace for each of these matchers:

This allows them to be used by the wider Github community and hopefully have a wider set of eyes looking at them to catch any issues.

Despite the error formats being relatively stable, relying on me to maintain the actions might be a little queasy for some of the core developers. In this case, it’s possible to commit the matchers (here’s an example of one) under the .github folder on our repo and just use the local versions, I’d be happy to change over to that method if people feel necessary.

4 Likes

I think this sounds good. If it’s really just the matcher .json files that would need to be added to the .github folder, I think I would opt for that just for discoverability. I’m not concerned about maintenance of these matchers; they appear simple enough to likely not need much if any for quite some time.

However, if these warnings are going to start appearing on every pull request, we likely want to fix the any existing warnings and enable any warnings-as-errors options on the CI whose output these checks parse when we add them since otherwise people are likely to be confused about why their typo fix in a docstring is causing build warnings :slight_smile:

I think this would be a great improvement. I have fixed many Windows and Linux compiler warnings in the past. I agree with @zware in that I think I would prefer to have these JSON files living in the repo.

@ammaraskar Could you make a PR adding the relevant files so we know how many warnings we have currently? Feel free to add me as a reviewer to such pr :wink:

Would you want to check the difference between master’s warnings and the current PR’s warnings and only put the new warnings in the PR’s comment?

An implementation is to commit (all of) the warnings as a text file with every PR, then the current PR can run diff on that file to get the text to display in the comment

Sorry, I was kinda being hand-wavey when I said comments, in reality they’re Github check annotations: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-status-checks#types-of-status-checks-on-github

This is actually handled in a much nicer way by Github whereby existing warnings in files that you didn’t touch show up like this:

That doesn’t mean we shouldn’t try to quash any existing warnings but it does make the experience not feel overwhelming for new contributors.

My next steps will involve creating PRs checking in the matcher JSON files.

Alright I’ve updated all three PRs to check-in the matcher files:

The only warnings are from the MSVC build, which is what I anticipated since most core-devs exclusively build on Linux. You can see all the warnings for the MSVC build on the bottom, Unchanged files with check annotations part of https://github.com/python/cpython/pull/18532/files