|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | | -name: PyLint and flake8 linting |
| 14 | +name: Code linting |
15 | 15 |
|
16 | 16 | on: |
17 | 17 | pull_request: |
18 | 18 | types: [opened, synchronize, reopened, labeled, unlabeled] |
19 | 19 | workflow_call: |
20 | 20 |
|
21 | 21 | jobs: |
22 | | - linting: |
| 22 | + lint-check: |
| 23 | + name: Lint check |
23 | 24 | runs-on: ubuntu-latest |
24 | 25 | steps: |
25 | | - - name: Checkout |
| 26 | + - name: Checkout repository |
26 | 27 | uses: actions/checkout@v4 |
27 | | - |
28 | | - - name: Install uv |
29 | | - uses: astral-sh/setup-uv@v5 |
30 | | - with: |
31 | | - version: "0.7.10" |
32 | | - |
33 | | - - name: Install dependencies |
34 | | - run: | |
35 | | - uv sync --only-group test |
36 | | -
|
37 | | - - name: Get changed files |
38 | | - id: changed-files |
39 | | - uses: step-security/[email protected] |
40 | 28 | with: |
41 | | - files: | |
42 | | - **/*.py |
43 | | -
|
44 | | - - name: Run PyLint |
45 | | - id: pylint |
46 | | - env: |
47 | | - CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} |
48 | | - SKIP_DOCS: ${{ contains(github.event.pull_request.labels.*.name, 'skip-docs') }} |
49 | | - SKIP_LINTING: ${{ contains(github.event.pull_request.labels.*.name, 'skip-linting') }} |
50 | | - run: | |
51 | | - if [[ -z "$CHANGED_FILES" ]]; then |
52 | | - echo Nothing to lint. |
53 | | - echo "exit-code=0" | tee -a "$GITHUB_OUTPUT" |
54 | | - exit 0 |
55 | | - fi |
56 | | -
|
57 | | - if [[ $SKIP_DOCS == true ]]; then |
58 | | - ADDITIONAL_PYLINT_ARGS="--disable=C0115,C0116" |
59 | | - else |
60 | | - ADDITIONAL_PYLINT_ARGS="" |
61 | | - fi |
62 | | -
|
63 | | - if [[ $SKIP_LINTING == true ]]; then |
64 | | - ADDITIONAL_PYLINT_ARGS="--exit-zero" |
65 | | - fi |
66 | | -
|
67 | | - set +e |
68 | | - uv run --only-group test pylint $ADDITIONAL_PYLINT_ARGS --output "pylintrc.txt" --rcfile ".pylintrc" ${CHANGED_FILES[@]} |
69 | | - echo "exit-code=$?" | tee -a "$GITHUB_OUTPUT" |
| 29 | + submodules: 'recursive' |
70 | 30 |
|
71 | | - - name: Run flake8 |
72 | | - id: flake8 |
73 | | - env: |
74 | | - CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} |
75 | | - SKIP_LINTING: ${{ contains(github.event.pull_request.labels.*.name, 'skip-linting') }} |
| 31 | + - name: Check lint |
76 | 32 | run: | |
77 | | - if [[ -z "$CHANGED_FILES" ]]; then |
78 | | - echo Nothing to lint. |
79 | | - echo "exit-code=0" | tee -a "$GITHUB_OUTPUT" |
80 | | - exit 0 |
81 | | - fi |
82 | | -
|
83 | | - if [[ $SKIP_LINTING == true ]]; then |
84 | | - ADDITIONAL_FLAKE8_ARGS="--exit-zero" |
85 | | - else |
86 | | - ADDITIONAL_FLAKE8_ARGS="" |
87 | | - fi |
88 | | -
|
89 | | - set +e |
90 | | - uv run --only-group test flake8 $ADDITIONAL_FLAKE8_ARGS --output "flake8.txt" --config ".flake8" ${CHANGED_FILES[@]} |
91 | | - echo "exit-code=$?" | tee -a "$GITHUB_OUTPUT" |
92 | | -
|
93 | | - - name: Run isort |
94 | | - id: isort |
95 | | - env: |
96 | | - CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} |
97 | | - SKIP_LINTING: ${{ contains(github.event.pull_request.labels.*.name, 'skip-linting') }} |
98 | | - run: | |
99 | | - if [[ -z "$CHANGED_FILES" ]]; then |
100 | | - echo Nothing to lint. |
101 | | - echo "exit-code=0" | tee -a "$GITHUB_OUTPUT" |
102 | | - exit 0 |
103 | | - fi |
104 | | -
|
105 | | - set +e |
106 | | - uv run --only-group test isort --check-only --diff ${CHANGED_FILES[@]} > isort.txt 2>&1 |
107 | | - ISORT_EXIT_CODE=$? |
108 | | -
|
109 | | - if [[ $SKIP_LINTING == true ]]; then |
110 | | - echo "exit-code=0" | tee -a "$GITHUB_OUTPUT" |
111 | | - else |
112 | | - echo "exit-code=$ISORT_EXIT_CODE" | tee -a "$GITHUB_OUTPUT" |
113 | | - fi |
114 | | -
|
115 | | - - name: Run black |
116 | | - id: black |
117 | | - env: |
118 | | - CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} |
119 | | - SKIP_LINTING: ${{ contains(github.event.pull_request.labels.*.name, 'skip-linting') }} |
120 | | - run: | |
121 | | - if [[ -z "$CHANGED_FILES" ]]; then |
122 | | - echo Nothing to lint. |
123 | | - echo "exit-code=0" | tee -a "$GITHUB_OUTPUT" |
124 | | - exit 0 |
125 | | - fi |
126 | | -
|
127 | | - set +e |
128 | | - uv run --only-group test black --check --diff ${CHANGED_FILES[@]} > black.txt 2>&1 |
129 | | - BLACK_EXIT_CODE=$? |
130 | | -
|
131 | | - if [[ $SKIP_LINTING == true ]]; then |
132 | | - echo "exit-code=0" | tee -a "$GITHUB_OUTPUT" |
133 | | - else |
134 | | - echo "exit-code=$BLACK_EXIT_CODE" | tee -a "$GITHUB_OUTPUT" |
135 | | - fi |
136 | | -
|
137 | | - - name: Summary |
138 | | - env: |
139 | | - PYLINT: ${{ steps.pylint.outputs.exit-code == 0 }} |
140 | | - FLAKE8: ${{ steps.flake8.outputs.exit-code == 0 }} |
141 | | - ISORT: ${{ steps.isort.outputs.exit-code == 0 }} |
142 | | - BLACK: ${{ steps.black.outputs.exit-code == 0 }} |
143 | | - SKIP_LINTING: ${{ contains(github.event.pull_request.labels.*.name, 'skip-linting') }} |
144 | | - run: | |
145 | | - if [[ "$PYLINT" != "true" ]]; then |
146 | | - echo "Pylint output:" | tee -a $GITHUB_STEP_SUMMARY |
147 | | -
|
148 | | - echo '```' | tee -a $GITHUB_STEP_SUMMARY |
149 | | - cat pylintrc.txt | tee -a $GITHUB_STEP_SUMMARY |
150 | | - echo '```' | tee -a $GITHUB_STEP_SUMMARY |
151 | | - fi |
152 | | -
|
153 | | - if [[ "$FLAKE8" != "true" ]]; then |
154 | | - echo "Flake8 output:" | tee -a $GITHUB_STEP_SUMMARY |
155 | | -
|
156 | | - echo '```' | tee -a $GITHUB_STEP_SUMMARY |
157 | | - cat flake8.txt | tee -a $GITHUB_STEP_SUMMARY |
158 | | - echo '```' | tee -a $GITHUB_STEP_SUMMARY |
159 | | - fi |
160 | | -
|
161 | | - if [[ "$ISORT" != "true" ]]; then |
162 | | - echo "isort output:" | tee -a $GITHUB_STEP_SUMMARY |
163 | | -
|
164 | | - echo '```' | tee -a $GITHUB_STEP_SUMMARY |
165 | | - cat isort.txt | tee -a $GITHUB_STEP_SUMMARY |
166 | | - echo '```' | tee -a $GITHUB_STEP_SUMMARY |
167 | | - fi |
168 | | -
|
169 | | - if [[ "$BLACK" != "true" ]]; then |
170 | | - echo "black output:" | tee -a $GITHUB_STEP_SUMMARY |
171 | | -
|
172 | | - echo '```' | tee -a $GITHUB_STEP_SUMMARY |
173 | | - cat black.txt | tee -a $GITHUB_STEP_SUMMARY |
174 | | - echo '```' | tee -a $GITHUB_STEP_SUMMARY |
175 | | - fi |
176 | | -
|
177 | | - if [[ "$PYLINT" != "true" || "$FLAKE8" != "true" || "$ISORT" != "true" || "$BLACK" != "true" ]]; then |
178 | | - echo "The following directories got scanned:" | tee -a $GITHUB_STEP_SUMMARY |
179 | | -
|
180 | | - echo '```' | tee -a $GITHUB_STEP_SUMMARY |
181 | | - echo ${{ steps.filter.outputs.main }} | tee -a $GITHUB_STEP_SUMMARY |
182 | | - echo '```' | tee -a $GITHUB_STEP_SUMMARY |
183 | | -
|
184 | | - exit 1 |
185 | | - fi |
186 | | -
|
187 | | - Nemo_Linting_Test: |
188 | | - needs: linting |
189 | | - runs-on: ubuntu-latest |
190 | | - if: always() |
191 | | - steps: |
192 | | - - name: Main |
193 | | - env: |
194 | | - RESULTS: ${{ toJson(needs.linting) }} |
195 | | - run: | |
196 | | - RESULT=$(echo "$RESULTS" | jq -r '.result') |
197 | | -
|
198 | | - if [[ "$RESULT" == "success" ]]; then |
199 | | - echo "All passed." |
200 | | - exit 0 |
201 | | - else |
202 | | - echo "Some linting domains failed." |
203 | | - exit 1 |
204 | | - fi |
| 33 | + pip install pre-commit==3.6.0 |
| 34 | + pre-commit install |
| 35 | + pre-commit run --all-files --show-diff-on-failure --color=always |
0 commit comments