I work with open-source & private Python projects on GitHub on a daily basis.
I use Github Actions to run my tests, linting, static type checking, and other CI/CD tasks.
The main goal is to be able to run both ruff and mypy on every pull request, and every push to the main branch.
Additionally we would want to be able to run these tools locally, with the same configuration so that we get consistent results locally & remote.
I personally love using pipenv, so in that case create/open a Pipfile in the root of your project and copy the following contents:
This basically specifies that our project has two dev dependencies of latest ruff & mypy.
In order to install these dependencies, simply run
pipenv install --dev.
As one of our goals was to have consistent results between remote & local executions, I like having a configuration file for all of the tools, which means I like having a
pyproject.toml file in the root of your project and copy the following contents:
To read more about the configurations options, refer to the respective docs:
After step 2, you should be able to run both ruff & mypy locally.
Now you will set an automatic workflow on GitHub, which will run ruff & mypy whenever a PR is opened and/or there was a push to the main branch.
Create a file
.github/workflows and copy the following contents:
If the above syntax is a bit mysterious, you can go through the syntax docs.
As soon as you will push the above file, you will see the actions being triggered.
Verify that both ruff and mypy executed successfully, and that they have consistent results with your local executions.
On GitHub, it should look like the following
Feel free to tweak this process with your own favorite tools, and if you have any questions you can reach out to me on twitter.