Skip to content
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

First prototype of Application Quality Pipeline #24

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3c403b7
first version of the 'Development Best Practices' workflow
hcremers-spaceapps Oct 3, 2024
0407b5e
added workflow/README.md
hcremers-spaceapps Oct 3, 2024
102341e
updated sonarqube tool
hcremers-spaceapps Oct 4, 2024
f2b77b8
split workflow into subworkflows
hcremers-spaceapps Oct 7, 2024
bb00e46
updated workflow/readme.md
hcremers-spaceapps Oct 7, 2024
f56a8ec
added Dockerfile for flake8-json
hcremers-spaceapps Oct 7, 2024
fa7d29a
prepared migration to kubernetes with calrissian
hcremers-spaceapps Oct 9, 2024
fcf0578
flake8-json image
hcremers-spaceapps Oct 21, 2024
479dedc
curl image in save-tool
hcremers-spaceapps Oct 21, 2024
7dbdc28
use git as base command in clone-tool
hcremers-spaceapps Oct 21, 2024
5200291
added pipeline_id and server_url to input list
hcremers-spaceapps Oct 21, 2024
0896eee
removed unnecessary files
hcremers-spaceapps Oct 21, 2024
518e9f6
updated workflow/readme.md and .gitignore
hcremers-spaceapps Oct 22, 2024
e6ecc95
removed example.py and the sonarqube tool
hcremers-spaceapps Oct 22, 2024
e6084a4
fixed curl error
hcremers-spaceapps Oct 28, 2024
f2a4678
added branch management in clone tool
hcremers-spaceapps Nov 8, 2024
216d7f7
added default branch in clone-tool
hcremers-spaceapps Nov 8, 2024
79486d6
ruff + updated post url
hcremers-spaceapps Nov 19, 2024
7b6a645
added bandit tool
hcremers-spaceapps Nov 21, 2024
c336fab
exit zero with flake8
hcremers-spaceapps Nov 21, 2024
73f3ba0
Merge branch '4-first-prototype' of github.com:EOEPCA/application-qua…
hcremers-spaceapps Nov 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
venv/
venv/
__pycache__
39 changes: 39 additions & 0 deletions workflow/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Workflow Module: Code Quality Analysis and Reporting

This module is a Common Workflow Language (CWL) workflow designed to automate code quality analysis for Python repositories. It is used in a Django application and executed using [pycalrissian](https://terradue.github.io/pycalrissian/), which runs the workflow in a Kubernetes environment. The workflow analyzes a Git repository using **pylint** and **flake8**, generates reports, and sends them to a specified database via POST requests.

## Inputs

The workflow requires the following inputs:

- **`repo_url`**: The URL to a Git repository that will be cloned and analyzed.
- **`server_url`**: The address of the database where the pylint and flake8 reports will be saved.
- **`pipeline_id`**: A unique identifier used for organizing report files in the database.
- **`run_id`**: A run-specific identifier to distinguish between different runs within the same pipeline.

## Workflow Overview

1. **Clone Repository**: The specified `repo_url` is cloned.
2. **Run pylint and flake8**:
- Two sub-workflows run pylint and flake8 on the cloned repository.
- Both generate code quality reports.
3. **Post Reports to Database**: Reports are sent to the `server_url` database using POST requests, with `pipeline_id` and `run_id` used to manage report storage.

## Running the Workflow

This workflow is normally executed within a Django app using **pycalrissian**, which handles the orchestration in a Kubernetes environment. Users do not typically run it directly. The app takes care of passing the inputs (`repo_url`, `server_url`, `pipeline_id`, `run_id`), executing the workflow, and processing the reports.

### Manual Execution (Using cwltool)

If manual execution is needed, you can run the workflow using **[cwltool](https://www.commonwl.org/user_guide/introduction/quick-start.html#installing-a-cwl-runner)** by providing inputs through the command line. However, you must modify the tool files to comment out or remove the `baseCommand` lines due to **cwltool** handling Docker ENTRYPOINT differently than Calrissian.

**Example of manual execution:**
```bash
cwltool workflow.cwl \
--repo_url https://github.com/example.git \
--server_url http://your-database-url/api/reports \
--pipeline_id 1234 \
--run_id run5678
```

Note: When using **cwltool**, ensure Docker is properly set up on your machine, as the tools rely on Docker containers for execution.
38 changes: 38 additions & 0 deletions workflow/bandit-workflow.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env cwltool
cwlVersion: v1.0
class: Workflow

inputs:
name:
type: string
default: bandit
pipeline_id:
type: string
repo_path:
type: Directory
run_id:
type: string
server_url:
type: string

outputs:
bandit_report:
type: File
outputSource: bandit_step/bandit_report

steps:
bandit_step:
in:
source_directory: repo_path
run: tools/bandit-tool.cwl
out:
- bandit_report
save_bandit_step:
in:
name: name
pipeline_id: pipeline_id
report: bandit_step/bandit_report
run_id: run_id
server_url: server_url
run: tools/save-tool.cwl
out: []
38 changes: 38 additions & 0 deletions workflow/flake8-workflow.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env cwltool
cwlVersion: v1.0
class: Workflow

inputs:
name:
type: string
default: flake8
pipeline_id:
type: string
repo_path:
type: Directory
run_id:
type: string
server_url:
type: string

outputs:
flake8_report:
type: File
outputSource: flake8_step/flake8_report

steps:
flake8_step:
in:
source_directory: repo_path
run: tools/flake8-tool.cwl
out:
- flake8_report
save_flake8_step:
in:
name: name
pipeline_id: pipeline_id
report: flake8_step/flake8_report
run_id: run_id
server_url: server_url
run: tools/save-tool.cwl
out: []
38 changes: 38 additions & 0 deletions workflow/pylint-workflow.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env cwltool
cwlVersion: v1.0
class: Workflow

inputs:
name:
type: string
default: pylint
pipeline_id:
type: string
repo_path:
type: Directory
run_id:
type: string
server_url:
type: string

outputs:
pylint_report:
type: File
outputSource: pylint_step/pylint_report

steps:
pylint_step:
in:
source_directory: repo_path
run: tools/pylint-tool.cwl
out:
- pylint_report
save_pylint_step:
in:
name: name
pipeline_id: pipeline_id
report: pylint_step/pylint_report
run_id: run_id
server_url: server_url
run: tools/save-tool.cwl
out: []
38 changes: 38 additions & 0 deletions workflow/ruff-workflow.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env cwltool
cwlVersion: v1.0
class: Workflow

inputs:
name:
type: string
default: ruff
pipeline_id:
type: string
repo_path:
type: Directory
run_id:
type: string
server_url:
type: string

outputs:
ruff_report:
type: File
outputSource: ruff_step/ruff_report

steps:
ruff_step:
in:
source_directory: repo_path
run: tools/ruff-tool.cwl
out:
- ruff_report
save_ruff_step:
in:
name: name
pipeline_id: pipeline_id
report: ruff_step/ruff_report
run_id: run_id
server_url: server_url
run: tools/save-tool.cwl
out: []
32 changes: 32 additions & 0 deletions workflow/tools/bandit-tool.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env cwltool

cwlVersion: v1.0
class: CommandLineTool

requirements:
DockerRequirement:
dockerPull: cytopia/bandit
InlineJavascriptRequirement: {}

inputs:
source_directory:
type: Directory
inputBinding:
position: 1

outputs:
bandit_report:
type: File
outputBinding:
glob: bandit_report.json

baseCommand:
- bandit
arguments:
- -x
- .git
- -f
- json
- -o
- bandit_report.json
- --exit-zero
29 changes: 29 additions & 0 deletions workflow/tools/clone-tool.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env cwltool

cwlVersion: v1.0
class: CommandLineTool

requirements:
DockerRequirement:
dockerPull: alpine/git
InlineJavascriptRequirement: {}

inputs:
branch:
type: string
default: main
repo_url:
type: string

outputs:
repo_directory:
type: Directory
outputBinding:
glob: $(inputs.repo_url.split('/').pop().replace('.git',''))

baseCommand: git
arguments:
- clone
- $(inputs.repo_url)
- -b
- $(inputs.branch)
26 changes: 26 additions & 0 deletions workflow/tools/flake8-tool.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env cwltool

cwlVersion: v1.0
class: CommandLineTool

requirements:
DockerRequirement:
dockerPull: eoepca/appquality-flake8-json:v0.1.0

inputs:
source_directory:
type: Directory
inputBinding:
position: 1

outputs:
flake8_report:
type: File
outputBinding:
glob: flake8_report.json

baseCommand: flake8
arguments:
- --format=json
- --output-file=flake8_report.json
- --exit-zero
28 changes: 28 additions & 0 deletions workflow/tools/pylint-tool.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env cwltool

cwlVersion: v1.0
class: CommandLineTool

requirements:
DockerRequirement:
dockerPull: cytopia/pylint
InlineJavascriptRequirement: {}

inputs:
source_directory:
type: Directory
inputBinding:
position: 1
valueFrom: $(inputs.source_directory.path + "/**/*.py")

outputs:
pylint_report:
type: File
outputBinding:
glob: pylint_report.json

baseCommand: pylint
arguments:
- --output-format=json
- --output=pylint_report.json
- --exit-zero
33 changes: 33 additions & 0 deletions workflow/tools/ruff-tool.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env cwltool

cwlVersion: v1.0
class: CommandLineTool

requirements:
DockerRequirement:
dockerPull: ghcr.io/astral-sh/ruff:alpine
InlineJavascriptRequirement: {}

inputs:
source_directory:
type: Directory
inputBinding:
position: 1

outputs:
ruff_report:
type: File
outputBinding:
glob: ruff_report.json

baseCommand:
- ruff
- check
arguments:
- --exclude
- .git
- --output-format
- json
- -o
- ruff_report.json
- -en
35 changes: 35 additions & 0 deletions workflow/tools/save-tool.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env cwltool

cwlVersion: v1.0
class: CommandLineTool

requirements:
DockerRequirement:
dockerPull: curlimages/curl
InlineJavascriptRequirement: {}

inputs:
name:
type: string
pipeline_id:
type: string
report:
type: File
run_id:
type: string
server_url:
type: string

outputs: []

baseCommand: curl
arguments:
- prefix: -X
valueFrom: POST
- prefix: -L
valueFrom: |-
$('http://' + inputs.server_url + '/api/pipelines/' + inputs.pipeline_id + '/runs/' + inputs.run_id + '/jobreports/?name=' + inputs.name)
- prefix: -H
valueFrom: Content-Type:application/json
- prefix: -d
valueFrom: $('@' + inputs.report.path)
Loading