|
1 | | -# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. |
2 | | -# |
3 | | -# Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | -# you may not use this file except in compliance with the License. |
5 | | -# You may obtain a copy of the License at |
6 | | -# |
7 | | -# http://www.apache.org/licenses/LICENSE-2.0 |
8 | | -# |
9 | | -# Unless required by applicable law or agreed to in writing, software |
10 | | -# distributed under the License is distributed on an "AS IS" BASIS, |
11 | | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | -# See the License for the specific language governing permissions and |
13 | | -# limitations under the License. |
14 | | -name: Code linting |
| 1 | +name: PyLint and flake8 linting |
15 | 2 |
|
16 | 3 | on: |
17 | 4 | pull_request: |
18 | 5 | types: [opened, synchronize, reopened, labeled, unlabeled] |
19 | 6 | workflow_call: |
20 | 7 |
|
21 | 8 | jobs: |
22 | | - lint-check: |
23 | | - name: Lint check |
| 9 | + linting: |
| 10 | + name: "Domain: ${{ matrix.domain }}" |
24 | 11 | runs-on: ubuntu-latest |
| 12 | + strategy: |
| 13 | + fail-fast: false |
| 14 | + matrix: |
| 15 | + domain: [speech, other] |
| 16 | + env: |
| 17 | + DOMAIN: ${{ matrix.domain }} |
25 | 18 | steps: |
26 | | - - name: Checkout repository |
| 19 | + - name: Checkout |
27 | 20 | uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Select filter |
| 23 | + id: filter |
| 24 | + run: | |
| 25 | + if [[ "$DOMAIN" == "speech" ]]; then |
| 26 | + FILTER=$(jq -crn '[ |
| 27 | + "nemo/collections/common/data/lhotse/*.py", |
| 28 | + "nemo/collections/asr/**/*.py", |
| 29 | + "nemo/collections/tts/**/*.py", |
| 30 | + "nemo/collections/audio/**/*.py", |
| 31 | + "nemo/collections/multimodal/speech_llm/**/*.py", |
| 32 | + "nemo/collections/speechlm/**/*.py", |
| 33 | + "nemo/collections/speechlm2/**/*.py" |
| 34 | + ] | join(",")') |
| 35 | +
|
| 36 | + else |
| 37 | + FILTER=$(jq -crn '[ |
| 38 | + "nemo/**/*.py", |
| 39 | + "!nemo/collections/common/data/lhotse/*.py", |
| 40 | + "!nemo/collections/asr/**/*.py", |
| 41 | + "!nemo/collections/tts/**/*.py", |
| 42 | + "!nemo/collections/audio/**/*.py", |
| 43 | + "!nemo/collections/multimodal/speech_llm/**/*.py", |
| 44 | + "!nemo/collections/speechlm/**/*.py", |
| 45 | + "!nemo/collections/speechlm2/**/*.py" |
| 46 | + ] | join(",")') |
| 47 | + fi |
| 48 | +
|
| 49 | + echo "main=$FILTER" | tee -a "$GITHUB_OUTPUT" |
| 50 | +
|
| 51 | + - name: Get changed files |
| 52 | + id: changed-files |
| 53 | + uses: step-security/changed-files@v45.0.1 |
28 | 54 | with: |
29 | | - submodules: 'recursive' |
| 55 | + files: ${{ steps.filter.outputs.main }} |
| 56 | + files_separator: "," |
| 57 | + separator: " " |
| 58 | + |
| 59 | + - name: Run PyLint |
| 60 | + id: pylint |
| 61 | + env: |
| 62 | + CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} |
| 63 | + SKIP_DOCS: ${{ contains(github.event.pull_request.labels.*.name, 'skip-docs') }} |
| 64 | + SKIP_LINTING: ${{ contains(github.event.pull_request.labels.*.name, 'skip-linting') }} |
| 65 | + run: | |
| 66 | + if [[ -z "$CHANGED_FILES" ]]; then |
| 67 | + echo Nothing to lint. |
| 68 | + echo "exit-code=0" | tee -a "$GITHUB_OUTPUT" |
| 69 | + exit 0 |
| 70 | + fi |
| 71 | +
|
| 72 | + if [[ $SKIP_DOCS == true ]]; then |
| 73 | + ADDITIONAL_PYLINT_ARGS="--disable=C0115,C0116" |
| 74 | + else |
| 75 | + ADDITIONAL_PYLINT_ARGS="" |
| 76 | + fi |
| 77 | +
|
| 78 | + if [[ $SKIP_LINTING == true ]]; then |
| 79 | + ADDITIONAL_PYLINT_ARGS="--exit-zero" |
| 80 | + fi |
| 81 | +
|
| 82 | + pip install pylint |
| 83 | + set +e |
| 84 | + pylint $ADDITIONAL_PYLINT_ARGS --output "pylintrc.$DOMAIN.txt" --rcfile ".pylintrc.$DOMAIN" ${CHANGED_FILES[@]} |
| 85 | + echo "exit-code=$?" | tee -a "$GITHUB_OUTPUT" |
| 86 | +
|
| 87 | + - name: Run flake8 |
| 88 | + id: flake8 |
| 89 | + env: |
| 90 | + CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} |
| 91 | + SKIP_LINTING: ${{ contains(github.event.pull_request.labels.*.name, 'skip-linting') }} |
| 92 | + run: | |
| 93 | + if [[ -z "$CHANGED_FILES" ]]; then |
| 94 | + echo Nothing to lint. |
| 95 | + echo "exit-code=0" | tee -a "$GITHUB_OUTPUT" |
| 96 | + exit 0 |
| 97 | + fi |
| 98 | +
|
| 99 | + if [[ $SKIP_LINTING == true ]]; then |
| 100 | + ADDITIONAL_FLAKE8_ARGS="--exit-zero" |
| 101 | + else |
| 102 | + ADDITIONAL_FLAKE8_ARGS="" |
| 103 | + fi |
30 | 104 |
|
31 | | - - name: Check lint |
| 105 | + pip install flake8 |
| 106 | + set +e |
| 107 | + flake8 $ADDITIONAL_FLAKE8_ARGS --output "flake8.$DOMAIN.txt" --config ".flake8.$DOMAIN" ${CHANGED_FILES[@]} |
| 108 | + echo "exit-code=$?" | tee -a "$GITHUB_OUTPUT" |
| 109 | +
|
| 110 | + - name: Summary |
| 111 | + env: |
| 112 | + PYLINT: ${{ steps.pylint.outputs.exit-code == 0 }} |
| 113 | + FLAKE8: ${{ steps.flake8.outputs.exit-code == 0 }} |
32 | 114 | run: | |
33 | | - pip install pre-commit==3.6.0 |
34 | | - pre-commit install |
35 | | - pre-commit run --all-files --show-diff-on-failure --color=always |
| 115 | +
|
| 116 | + if [[ "$PYLINT" != "true" ]]; then |
| 117 | + echo "Pylint output:" | tee -a $GITHUB_STEP_SUMMARY |
| 118 | +
|
| 119 | + echo '```' | tee -a $GITHUB_STEP_SUMMARY |
| 120 | + cat pylintrc.$DOMAIN.txt | tee -a $GITHUB_STEP_SUMMARY |
| 121 | + echo '```' | tee -a $GITHUB_STEP_SUMMARY |
| 122 | + fi |
| 123 | +
|
| 124 | + if [[ "$FLAKE8" != "true" ]]; then |
| 125 | + echo "Flake8 output:" | tee -a $GITHUB_STEP_SUMMARY |
| 126 | +
|
| 127 | + echo '```' | tee -a $GITHUB_STEP_SUMMARY |
| 128 | + cat flake8.$DOMAIN.txt | tee -a $GITHUB_STEP_SUMMARY |
| 129 | + echo '```' | tee -a $GITHUB_STEP_SUMMARY |
| 130 | + fi |
| 131 | +
|
| 132 | + if [[ "$PYLINT" != "true" || "$FLAKE8" != "true" ]]; then |
| 133 | + echo "The following directories got scanned:" | tee -a $GITHUB_STEP_SUMMARY |
| 134 | +
|
| 135 | + echo '```' | tee -a $GITHUB_STEP_SUMMARY |
| 136 | + echo ${{ steps.filter.outputs.main }} | tee -a $GITHUB_STEP_SUMMARY |
| 137 | + echo '```' | tee -a $GITHUB_STEP_SUMMARY |
| 138 | +
|
| 139 | + exit 1 |
| 140 | + fi |
| 141 | +
|
| 142 | + Nemo_Linting_Test: |
| 143 | + needs: linting |
| 144 | + runs-on: ubuntu-latest |
| 145 | + if: always() |
| 146 | + steps: |
| 147 | + - name: Main |
| 148 | + env: |
| 149 | + RESULTS: ${{ toJson(needs.linting) }} |
| 150 | + run: | |
| 151 | + RESULT=$(echo "$RESULTS" | jq -r '.result') |
| 152 | +
|
| 153 | + if [[ "$RESULT" == "success" ]]; then |
| 154 | + echo "All passed." |
| 155 | + exit 0 |
| 156 | + else |
| 157 | + echo "Some linting domains failed." |
| 158 | + exit 1 |
| 159 | + fi |
0 commit comments