TensorRT-LLMs/scripts/release_check.py
tburt-nv 5616c0d232
add precommit check to github actions (#3129)
Signed-off-by: Tyler Burt <195370667+tburt-nv@users.noreply.github.com>
2025-04-11 06:40:53 +08:00

71 lines
2.2 KiB
Python

#!/usr/bin/env python3
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import subprocess as sp
import sys
def run_cmd(cmd):
"""Run a command and return output, raising error by default if command fails"""
print(f"Running command: {cmd}")
result = sp.run(cmd,
shell=True,
stdout=sp.PIPE,
text=True,
stderr=sp.STDOUT)
if result.returncode != 0:
print(f"Failing command output:\n{result.stdout}")
sys.exit(1)
return result
def main():
# Install pre-commit and bandit from requirements-dev.txt
with open("requirements-dev.txt") as f:
reqs = f.readlines()
pre_commit_req = next(line for line in reqs if "pre-commit" in line)
bandit_req = next(line for line in reqs if "bandit" in line)
run_cmd(f"pip3 install {pre_commit_req.strip()}")
run_cmd(f"pip3 install {bandit_req.strip()}")
# Install pre-commit hooks
run_cmd("pre-commit install")
# Run pre-commit on all files
run_cmd("pre-commit run -a --show-diff-on-failure")
# Run bandit security checks
bandit_output = run_cmd(
"bandit --configfile scripts/bandit.yaml -r tensorrt_llm").stdout
print(f"Bandit output:\n{bandit_output}")
# Check bandit results
if "Total lines skipped (#nosec): 0" not in bandit_output:
print("Error: Found #nosec annotations in code")
sys.exit(1)
if "Issue:" in bandit_output:
print("Error: Bandit found security issues")
sys.exit(1)
print("pre-commit and bandit checks passed")
if __name__ == "__main__":
main()