Add quality gate workflow 12.
This commit is contained in:
committed by
vitor-aignosi
parent
79fc605669
commit
9948a2cc9b
66
.github/workflows/quality-gate.yml
vendored
66
.github/workflows/quality-gate.yml
vendored
@@ -13,28 +13,65 @@ jobs:
|
|||||||
sonar:
|
sonar:
|
||||||
name: SonarQube Analysis
|
name: SonarQube Analysis
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions: write-all
|
permissions:
|
||||||
|
contents: read # Necessário para checkout
|
||||||
|
# Adicione outras permissões se o token do app precisar delas,
|
||||||
|
# mas 'write-all' é muito amplo e geralmente não necessário para o token do workflow em si.
|
||||||
|
# As permissões para o token do app são definidas na configuração do GitHub App.
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: ⬇️ Checkout Code
|
- name: ⬇️ Checkout Code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0 # Necessário para SonarQube analysis
|
||||||
|
persist-credentials: false # Importante: Evita que o token padrão do checkout interfira
|
||||||
|
|
||||||
- name: Generate token
|
- name: Generate App Token
|
||||||
id: generate-token
|
id: generate-app-token
|
||||||
uses: actions/create-github-app-token@v1
|
uses: actions/create-github-app-token@v1
|
||||||
with:
|
with:
|
||||||
app-id: ${{ secrets.APP_ID }}
|
app-id: ${{ secrets.APP_ID }}
|
||||||
private-key: ${{ secrets.APP_PRIVATE_KEY }}
|
private-key: ${{ secrets.APP_PRIVATE_KEY }}
|
||||||
owner: 'Aignosi'
|
owner: 'Aignosi' # O proprietário (usuário ou organização) dos repositórios
|
||||||
repositories: 'sientia-dataops-library,sientia-mlops-library'
|
repositories: 'sientia-dataops-library,sientia-mlops-library' # Repositórios que o token do app precisa acessar
|
||||||
|
|
||||||
- name: Create temporary requirements file
|
- name: Prepare requirements.txt
|
||||||
env:
|
id: prepare-requirements
|
||||||
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
|
|
||||||
run: |
|
run: |
|
||||||
sed "s|git+ssh://git@github.com|git+https://${GITHUB_TOKEN}@github.com|g" requirements.txt > requirements_https.txt
|
if [ ! -f requirements.txt ]; then
|
||||||
|
echo "requirements.txt not found!"
|
||||||
|
# Decide how to handle: exit 1, or create an empty one, or use a default
|
||||||
|
# For now, let's assume it might be optional or created elsewhere if not present.
|
||||||
|
# If it's mandatory, uncomment the line below:
|
||||||
|
exit 1
|
||||||
|
echo "PROCESSED_REQUIREMENTS_FILE=requirements.txt" >> $GITHUB_OUTPUT # Fallback or handle error
|
||||||
|
else
|
||||||
|
# Converte URLs SSH (git@github.com: ou git+ssh://git@github.com/) para HTTPS genéricas
|
||||||
|
# Exemplo: git+ssh://git@github.com/Aignosi/repo.git -> git+https://github.com/Aignosi/repo.git
|
||||||
|
# Exemplo: git@github.com:Aignosi/repo.git -> git+https://github.com/Aignosi/repo.git
|
||||||
|
sed -e "s|git+ssh://git@github.com/|git+https://github.com/|g" \
|
||||||
|
-e "s|git@github.com:|git+https://github.com/|g" \
|
||||||
|
requirements.txt > requirements_prepared.txt
|
||||||
|
echo "PROCESSED_REQUIREMENTS_FILE=requirements_prepared.txt" >> $GITHUB_OUTPUT
|
||||||
|
echo "--- Original requirements.txt ---"
|
||||||
|
cat requirements.txt
|
||||||
|
echo "--- Prepared requirements_prepared.txt ---"
|
||||||
|
cat requirements_prepared.txt
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Configure Git to use App Token
|
||||||
|
env:
|
||||||
|
# Este é o token gerado pelo GitHub App, com permissões para os repositórios de dependência
|
||||||
|
GH_APP_TOKEN: ${{ steps.generate-app-token.outputs.token }}
|
||||||
|
run: |
|
||||||
|
# Configura o Git para usar o token do app para todas as URLs HTTPS do github.com
|
||||||
|
# Isso garante que o pip, ao clonar dependências, usará este token.
|
||||||
|
git config --global url."https://oauth2:${GH_APP_TOKEN}@github.com/".insteadOf "https://github.com/"
|
||||||
|
echo "Git authentication configured to use the App Token for github.com"
|
||||||
|
|
||||||
|
# (Opcional) Para depuração: Verifique se o token pode listar o repositório remoto
|
||||||
|
GIT_TERMINAL_PROMPT=0 git ls-remote https://github.com/Aignosi/sientia-dataops-library.git HEAD || echo "Failed to ls-remote sientia-dataops-library"
|
||||||
|
GIT_TERMINAL_PROMPT=0 git ls-remote https://github.com/Aignosi/sientia-mlops-library.git HEAD || echo "Failed to ls-remote sientia-mlops-library"
|
||||||
|
|
||||||
- name: 🔧 Setup Python
|
- name: 🔧 Setup Python
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v4
|
||||||
@@ -45,14 +82,15 @@ jobs:
|
|||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/.cache/pip
|
path: ~/.cache/pip
|
||||||
key: ${{ runner.os }}-pip-${{ hashFiles('requirements_https.txt') }}
|
key: ${{ runner.os }}-pip-${{ hashFiles(steps.prepare-requirements.outputs.PROCESSED_REQUIREMENTS_FILE) }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-pip-
|
${{ runner.os }}-pip-
|
||||||
|
|
||||||
- name: 📦 Install Dependencies
|
- name: 📦 Install Dependencies
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
pip install -r requirements_https.txt
|
echo "Installing dependencies from ${{ steps.prepare-requirements.outputs.PROCESSED_REQUIREMENTS_FILE }}"
|
||||||
|
pip install -r ${{ steps.prepare-requirements.outputs.PROCESSED_REQUIREMENTS_FILE }}
|
||||||
pip install pytest pytest-cov
|
pip install pytest pytest-cov
|
||||||
|
|
||||||
- name: ⬇️ Setup Node.js 18
|
- name: ⬇️ Setup Node.js 18
|
||||||
@@ -65,13 +103,13 @@ jobs:
|
|||||||
|
|
||||||
- name: 🧪 Run Tests with Pytest
|
- name: 🧪 Run Tests with Pytest
|
||||||
run: |
|
run: |
|
||||||
pytest tests --junitxml=pytest.xml --cov=scouter requirements--cov-report=xml --cov-report=term
|
pytest tests --junitxml=pytest.xml --cov=scouter --cov-report=xml --cov-report=term
|
||||||
|
|
||||||
- name: 📊 Run SonarQube Analysis
|
- name: 📊 Run SonarQube Analysis
|
||||||
env:
|
env:
|
||||||
SONAR_PROJECT_KEY: ${{ secrets.SONAR_PROJECT_KEY }}
|
SONAR_PROJECT_KEY: ${{ secrets.SONAR_PROJECT_KEY }}
|
||||||
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
|
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
|
||||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} # Este é o token do SonarQube
|
||||||
run: |
|
run: |
|
||||||
sonar-scanner \
|
sonar-scanner \
|
||||||
-Dsonar.projectKey=$SONAR_PROJECT_KEY \
|
-Dsonar.projectKey=$SONAR_PROJECT_KEY \
|
||||||
|
|||||||
Reference in New Issue
Block a user