Skip to content

Commit bad7099

Browse files
committed
Enhances CI with tests and analysis
Integrates a Python tests workflow with multi-version support and caching. Adds new analysis tools (Pyright, CycloneDX) and updates the quality gate workflow. Introduces least privilege permissions and weekly scheduling. Signed-off-by: DavidOsipov <[email protected]>
1 parent a1a771f commit bad7099

File tree

2 files changed

+108
-5
lines changed

2 files changed

+108
-5
lines changed

.github/workflows/python-tests.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: 🧪 Python Tests
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
workflow_dispatch:
9+
workflow_call:
10+
# Adding empty outputs to properly define the workflow_call trigger
11+
outputs:
12+
result:
13+
description: "Test execution result"
14+
value: ${{ jobs.test.result }}
15+
16+
# Adding explicit permissions following the principle of least privilege
17+
permissions:
18+
contents: read
19+
20+
jobs:
21+
test:
22+
name: Test Python ${{ matrix.python-version }}
23+
runs-on: ubuntu-latest
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
python-version: ["3.10", "3.11", "3.12", "3.13"]
28+
29+
steps:
30+
- name: Checkout code
31+
uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
32+
- name: Set up Python ${{ matrix.python-version }}
33+
uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55
34+
with:
35+
python-version: ${{ matrix.python-version }}
36+
cache: 'pip'
37+
38+
- name: Cache pip dependencies
39+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
40+
with:
41+
path: |
42+
~/.cache/pip
43+
~/.cache/pypoetry
44+
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}
45+
restore-keys: |
46+
${{ runner.os }}-pip-${{ matrix.python-version }}-
47+
48+
- name: Install Poetry
49+
run: |
50+
pip install poetry
51+
poetry --version
52+
53+
- name: Install dependencies
54+
run: |
55+
poetry install --no-interaction
56+
57+
- name: Typecheck with mypy
58+
run: |
59+
poetry run mypy feldman_vss.py
60+
61+
# Uncomment and modify when you have tests
62+
# - name: Run tests
63+
# run: |
64+
# poetry run pytest

.github/workflows/sonarqube.yml

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
name: 🛡️ Bastion Quality Gates
22

3+
34
on:
45
push:
56
branches: [ "main" ]
67
pull_request:
78
branches: [ "main" ]
9+
schedule:
10+
- cron: '0 0 * * 0' # Weekly on Sunday
811
workflow_dispatch:
912

1013
permissions:
1114
pull-requests: read
1215
security-events: write
1316

1417
jobs:
18+
test:
19+
uses: ./.github/workflows/python-tests.yml
20+
# This workflow now depends on the successful completion of the python-tests workflow
1521
Analyze:
22+
needs: test
1623
runs-on: ubuntu-latest
1724
strategy:
1825
matrix:
19-
tool: [bandit, ruff, mypy, flake8, pylint, codeql, snyk]
26+
tool: [bandit, ruff, mypy, flake8, pylint, codeql, snyk, pyright, cyclonedx]
2027
steps:
2128
- name: Checkout code
2229
uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2
@@ -50,7 +57,7 @@ jobs:
5057
poetry install --with dev --no-interaction
5158
5259
- name: Install analysis tools
53-
if: matrix.tool != 'codeql' && matrix.tool != 'snyk'
60+
if: matrix.tool != 'codeql' && matrix.tool != 'snyk' && matrix.tool != 'pyright' && matrix.tool != 'cyclonedx'
5461
run: |
5562
poetry run pip install bandit ruff mypy flake8 pylint
5663
poetry run bandit --version
@@ -59,6 +66,24 @@ jobs:
5966
poetry run flake8 --version
6067
poetry run pylint --version
6168
69+
- name: Install Node.js for Pyright
70+
if: matrix.tool == 'pyright'
71+
uses: actions/setup-node@v4
72+
with:
73+
node-version: '20'
74+
75+
- name: Install Pyright
76+
if: matrix.tool == 'pyright'
77+
run: |
78+
npm install -g pyright
79+
pyright --version
80+
81+
- name: Install CycloneDX
82+
if: matrix.tool == 'cyclonedx'
83+
run: |
84+
poetry run pip install cyclonedx-bom
85+
poetry run cyclonedx-py --version || echo "CycloneDX installed"
86+
6287
- name: Setup Snyk CLI
6388
if: matrix.tool == 'snyk'
6489
uses: snyk/actions/setup@cdb760004ba9ea4d525f2e043745dfe85bb9077e
@@ -73,8 +98,9 @@ jobs:
7398
run: |
7499
pip install poetry
75100
pip install poetry-plugin-export
76-
poetry export --format requirements.txt --output requirements.txt
77-
snyk test --file=requirements.txt --sarif-file-output=snyk_report.sarif
101+
poetry export --format requirements.txt --output requirements.txt --with dev
102+
pip install black blake3 click colorama flake8 gmpy2 isort mccabe msgpack-types mypy-extensions pathspec psutil pycodestyle pyflakes setuptools types-requests types-setuptools typing-extensions
103+
snyk test --file=requirements.txt --sarif-file-output=snyk_report.sarif --skip-unresolved || snyk test --file=requirements.txt --sarif-file-output=snyk_report.sarif --skip-unresolved --all-projects
78104
79105
- name: Run Bandit
80106
if: matrix.tool == 'bandit'
@@ -96,6 +122,15 @@ jobs:
96122
if: matrix.tool == 'pylint'
97123
run: poetry run pylint --recursive=y . --output-format=json > pylint_report.json || true
98124

125+
- name: Run Pyright
126+
if: matrix.tool == 'pyright'
127+
run: pyright --outputjson > pyright_report.json || true
128+
129+
- name: Generate Software Bill of Materials (SBOM)
130+
if: matrix.tool == 'cyclonedx'
131+
run: |
132+
poetry run cyclonedx-py -o cyclonedx_report.json -j . || true
133+
99134
- name: Initialize CodeQL
100135
if: matrix.tool == 'codeql'
101136
uses: github/codeql-action/init@main
@@ -137,10 +172,12 @@ jobs:
137172
mv reports/pylint-report/pylint_report.json .
138173
mv reports/codeql-report/codeql_report.sarif .
139174
mv reports/snyk-report/snyk_report.sarif .
175+
mv reports/pyright-report/pyright_report.json .
176+
mv reports/cyclonedx-report/cyclonedx_report.json .
140177
141178
- name: Check if reports exist
142179
run: |
143-
for report in bandit_report.json ruff_report.json mypy_report.txt flake8_report.txt pylint_report.json codeql_report.sarif snyk_report.sarif; do
180+
for report in bandit_report.json ruff_report.json mypy_report.txt flake8_report.txt pylint_report.json codeql_report.sarif snyk_report.sarif pyright_report.json cyclonedx_report.json; do
144181
if [ ! -f "$report" ]; then
145182
echo "$report not found. Exiting."
146183
exit 1
@@ -163,5 +200,7 @@ jobs:
163200
-Dsonar.python.flake8.reportPaths=flake8_report.txt
164201
-Dsonar.python.pylint.reportPaths=pylint_report.json
165202
-Dsonar.sarifReportPaths=codeql_report.sarif,snyk_report.sarif
203+
-Dsonar.externalIssuesReportPaths=pyright_report.json
204+
-Dsonar.dependencyCheck.jsonReportPath=cyclonedx_report.json
166205
-Dsonar.python.version=3.10-3.13
167206
-Dsonar.languages=python

0 commit comments

Comments
 (0)