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

ci: Add Sonarqube & Defectdojo analysis #229

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 8 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
name: Iroha 2 main branch workflow
name: Iroha2::Main

on:
push:
branches: [main]

env:
TOOLCHAIN_VER: nightly-2024-09-09

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -16,9 +21,9 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Install correct rust version
run: rustup install nightly-2024-09-09 && rustup component add rust-src --toolchain nightly-2024-09-09
run: rustup install ${{ env.TOOLCHAIN_VER }} && rustup component add rust-src --toolchain ${{ env.TOOLCHAIN_VER }}
- name: Set toolchain
run: rustup default nightly-2024-09-09
run: rustup default ${{ env.TOOLCHAIN_VER }}
- name: Maturin build
run: |
pip install maturin
Expand Down
23 changes: 17 additions & 6 deletions .github/workflows/pr-pytests.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
name: Iroha 2 pull request pytests
name: Iroha2:PR::Pytests

on:
repository_dispatch:
types: [dispatch-event]
pull_request:
branches: [main]

env:
TOOLCHAIN_VER: nightly-2024-09-09
IROHA_BRANCH: 2.0.0-rc.1

jobs:
pytest:
runs-on: ubuntu-latest
Expand All @@ -22,11 +26,11 @@ jobs:
- name: Install dependencies
run: pip install poetry tomli-w
- name: Checkout irohad repo code
run: git clone --depth 1 https://github.com/hyperledger-iroha/iroha.git -b 2.0.0-rc.1 iroha_daemon
run: git clone --depth 1 https://github.com/hyperledger-iroha/iroha.git -b ${{ env.IROHA_BRANCH }} iroha_daemon
- name: Install correct rust version
run: rustup install nightly-2024-09-09 && rustup component add rust-src --toolchain nightly-2024-09-09
run: rustup install ${{ env.TOOLCHAIN_VER }} && rustup component add rust-src --toolchain ${{ env.TOOLCHAIN_VER }}
- name: Set toolchain
run: rustup default nightly-2024-09-09
run: rustup default ${{ env.TOOLCHAIN_VER }}
- name: Build irohad
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
- name: Build kagami
Expand All @@ -39,8 +43,15 @@ jobs:
cd iroha_daemon && scripts/test_env.py setup && cd .. &&
python -m venv .venv &&
source .venv/bin/activate &&
pip install pytest faker allure-pytest &&
pip install pytest faker allure-pytest pytest-cov &&
pip install --break-system-packages target/wheels/iroha2-*.whl &&
python -m pytest tests/"
python -m pytest --cov=. --cov-report xml:coverage-reports/coverage.xml tests/"
- name: Tear down the network
if: always()
run: cd iroha_daemon && scripts/test_env.py cleanup
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: report-coverage
path: coverage-reports/coverage.xml
retention-days: 1
55 changes: 55 additions & 0 deletions .github/workflows/sonar-dojo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Iroha2::Sonar-Dojo

on:
workflow_run:
workflows: ["Iroha2:PR::Pytests"]
types: [completed]

concurrency:
group: ${{ github.workflow }}-${{ github.actor }}
cancel-in-progress: true

jobs:
sonarqube-defectdojo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download coverage report
uses: actions/download-artifact@v4
with:
path: coverage-reports
pattern: report-coverage
merge-multiple: true
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Run Bandit analysis
continue-on-error: true
run: |
pip install bandit
bandit -r tests/ examples/ docs-recipes/ -f json -o bandit-report.json
- name: Run Pylint analysis
continue-on-error: true
run: |
pip install pylint
python -m pylint tests/ examples/ docs-recipes/ -r n --output-format=parseable > pylint-report.txt
- name: SonarQube
if: always()
uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
- name: DefectDojo
if: always()
uses: C4tWithShell/[email protected]
with:
token: ${{ secrets.DEFECTOJO_TOKEN }}
defectdojo_url: ${{ secrets.DEFECTOJO_URL }}
product_type: iroha2
engagement: ${{ github.ref_name }}
tools: "SonarQube API Import,Github Vulnerability Scan"
sonar_projectKey: hyperledger-iroha:iroha-python
github_token: ${{ secrets.GITHUB_TOKEN }}
github_repository: ${{ github.repository }}
product: ${{ github.repository }}
environment: Test
reports: '{"Github Vulnerability Scan": "github.json"}'
5 changes: 5 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sonar.projectKey = hyperledger-iroha:iroha-python
sonar.language = py
sonar.python.coverage.reportPaths = coverage-reports/coverage.xml
sonar.python.bandit.reportPaths = bandit-report.json
sonar.python.pylint.reportPaths = pylint-report.txt
Loading