Skip to content

Commit 2009ea0

Browse files
BAStos525SamHSmith
authored andcommitted
ci: Add Sonarqube & Defectdojo analysis
Signed-off-by: BAStos525 <[email protected]>
1 parent 8adc891 commit 2009ea0

File tree

4 files changed

+85
-9
lines changed

4 files changed

+85
-9
lines changed

.github/workflows/main.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
name: Iroha 2 main branch workflow
1+
name: Iroha2::Main
2+
23
on:
34
push:
45
branches: [main]
6+
7+
env:
8+
TOOLCHAIN_VER: nightly-2024-09-09
9+
510
jobs:
611
build:
712
runs-on: ubuntu-latest
@@ -16,9 +21,9 @@ jobs:
1621
- name: Checkout code
1722
uses: actions/checkout@v4
1823
- name: Install correct rust version
19-
run: rustup install nightly-2024-09-09 && rustup component add rust-src --toolchain nightly-2024-09-09
24+
run: rustup install ${{ env.TOOLCHAIN_VER }} && rustup component add rust-src --toolchain ${{ env.TOOLCHAIN_VER }}
2025
- name: Set toolchain
21-
run: rustup default nightly-2024-09-09
26+
run: rustup default ${{ env.TOOLCHAIN_VER }}
2227
- name: Maturin build
2328
run: |
2429
pip install maturin

.github/workflows/pr-pytests.yml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
name: Iroha 2 pull request pytests
1+
name: Iroha2:PR::Pytests
22

33
on:
44
repository_dispatch:
55
types: [dispatch-event]
66
pull_request:
77
branches: [main]
88

9+
env:
10+
TOOLCHAIN_VER: nightly-2024-09-09
11+
IROHA_BRANCH: 2.0.0-rc.1
12+
913
jobs:
1014
pytest:
1115
runs-on: ubuntu-latest
@@ -22,11 +26,11 @@ jobs:
2226
- name: Install dependencies
2327
run: pip install poetry tomli-w
2428
- name: Checkout irohad repo code
25-
run: git clone --depth 1 https://github.com/hyperledger-iroha/iroha.git -b 2.0.0-rc.1 iroha_daemon
29+
run: git clone --depth 1 https://github.com/hyperledger-iroha/iroha.git -b ${{ env.IROHA_BRANCH }} iroha_daemon
2630
- name: Install correct rust version
27-
run: rustup install nightly-2024-09-09 && rustup component add rust-src --toolchain nightly-2024-09-09
31+
run: rustup install ${{ env.TOOLCHAIN_VER }} && rustup component add rust-src --toolchain ${{ env.TOOLCHAIN_VER }}
2832
- name: Set toolchain
29-
run: rustup default nightly-2024-09-09
33+
run: rustup default ${{ env.TOOLCHAIN_VER }}
3034
- name: Build irohad
3135
run: cd iroha_daemon && cargo build --release && mkdir target/debug -p && cp target/release/irohad target/debug/irohad && cp target/release/iroha target/debug/iroha
3236
- name: Build kagami
@@ -39,8 +43,15 @@ jobs:
3943
cd iroha_daemon && scripts/test_env.py setup && cd .. &&
4044
python -m venv .venv &&
4145
source .venv/bin/activate &&
42-
pip install pytest faker allure-pytest &&
46+
pip install pytest faker allure-pytest pytest-cov &&
4347
pip install --break-system-packages target/wheels/iroha2-*.whl &&
44-
python -m pytest tests/"
48+
python -m pytest --cov=. --cov-report xml:coverage-reports/coverage.xml tests/"
4549
- name: Tear down the network
50+
if: always()
4651
run: cd iroha_daemon && scripts/test_env.py cleanup
52+
- name: Upload coverage report
53+
uses: actions/upload-artifact@v4
54+
with:
55+
name: report-coverage
56+
path: coverage-reports/coverage.xml
57+
retention-days: 1

.github/workflows/sonar-dojo.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Iroha2::Sonar-Dojo
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Iroha2:PR::Pytests"]
6+
types: [completed]
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.actor }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
sonarqube-defectdojo:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Download coverage report
18+
uses: actions/download-artifact@v4
19+
with:
20+
path: coverage-reports
21+
pattern: report-coverage
22+
merge-multiple: true
23+
run-id: ${{ github.event.workflow_run.id }}
24+
github-token: ${{ secrets.GITHUB_TOKEN }}
25+
- name: Run Bandit analysis
26+
continue-on-error: true
27+
run: |
28+
pip install bandit
29+
bandit -r tests/ examples/ docs-recipes/ -f json -o bandit-report.json
30+
- name: Run Pylint analysis
31+
continue-on-error: true
32+
run: |
33+
pip install pylint
34+
python -m pylint tests/ examples/ docs-recipes/ -r n --output-format=parseable > pylint-report.txt
35+
- name: SonarQube
36+
if: always()
37+
uses: sonarsource/sonarqube-scan-action@master
38+
env:
39+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
40+
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
41+
- name: DefectDojo
42+
if: always()
43+
uses: C4tWithShell/[email protected]
44+
with:
45+
token: ${{ secrets.DEFECTOJO_TOKEN }}
46+
defectdojo_url: ${{ secrets.DEFECTOJO_URL }}
47+
product_type: iroha2
48+
engagement: ${{ github.ref_name }}
49+
tools: "SonarQube API Import,Github Vulnerability Scan"
50+
sonar_projectKey: hyperledger-iroha:iroha-python
51+
github_token: ${{ secrets.GITHUB_TOKEN }}
52+
github_repository: ${{ github.repository }}
53+
product: ${{ github.repository }}
54+
environment: Test
55+
reports: '{"Github Vulnerability Scan": "github.json"}'

sonar-project.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sonar.projectKey = hyperledger-iroha:iroha-python
2+
sonar.language = py
3+
sonar.python.coverage.reportPaths = coverage-reports/coverage.xml
4+
sonar.python.bandit.reportPaths = bandit-report.json
5+
sonar.python.pylint.reportPaths = pylint-report.txt

0 commit comments

Comments
 (0)