You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: article/article.md
+59-34Lines changed: 59 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -1,51 +1,82 @@
1
-
Linter helps and advises us about code quality by running sanity checks and displaying warnings and errors about code
2
-
smells. Also, potentially it helps to prevent bugs in a project.
1
+
Hello everyone, I am a Data Platform or DataOps Engineer at [FreshBooks](https://www.freshbooks.com/). In this article I would like to share my experience on configure best practices in CI/CD pipelines. We had a linter configuration that developers could run before submitting PR. We understand that we want to integrate that checks into our regular CI/CD pipeline. This adoption helps to eliminate potential errors, bugs, stylistic errors, and basically have the common code style across the team.
3
2
4
-
As we are in FreshBooks using GitHub, so we would like to use it as much as possible.
3
+
We are in FreshBooks using GitHub as a home for our code base, so we would like to use it as much as possible. Recently I finished this configuration so linter and its checks are now part of GitHub actions CI/CD workflow.
5
4
6
-
Recently I was involved in configuring linters as a part of CI/CD in GitHub actions.
5
+
This article has two major parts: the first one is linter configuration, and the second one is GitHub workflow configuration itself. Feel free to read all the parts, or skip some and jump into specific one you are interested in.
I would like to share how to configure it for the python project. I prepared a full [github actions python configuration demo repository](https://github.com/iamtodor/github-actions-python-demo).
11
30
12
-
We use flakeheaven as a flake8 wrapper, which is very easy to configure in one single `pyproject.toml` configuration file.
13
-
The whole `pyproject.toml` configuration file could be found in
31
+
We use flakeheaven as a flake8 wrapper, which is very easy to configure in one single `pyproject.toml`. The whole `pyproject.toml` configuration file could be found in
14
32
a [repo](https://github.com/iamtodor/github-actions-python-configuration-demo/blob/main/pyproject.toml).
Our linter requirements live in a separate file, and we don't aim to mix it with our main production requirements. Hence, linter would complain about import libraries as linter env does not have production libraries, quite obvious.
51
+
52
+
```
53
+
>>> python -m flakeheaven lint .
54
+
55
+
dags/dummy.py
56
+
3: 1 E0401 Unable to import 'airflow' (import-error) [pylint]
57
+
from airflow import DAG
58
+
^
59
+
4: 1 E0401 Unable to import 'airflow.operators.dummy_operator' (import-error) [pylint]
60
+
from airflow.operators.dummy_operator import DummyOperator
61
+
^
62
+
```
30
63
31
-
Our linter requirements live in a separate file, and we don't aim to mix it with our main production requirements.
32
-
Hence, linter could complain about import libraries as linter env does not have production libraries, quite obvious. So
33
-
we need to disable this check. We assume that the developer who writes the code and imports the libs is responsible for
34
-
the tests. So if the test does not pass it means that it's something with import or a code itself. Import checks it's
35
-
not something we would like to put as a linter job.
We assume that the developer who writes the code and imports the libs is responsible for the writing reliable tests. So if the test does not pass it means that it's something with import or a code (logic) itself. Import check is not something we would like to put as a linter job.
69
+
70
+
#### Tweaks for airflow code
40
71
41
72
To configure code for Airflow DAGs there are also a few tweaks. Here is the dummy example `dummy.py`.
The whole `py_linter.yml` config could be found in
97
-
a [repo](https://github.com/iamtodor/github-actions-python-demo/blob/main/.github/workflows/py_linter.yml). I will walk you thru it step by step.
118
+
The whole `py_linter.yml` config could be found in a [repo](https://github.com/iamtodor/github-actions-python-demo/blob/main/.github/workflows/py_linter.yml). I will walk you thru it step by step.
We are interested in running linter only when PR has `.py` files. For instance, when we update `README.md` there is no sense to run python linter.
102
125
103
126

104
127
128
+
### What files does it run against to
129
+
105
130
We are interested in running a linter only against the modified files. Let's say, we take a look at the provided repo, if I update `dags/dummy.py` I don't want to waste a time and resources running linter against `main.py`. For this purpose we use [Paths Filter GitHub Action](https://github.com/dorny/paths-filter), which is very flexible.
0 commit comments