Github action template for Python based projects

· 2 min

Five traits that almost all the GitHub Action workflows in my Python projects share are:

  • If a new workflow is triggered while the previous one is running, the first one will get canceled.
  • The CI is triggered every day at UTC 1.
  • Tests and the lint-checkers are run on Ubuntu and MacOS against multiple Python versions.
  • Pip dependencies are cached.
  • Dependencies, including the Actions dependencies are automatically updated via Dependabot.

I use pip-tools for managing dependencies in applications and setuptools setup.py combo for managing dependencies in libraries. Here’s an annotated version of the template action syntax:

Running Python linters with pre-commit hooks

· 4 min

Pre-commit hooks can be a neat way to run automated ad-hoc tasks before submitting a new git commit. These tasks may include linting, trimming trailing whitespaces, running code formatter before code reviews etc. Let’s see how multiple Python linters and formatters can be applied automatically before each commit to impose strict conformity on your codebase.

To keep my sanity, I only use three linters in all of my python projects: