55 lines
1.8 KiB
YAML
55 lines
1.8 KiB
YAML
---
|
|
apiVersion: tekton.dev/v1beta1
|
|
kind: Task
|
|
metadata:
|
|
name: python-coverage
|
|
labels:
|
|
app.kubernetes.io/version: "0.1"
|
|
annotations:
|
|
tekton.dev/categories: Code Quality
|
|
tekton.dev/pipelines.minVersion: "0.12.1"
|
|
tekton.dev/tags: python, coverage
|
|
tekton.dev/displayName: python coverage
|
|
tekton.dev/platforms: "linux/amd64,linux/s390x,linux/ppc64le"
|
|
spec:
|
|
description: >-
|
|
This task can be used to measure code coverage of Python projects.
|
|
|
|
workspaces:
|
|
- name: source
|
|
params:
|
|
- name: PYTHON
|
|
description: The used Python version, more precisely the tag for the Python image
|
|
type: string
|
|
default: "latest"
|
|
- name: ARGS
|
|
description: The additional arguments to be used with pytest
|
|
type: string
|
|
default: ""
|
|
- name: SOURCE_PATH
|
|
description: The path to the source code
|
|
default: "."
|
|
- name: REQUIREMENTS_FILE
|
|
description: The name of the requirements file inside the source location
|
|
default: "requirements.txt"
|
|
steps:
|
|
- name: code-coverage
|
|
image: docker.io/python:$(inputs.params.PYTHON)
|
|
workingDir: $(workspaces.source.path)
|
|
script: |
|
|
export PATH=$PATH:$HOME/.local/bin
|
|
if [ -n "$(inputs.params.REQUIREMENTS_FILE)" ] && [ -e "$(inputs.params.REQUIREMENTS_FILE)" ];then
|
|
pip install -r $(inputs.params.SOURCE_PATH)/$(inputs.params.REQUIREMENTS_FILE)
|
|
pip show pytest || {
|
|
echo "###\nWarning: Pytest is missing in your requirements\n###";
|
|
pip install pytest
|
|
}
|
|
pip show coverage || {
|
|
echo "###\nWarning: Coverage is missing in your requirements\n###";
|
|
pip install coverage
|
|
}
|
|
else
|
|
pip install pytest coverage
|
|
fi
|
|
coverage run -m pytest $(inputs.params.ARGS) $(inputs.params.SOURCE_PATH)
|
|
coverage report -m |