Files
nvidia-nemo--speech/.github/workflows/code-linting.yml
T
wehub-resource-sync ba4be087d5
CICD NeMo / cicd-main-unit-tests (push) Blocked by required conditions
CICD NeMo / cicd-main-speech (push) Blocked by required conditions
CICD NeMo / cicd-test-container-build (push) Blocked by required conditions
CICD NeMo / cicd-import-tests (push) Blocked by required conditions
CICD NeMo / L0_Setup_Test_Data_And_Models (push) Blocked by required conditions
CICD NeMo / Nemo_CICD_Test (push) Blocked by required conditions
CICD NeMo / Coverage (e2e) (push) Blocked by required conditions
CICD NeMo / Coverage (unit-test) (push) Blocked by required conditions
CodeQL / Analyze (python) (push) Waiting to run
Create PR to main with cherry-pick from release / cherry-pick (push) Failing after 0s
CICD NeMo / pre-flight (push) Failing after 0s
CICD NeMo / configure (push) Has been skipped
Build, validate, and release Neural Modules / pre-flight (push) Failing after 1s
CICD NeMo / code-linting (push) Has been skipped
CICD NeMo / cicd-wait-in-queue (push) Waiting to run
Build, validate, and release Neural Modules / release (push) Has been skipped
Build, validate, and release Neural Modules / release-summary (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:28:58 +08:00

179 lines
5.7 KiB
YAML

name: PyLint and flake8 linting
on:
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
workflow_call:
inputs:
skip_docs:
required: false
default: 'false'
type: string
skip_linting:
required: false
default: 'false'
type: string
jobs:
linting:
name: "Domain: ${{ matrix.domain }}"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
domain: [speech, other]
env:
DOMAIN: ${{ matrix.domain }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Get PR info
id: get-pr-info
if: startsWith(github.ref, 'refs/heads/pull-request/')
uses: nv-gha-runners/get-pr-info@main
- name: Select filter
id: filter
run: |
if [[ "$DOMAIN" == "speech" ]]; then
FILTER=$(jq -crn '[
"nemo/collections/common/data/lhotse/*.py",
"nemo/collections/asr/**/*.py",
"nemo/collections/tts/**/*.py",
"nemo/collections/audio/**/*.py",
"nemo/collections/multimodal/speech_llm/**/*.py",
"nemo/collections/speechlm/**/*.py",
"nemo/collections/speechlm2/**/*.py"
] | join(",")')
else
FILTER=$(jq -crn '[
"nemo/**/*.py",
"!nemo/collections/common/data/lhotse/*.py",
"!nemo/collections/asr/**/*.py",
"!nemo/collections/tts/**/*.py",
"!nemo/collections/audio/**/*.py",
"!nemo/collections/multimodal/speech_llm/**/*.py",
"!nemo/collections/speechlm/**/*.py",
"!nemo/collections/speechlm2/**/*.py",
"!nemo/export/**/*.py"
] | join(",")')
fi
echo "main=$FILTER" | tee -a "$GITHUB_OUTPUT"
- name: Get changed files
id: changed-files
uses: step-security/changed-files@v45.0.1
with:
sha: ${{ github.sha }}
base_sha: ${{ fromJSON(steps.get-pr-info.outputs.pr-info || '{}').base.sha || github.event.pull_request.base.sha }}
files: ${{ steps.filter.outputs.main }}
files_separator: ","
separator: " "
- name: Run PyLint
id: pylint
env:
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
SKIP_DOCS: ${{ inputs.skip_docs == 'true' || contains(github.event.pull_request.labels.*.name, 'skip-docs') }}
SKIP_LINTING: ${{ inputs.skip_linting == 'true' || contains(github.event.pull_request.labels.*.name, 'skip-linting') }}
run: |
if [[ -z "$CHANGED_FILES" ]]; then
echo Nothing to lint.
echo "exit-code=0" | tee -a "$GITHUB_OUTPUT"
exit 0
fi
if [[ $SKIP_DOCS == true ]]; then
ADDITIONAL_PYLINT_ARGS="--disable=C0115,C0116"
else
ADDITIONAL_PYLINT_ARGS=""
fi
if [[ $SKIP_LINTING == true ]]; then
ADDITIONAL_PYLINT_ARGS="--exit-zero"
fi
pip install pylint
set +e
pylint $ADDITIONAL_PYLINT_ARGS --output "pylintrc.$DOMAIN.txt" --rcfile ".pylintrc.$DOMAIN" ${CHANGED_FILES[@]}
echo "exit-code=$?" | tee -a "$GITHUB_OUTPUT"
- name: Run flake8
id: flake8
env:
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
SKIP_LINTING: ${{ inputs.skip_linting == 'true' || contains(github.event.pull_request.labels.*.name, 'skip-linting') }}
run: |
if [[ -z "$CHANGED_FILES" ]]; then
echo Nothing to lint.
echo "exit-code=0" | tee -a "$GITHUB_OUTPUT"
exit 0
fi
if [[ $SKIP_LINTING == true ]]; then
ADDITIONAL_FLAKE8_ARGS="--exit-zero"
else
ADDITIONAL_FLAKE8_ARGS=""
fi
pip install flake8
set +e
flake8 $ADDITIONAL_FLAKE8_ARGS --output "flake8.$DOMAIN.txt" --config ".flake8.$DOMAIN" ${CHANGED_FILES[@]}
echo "exit-code=$?" | tee -a "$GITHUB_OUTPUT"
- name: Summary
env:
PYLINT: ${{ steps.pylint.outputs.exit-code == 0 }}
FLAKE8: ${{ steps.flake8.outputs.exit-code == 0 }}
run: |
if [[ "$PYLINT" != "true" ]]; then
echo "Pylint output:" | tee -a $GITHUB_STEP_SUMMARY
echo '```' | tee -a $GITHUB_STEP_SUMMARY
cat pylintrc.$DOMAIN.txt | tee -a $GITHUB_STEP_SUMMARY
echo '```' | tee -a $GITHUB_STEP_SUMMARY
fi
if [[ "$FLAKE8" != "true" ]]; then
echo "Flake8 output:" | tee -a $GITHUB_STEP_SUMMARY
echo '```' | tee -a $GITHUB_STEP_SUMMARY
cat flake8.$DOMAIN.txt | tee -a $GITHUB_STEP_SUMMARY
echo '```' | tee -a $GITHUB_STEP_SUMMARY
fi
if [[ "$PYLINT" != "true" || "$FLAKE8" != "true" ]]; then
echo "The following directories got scanned:" | tee -a $GITHUB_STEP_SUMMARY
echo '```' | tee -a $GITHUB_STEP_SUMMARY
echo ${{ steps.filter.outputs.main }} | tee -a $GITHUB_STEP_SUMMARY
echo '```' | tee -a $GITHUB_STEP_SUMMARY
exit 1
fi
Nemo_Linting_Test:
needs: linting
runs-on: ubuntu-latest
if: always()
steps:
- name: Main
env:
RESULTS: ${{ toJson(needs.linting) }}
run: |
RESULT=$(echo "$RESULTS" | jq -r '.result')
if [[ "$RESULT" == "success" ]]; then
echo "All passed."
exit 0
else
echo "Some linting domains failed."
exit 1
fi