我是否可以在Google构建中集成代码链接生成步骤,特别是Pylint,而任何得分低于8分的代码都无法构建?
我的CICD设置将代码从Github移动到(Airflow) GCS。
发布于 2021-11-11 13:11:44
快速回答
您可以在其他构建步骤之前添加一个步骤,就像运行单元测试一样,并在其中执行Pylint命令,其中有@Pierre.Sassoulas提到的fail-under选项,因此,如果在一定分数下失败,构建过程将停止(即,如果小于8.0,则失败)。
例如:
# Build step to run pylint on my prod.py file.
# It will stop the process if the score is less than 8.0.
- name: python
entrypoint: python
args: ["-m", "pylint", "prod.py", "--fail-under=8.0"]示例
作为参考,我在这篇文章的启发下,使用这篇文章做了一个小的运行示例
cloudbuild.yaml
steps:
# Install dependencies
- name: python
entrypoint: pip3
args: ["install", "-r", "./requirements.txt", "--user"]
# Build step to run pylint on my prod.py file.
# It will stop the process if the score is less than 8.0.
- name: python
entrypoint: python
args: ["-m", "pylint", "prod.py", "--fail-under=8.0"]
# Yay!
- name: 'bash'
args: ['echo', 'Success!']FastAPI 样本代码
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}结果(失败):
Starting Step #1
Step #1: Already have image (with digest): python
Step #1: ************* Module prod
Step #1: prod.py:1:0: C0114: Missing module docstring (missing-module-docstring)
Step #1: prod.py:4:0: C0116: Missing function or method docstring (missing-function-docstring)
Step #1:
Step #1: -----------------------------------
Step #1: Your code has been rated at 5.00/10
Step #1:
Finished Step #1
2021/11/11 12:29:23 Step Step #1 finished
2021/11/11 12:29:23 status changed to "ERROR"
ERROR
ERROR: build step 1 "python" failed: exit status 16
2021/11/11 12:29:23 Build finished with ERROR status现在,修改示例代码:
"""
Basic API taken from https://fastapi.tiangolo.com/tutorial/first-steps/
"""
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
"""
Top level endpoint to test server
"""
return {"message": "Hello World"}结果(成功):
Starting Step #1
Step #1: Already have image (with digest): python
Step #1:
Step #1: ------------------------------------
Step #1: Your code has been rated at 10.00/10
Step #1:
Finished Step #1
2021/11/11 12:43:13 Step Step #1 finished
Starting Step #2
Step #2: Pulling image: bash
Step #2: Using default tag: latest
.
.
.
Step #2: Success!
Finished Step #2
2021/11/11 12:43:15 Step Step #2 finished
2021/11/11 12:43:15 status changed to "DONE"
DONE发布于 2021-11-09 10:29:17
任何得分低于8分的代码都无法生成?
我不知道Google构建部分,但是您可以在启动pylint时使用选项 (缺省值为10.0)
https://stackoverflow.com/questions/69896311
复制相似问题