diff --git a/task/pylint/0.1/README.md b/task/pylint/0.1/README.md new file mode 100644 index 0000000000..bad6eb8001 --- /dev/null +++ b/task/pylint/0.1/README.md @@ -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" +``` diff --git a/task/pylint/0.1/pylint.yaml b/task/pylint/0.1/pylint.yaml new file mode 100644 index 0000000000..c8250d6e2e --- /dev/null +++ b/task/pylint/0.1/pylint.yaml @@ -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) diff --git a/task/pylint/0.1/tests/pre-apply-task-hook.sh b/task/pylint/0.1/tests/pre-apply-task-hook.sh new file mode 100755 index 0000000000..51a3a68e88 --- /dev/null +++ b/task/pylint/0.1/tests/pre-apply-task-hook.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# Add git-clone +kubectl -n ${tns} apply -f ./task/git-clone/0.1/git-clone.yaml diff --git a/task/pylint/0.1/tests/resources.yaml b/task/pylint/0.1/tests/resources.yaml new file mode 100644 index 0000000000..93f6891509 --- /dev/null +++ b/task/pylint/0.1/tests/resources.yaml @@ -0,0 +1,11 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: python-source-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 200Mi diff --git a/task/pylint/0.1/tests/run.yaml b/task/pylint/0.1/tests/run.yaml new file mode 100644 index 0000000000..834cc30959 --- /dev/null +++ b/task/pylint/0.1/tests/run.yaml @@ -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 diff --git a/task/pytest/0.1/README.md b/task/pytest/0.1/README.md new file mode 100644 index 0000000000..01f0e0fece --- /dev/null +++ b/task/pytest/0.1/README.md @@ -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" +``` \ No newline at end of file diff --git a/task/pytest/0.1/pytest.yaml b/task/pytest/0.1/pytest.yaml new file mode 100644 index 0000000000..f8e4cdbcae --- /dev/null +++ b/task/pytest/0.1/pytest.yaml @@ -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) diff --git a/task/pytest/0.1/tests/pre-apply-task-hook.sh b/task/pytest/0.1/tests/pre-apply-task-hook.sh new file mode 100755 index 0000000000..51a3a68e88 --- /dev/null +++ b/task/pytest/0.1/tests/pre-apply-task-hook.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# Add git-clone +kubectl -n ${tns} apply -f ./task/git-clone/0.1/git-clone.yaml diff --git a/task/pytest/0.1/tests/resources.yaml b/task/pytest/0.1/tests/resources.yaml new file mode 100644 index 0000000000..93f6891509 --- /dev/null +++ b/task/pytest/0.1/tests/resources.yaml @@ -0,0 +1,11 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: python-source-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 200Mi diff --git a/task/pytest/0.1/tests/run.yaml b/task/pytest/0.1/tests/run.yaml new file mode 100644 index 0000000000..537b37f027 --- /dev/null +++ b/task/pytest/0.1/tests/run.yaml @@ -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