98 lines
3.3 KiB
YAML
98 lines
3.3 KiB
YAML
name: Code Quality Check
|
|
|
|
on:
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
quality-check:
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
GITHUB: ${{ secrets.GITHUB }}
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v6
|
|
with:
|
|
python-version: '3.14'
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
pip install -r src/requirements.txt
|
|
pip install black isort pylint flake8 mypy bandit safety pytest coverage radon
|
|
|
|
- name: Create results folder
|
|
run: mkdir -p /tmp/results
|
|
|
|
# Tools ausführen
|
|
- name: Run Black
|
|
run: black --check --diff . > /tmp/results/black.txt 2>&1 || echo "BLACK_FAILED=true" >> $GITHUB_ENV
|
|
|
|
- name: Run isort
|
|
run: isort --check-only --diff . > /tmp/results/isort.txt 2>&1 || echo "ISORT_FAILED=true" >> $GITHUB_ENV
|
|
|
|
- name: Run pylint with optional rcfile
|
|
run: |
|
|
if [ -f .gitea/linters/pylintrc ]; then
|
|
echo "Using custom pylintrc file."
|
|
pylint --rcfile=.gitea/linters/pylintrc . > /tmp/results/pylint.txt 2>&1 || echo "PYLINT_FAILED=true" >> $GITHUB_ENV
|
|
else
|
|
echo "No custom pylintrc file found. Using default settings."
|
|
pylint . > /tmp/results/pylint.txt 2>&1 || echo "PYLINT_FAILED=true" >> $GITHUB_ENV
|
|
fi
|
|
|
|
- name: Run flake8 with optional config
|
|
run: |
|
|
if [ -f .gitea/linters/flake8 ]; then
|
|
echo "Using custom flake8 config."
|
|
flake8 --config=.gitea/linters/flake8 . > /tmp/results/flake8.txt 2>&1 || echo "FLAKE8_FAILED=true" >> $GITHUB_ENV
|
|
else
|
|
echo "No custom flake8 config found. Using default settings."
|
|
flake8 . > /tmp/results/flake8.txt 2>&1 || echo "FLAKE8_FAILED=true" >> $GITHUB_ENV
|
|
fi
|
|
|
|
# Ergebnisse zusammenfassen
|
|
- name: Combine all results
|
|
run: |
|
|
echo "### 🛡️ Code Quality Report" > /tmp/results/summary.md
|
|
|
|
for tool in black isort pylint flake8; do
|
|
echo "#### 🔍 ${tool}" >> /tmp/results/summary.md
|
|
echo '```' >> /tmp/results/summary.md
|
|
cat /tmp/results/${tool}.txt >> /tmp/results/summary.md
|
|
echo '```' >> /tmp/results/summary.md
|
|
echo "" >> /tmp/results/summary.md
|
|
done
|
|
|
|
# PR-Kommentar hinzufügen
|
|
- name: Add comment to PR
|
|
if: ${{ env.GITHUB_EVENT_NAME == 'pull_request' }}
|
|
uses: mshick/add-pr-comment@v2
|
|
with:
|
|
message-path: /tmp/results/summary.md
|
|
|
|
- name: Create black diff patch
|
|
run: black --diff . > /tmp/results/black_diff.patch
|
|
|
|
- name: Create isort diff patch
|
|
run: isort . --diff > /tmp/results/isort.patch
|
|
|
|
# Ergebnisse als Artefakte speichern
|
|
- name: Upload results as artifacts
|
|
uses: actions/upload-artifact@v6
|
|
with:
|
|
name: quality-reports
|
|
path: /tmp/results
|
|
|
|
- name: Check for issues
|
|
run: |
|
|
if [[ "$BLACK_FAILED" == "true" || "$ISORT_FAILED" == "true" || "$PYLINT_FAILED" == "true" || "$FLAKE8_FAILED" == "true" ]]; then
|
|
echo "❌ Code quality issues found! Please fix the issues before merging." && exit 1
|
|
fi
|