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

Add CodeQL workflow for GitHub code scanning #467

Merged
merged 10 commits into from
Nov 24, 2022
Merged

Conversation

lgtm-com[bot]
Copy link

@lgtm-com lgtm-com bot commented Nov 16, 2022

Hi crate/crate-python!

This is a one-off automatically generated pull request from LGTM.com 🤖. You might have heard that we’ve integrated LGTM’s underlying CodeQL analysis engine natively into GitHub. The result is GitHub code scanning!

With LGTM fully integrated into code scanning, we are focused on improving CodeQL within the native GitHub code scanning experience. In order to take advantage of current and future improvements to our analysis capabilities, we suggest you enable code scanning on your repository. Please take a look at our blog post for more information.

This pull request enables code scanning by adding an auto-generated codeql.yml workflow file for GitHub Actions to your repository — take a look! We tested it before opening this pull request, so all should be working ✔️. In fact, you might already have seen some alerts appear on this pull request!

Where needed and if possible, we’ve adjusted the configuration to the needs of your particular repository. But of course, you should feel free to tweak it further! Check this page for detailed documentation.

Questions? Check out the FAQ below!

FAQ

Click here to expand the FAQ section

How often will the code scanning analysis run?

By default, code scanning will trigger a scan with the CodeQL engine on the following events:

  • On every pull request — to flag up potential security problems for you to investigate before merging a PR.
  • On every push to your default branch and other protected branches — this keeps the analysis results on your repository’s Security tab up to date.
  • Once a week at a fixed time — to make sure you benefit from the latest updated security analysis even when no code was committed or PRs were opened.

What will this cost?

Nothing! The CodeQL engine will run inside GitHub Actions, making use of your unlimited free compute minutes for public repositories.

What types of problems does CodeQL find?

The CodeQL engine that powers GitHub code scanning is the exact same engine that powers LGTM.com. The exact set of rules has been tweaked slightly, but you should see almost exactly the same types of alerts as you were used to on LGTM.com: we’ve enabled the security-and-quality query suite for you.

How do I upgrade my CodeQL engine?

No need! New versions of the CodeQL analysis are constantly deployed on GitHub.com; your repository will automatically benefit from the most recently released version.

The analysis doesn’t seem to be working

If you get an error in GitHub Actions that indicates that CodeQL wasn’t able to analyze your code, please follow the instructions here to debug the analysis.

How do I disable LGTM.com?

If you have LGTM’s automatic pull request analysis enabled, then you can follow these steps to disable the LGTM pull request analysis. You don’t actually need to remove your repository from LGTM.com; it will automatically be removed in the next few months as part of the deprecation of LGTM.com (more info here).

Which source code hosting platforms does code scanning support?

GitHub code scanning is deeply integrated within GitHub itself. If you’d like to scan source code that is hosted elsewhere, we suggest that you create a mirror of that code on GitHub.

How do I know this PR is legitimate?

This PR is filed by the official LGTM.com GitHub App, in line with the deprecation timeline that was announced on the official GitHub Blog. The proposed GitHub Action workflow uses the official open source GitHub CodeQL Action. If you have any other questions or concerns, please join the discussion here in the official GitHub community!

I have another question / how do I get in touch?

Please join the discussion here to ask further questions and send us suggestions!

.github/codeql.yml Outdated Show resolved Hide resolved
@amotl
Copy link
Member

amotl commented Nov 21, 2022

This patch should also remove lgtm.yml, no? Done with 672a29b.

@amotl
Copy link
Member

amotl commented Nov 21, 2022

Further analyzing the scan outcome 1.

  • Many occurrances of py/mixed-returns.
  • A number of py/empty-except occurrances.
  • Loads of py/unused-local-variable.

I think it is safe to suppress them for now, see 98e0fb9.

Footnotes

  1. https://github.com/crate/crate-python/pull/467/checks?check_run_id=9621584111

@amotl
Copy link
Member

amotl commented Nov 21, 2022

@amotl
Copy link
Member

amotl commented Nov 22, 2022

Source: https://github.com/crate/crate-python/pull/467/checks?check_run_id=9647694567


No new or fixed alerts

Warning: The base analysis for some categories could not be found. All their alerts have been reported as new.

No new or fixed alerts

View all branch alerts.

Analyses

Code scanning compared refs/heads/master with refs/pull/467/merge (commit e1d63cc) and `` (commit 4e3706e).

Category Base branch Pull request
/language:python ❓  Not found ✔️  Found for e1d63cc
No new or fixed alerts

Warning: The base analysis for some categories could not be found. All their alerts have been reported as new.
No new or fixed alerts

View all branch alerts.
Analyses

Code scanning compared refs/heads/master with refs/pull/467/merge (commit e1d63cc) and `` (commit 4e3706e).
Category Base branch Pull request
/language:python ❓  Not found ✔️  Found for e1d63cc

`zope.testrunner.run` already invokes `sys.exit`. No need to do it here.
# TODO: May be improved.
# https://codeql.github.com/codeql-query-help/python/py-unused-local-variable/
- exclude:
id: py/unused-local-variable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this easy to fix? I'd prefer not to exclude such warnings as unused variables may pollute our code...

Copy link
Member

@amotl amotl Nov 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've removed suppressing this rule. Can I ask you to inspect [1] now? I don't see any way how to suppress those occurrances in any other sensible way. However, suppressing py/unused-local-variable completely is also not sensible.

So, let's just dismiss those items like [2] as False positive interactively on the UI?

image

I think the code itself is sane.

def test_create_table_with_basic_types(self):
class User(self.Base):
__tablename__ = 'users'
string_col = sa.Column(sa.String, primary_key=True)
unicode_col = sa.Column(sa.Unicode)
text_col = sa.Column(sa.Text)
int_col = sa.Column(sa.Integer)
long_col1 = sa.Column(sa.BigInteger)
long_col2 = sa.Column(sa.NUMERIC)
bool_col = sa.Column(sa.Boolean)
short_col = sa.Column(sa.SmallInteger)
datetime_col = sa.Column(sa.DateTime)
date_col = sa.Column(sa.Date)
float_col = sa.Column(sa.Float)
double_col = sa.Column(sa.DECIMAL)
self.Base.metadata.create_all()
fake_cursor.execute.assert_called_with(
('\nCREATE TABLE users (\n\tstring_col STRING, '
'\n\tunicode_col STRING, \n\ttext_col STRING, \n\tint_col INT, '
'\n\tlong_col1 LONG, \n\tlong_col2 LONG, '
'\n\tbool_col BOOLEAN, '
'\n\tshort_col SHORT, '
'\n\tdatetime_col TIMESTAMP, \n\tdate_col TIMESTAMP, '
'\n\tfloat_col FLOAT, \n\tdouble_col DOUBLE, '
'\n\tPRIMARY KEY (string_col)\n)\n\n'),
())

[1] https://github.com/crate/crate-python/pull/467/checks?check_run_id=9668687460
[2] https://github.com/crate/crate-python/security/code-scanning/44

Copy link
Member

@amotl amotl Nov 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed with crate-workbench/codeql-evaluations#4, reported to CodeQL with github/codeql#11407.

Copy link
Member

@amotl amotl Nov 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At github/codeql#11407 (comment), it has been acknowledged as a false positive. It has been recommended to dismiss those kinds of notices manually. I will do so.

Copy link
Member

@seut seut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@amotl amotl removed the request for review from mfussenegger November 24, 2022 17:09
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.

3 participants