87 lines
2.6 KiB
YAML
87 lines
2.6 KiB
YAML
name: Quality gate
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- '**'
|
|
pull_request:
|
|
branches:
|
|
- '**'
|
|
types: [ opened, synchronize, reopened ]
|
|
|
|
jobs:
|
|
sonar:
|
|
name: SonarQube Analysis
|
|
runs-on: ubuntu-latest
|
|
permissions: write-all
|
|
|
|
steps:
|
|
- name: ⬇️ Checkout Code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Generate token
|
|
id: generate_token
|
|
uses: tibdex/github-app-token@v1
|
|
with:
|
|
app_id: ${{ secrets.APP_ID }}
|
|
private_key: ${{ secrets.APP_PRIVATE_KEY }}
|
|
installation_id: ${{ secrets.INSTALLATION_ID }}
|
|
|
|
- name: Create temporary requirements file
|
|
env:
|
|
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
|
|
run: |
|
|
# Criar uma versão temporária do requirements.txt com URLs HTTPS
|
|
sed "s|git+ssh://git@github.com|git+https://${GITHUB_TOKEN}@github.com|g" requirements.txt > requirements_https.txt
|
|
cat requirements_https.txt | sed "s|${GITHUB_TOKEN}|***MASKED***|g"
|
|
|
|
- name: 🔧 Setup Python
|
|
uses: actions/setup-python@v4
|
|
with:
|
|
python-version: "3.11"
|
|
|
|
- name: 🗄️ Cache Python dependencies
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: ~/.cache/pip
|
|
key: ${{ runner.os }}-pip-${{ hashFiles('requirements_https.txt') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-pip-
|
|
|
|
- name: 📦 Install Dependencies
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
pip install -r requirements_https.txt
|
|
pip install pytest pytest-cov
|
|
|
|
- name: ⬇️ Setup Node.js 18
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 18
|
|
|
|
- name: 📥 Setup SonarScanner
|
|
uses: warchant/setup-sonar-scanner@v7
|
|
|
|
- name: 🧪 Run Tests with Pytest
|
|
run: |
|
|
pytest tests --junitxml=pytest.xml --cov=scouter --cov-report=xml --cov-report=term
|
|
|
|
- name: 📊 Run SonarQube Analysis
|
|
env:
|
|
SONAR_PROJECT_KEY: ${{ secrets.SONAR_PROJECT_KEY }}
|
|
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
|
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
|
run: |
|
|
sonar-scanner \
|
|
-Dsonar.projectKey=$SONAR_PROJECT_KEY \
|
|
-Dsonar.sources=scouter \
|
|
-Dsonar.tests=tests \
|
|
-Dsonar.python.coverage.reportPaths=coverage.xml \
|
|
-Dsonar.python.xunit.reportPath=pytest.xml \
|
|
-Dsonar.host.url=$SONAR_HOST_URL \
|
|
-Dsonar.token=$SONAR_TOKEN \
|
|
-Dsonar.python.version=3.11 \
|
|
-Dsonar.projectVersion=1.0.0
|