Skip to content

Commit

Permalink
Add pylint and pytest task
Browse files Browse the repository at this point in the history
  • Loading branch information
wumaxd authored and tekton-robot committed Jul 23, 2020
1 parent f5a4936 commit a0e2d1e
Show file tree
Hide file tree
Showing 10 changed files with 312 additions and 0 deletions.
50 changes: 50 additions & 0 deletions task/pylint/0.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# pylint

The task provides linting based on [pylint](https://pypi.org/project/pylint/) for Python. The used images are based on the official Docker Hub [Python images](https://hub.docker.com/_/python). The installation of the packages is performed via a `pip install`.

**It is required that `pylint` is part of the requirements file for the task. If the module is not included a warning will be printed.**

## Install the Task

### Workspaces

* **source**: A [Workspace](https://github.com/tektoncd/pipeline/blob/master/docs/workspaces.md) volume containing the python code.

### Install pylint

```bash
kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/task/pylint/0.1/pylint.yaml
```

## Parameters

* **PYTHON**: The used Python version, more precisely the tag for the Python image (_default_: `3.6`)
* **SOURCE_PATH**: The path to the source code (_default_: `.`)
* **MODULE_PATH**: The path to the module which should be analysed by pylint (_default_: `.`)
* **ARGS**: The additional arguments to be used with pylint
* **REQUIREMENTS_FILE**: The name of the requirements file inside the source location (_default_: `requirements.txt`)

## Usage

This `TaskRun` runs `pylint` on a repository.

```yaml
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: lint
spec:
taskRef:
name: pylint
workspaces:
- name: source
persistentVolumeClaim:
claimName: my-source
params:
- name: PYTHON
value: "3.7"
- name: MODULE
value: "examples/custom.py"
- name: ARGS
value: "-r y"
```
44 changes: 44 additions & 0 deletions task/pylint/0.1/pylint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: pylint
labels:
app.kubernetes.io/version: "0.1"
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/tags: python, pylint
tekton.dev/displayName: pylint

spec:
description: >-
This task will run pylint on the provided input.
workspaces:
- name: source
params:
- name: PYTHON
description: The used Python version, more precisely the tag for the Python image
type: string
default: "3.6"
- name: SOURCE_PATH
description: The path to the source code
default: "."
- name: MODULE_PATH
description: The path to the module which should be analysed by pylint
default: "."
- name: ARGS
description: The additional arguments to be used with pylint
type: string
default: ""
- name: REQUIREMENTS_FILE
description: The name of the requirements file inside the source location
default: "requirements.txt"
steps:
- name: lint
image: docker.io/python:$(inputs.params.PYTHON)
workingDir: /workspace/source
script: |
pip install -r $(inputs.params.SOURCE_PATH)/$(inputs.params.REQUIREMENTS_FILE)
pip show pylint || echo "###\nWarning: Pylint is missing in your requirements\n###" && pip install pylint
pylint $(inputs.params.ARGS) $(inputs.params.MODULE_PATH)
4 changes: 4 additions & 0 deletions task/pylint/0.1/tests/pre-apply-task-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# Add git-clone
kubectl -n ${tns} apply -f ./task/git-clone/0.1/git-clone.yaml
11 changes: 11 additions & 0 deletions task/pylint/0.1/tests/resources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: python-source-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 200Mi
52 changes: 52 additions & 0 deletions task/pylint/0.1/tests/run.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: python-test-pipeline
spec:
workspaces:
- name: shared-workspace
tasks:
- name: fetch-repository
taskRef:
name: git-clone
workspaces:
- name: output
workspace: shared-workspace
params:
- name: url
value: https://github.com/wumaxd/pylint-pytest-example.git
- name: subdirectory
value: ""
- name: deleteExisting
value: "true"

- name: pylint
taskRef:
name: pylint
runAfter:
- fetch-repository
workspaces:
- name: source
workspace: shared-workspace
params:
- name: PYTHON
value: "3.7"
- name: ARGS
value: "-r y"
- name: MODULE_PATH
value: "src/"
- name: REQUIREMENTS_FILE
value: "requirements.txt"
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: python-test-pipeline-run
spec:
pipelineRef:
name: python-test-pipeline
workspaces:
- name: shared-workspace
persistentvolumeclaim:
claimName: python-source-pvc
47 changes: 47 additions & 0 deletions task/pytest/0.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# pytest

The task provides test execution based on [pytest](https://pypi.org/project/pytest/) for Python. The used images are based on the official Docker Hub [Python images](https://hub.docker.com/_/python). The installation of the packages is performed via a `pip install`.

**It is required that `pytest` is part of the requirements file for the task. If the module is not included a warning will be printed.**

## Install the Task

### Workspaces

* **source**: A [Workspace](https://github.com/tektoncd/pipeline/blob/master/docs/workspaces.md) volume containing the python code.

### Install pytest

```bash
kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/task/pytest/0.1/pytest.yaml
```

## Parameters

* **PYTHON**: The used Python version, more precisely the tag for the Python image (_default_: `3.6`)
* **ARGS**: The additional arguments to be used with pytest
* **SOURCE_PATH**: The path to the source code (_default_: `.`)
* **REQUIREMENTS_FILE**: The name of the requirements file inside the source location (_default_: `requirements.txt`)

## Usage

This `TaskRun` runs `pytest` on a repository.

```yaml
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: pytest
spec:
taskRef:
name: pytest
workspaces:
- name: source
persistentVolumeClaim:
claimName: my-source
params:
- name: PYTHON
value: "3.7"
- name: ARGS
value: "-rfs"
```
41 changes: 41 additions & 0 deletions task/pytest/0.1/pytest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: pytest
labels:
app.kubernetes.io/version: "0.1"
annotations:
tekton.dev/pipelines.minVersion: "0.12.1"
tekton.dev/tags: python, pytest
tekton.dev/displayName: pytest

spec:
description: >-
This task will run pytest on the provided input.
workspaces:
- name: source
params:
- name: PYTHON
description: The used Python version, more precisely the tag for the Python image
type: string
default: "3.6"
- 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: unit-test
image: docker.io/python:$(inputs.params.PYTHON)
workingDir: /workspace/source
script: |
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
pytest $(inputs.params.ARGS) $(inputs.params.SOURCE-PATH)
4 changes: 4 additions & 0 deletions task/pytest/0.1/tests/pre-apply-task-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# Add git-clone
kubectl -n ${tns} apply -f ./task/git-clone/0.1/git-clone.yaml
11 changes: 11 additions & 0 deletions task/pytest/0.1/tests/resources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: python-source-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 200Mi
48 changes: 48 additions & 0 deletions task/pytest/0.1/tests/run.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: python-test-pipeline
spec:
workspaces:
- name: shared-workspace
tasks:
- name: fetch-repository
taskRef:
name: git-clone
workspaces:
- name: output
workspace: shared-workspace
params:
- name: url
value: https://github.com/wumaxd/pylint-pytest-example.git
- name: subdirectory
value: ""
- name: deleteExisting
value: "true"

- name: pytest
taskRef:
name: pytest
runAfter:
- fetch-repository
workspaces:
- name: source
workspace: shared-workspace
params:
- name: PYTHON
value: "3.7"
- name: ARGS
value: "-rfs"
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: python-test-pipeline-run
spec:
pipelineRef:
name: python-test-pipeline
workspaces:
- name: shared-workspace
persistentvolumeclaim:
claimName: python-source-pvc

0 comments on commit a0e2d1e

Please sign in to comment.