-
Notifications
You must be signed in to change notification settings - Fork 577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pylint and pytest task #432
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we use 3.8 (whichi s the latest) by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. We could even place there latest as it is the tag for the Python image. Do you think this would make sense or is too confusing having a Python version latest?