From e099253070f22a05b244f2f95ca7ad407524539f Mon Sep 17 00:00:00 2001 From: Bruno Domingues Date: Wed, 14 May 2025 12:02:35 -0300 Subject: [PATCH 01/14] Add quality gate workflow. --- .github/workflows/quality-gate.yml | 82 ++++++++++++++++++++++++++++++ requirements.txt | 5 ++ 2 files changed, 87 insertions(+) create mode 100644 .github/workflows/quality-gate.yml create mode 100644 requirements.txt diff --git a/.github/workflows/quality-gate.yml b/.github/workflows/quality-gate.yml new file mode 100644 index 0000000..bb33103 --- /dev/null +++ b/.github/workflows/quality-gate.yml @@ -0,0 +1,82 @@ +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: 🔧 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.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Configure SSH + uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: | + ${{ secrets.SSH_PRIVATE_KEY_DATAOPS }} + ${{ secrets.SSH_PRIVATE_KEY_MLOPS }} + + - name: Add github.com to known_hosts + run: | + mkdir -p ~/.ssh + ssh-keyscan github.com >> ~/.ssh/known_hosts + + - name: 📦 Install Dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.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 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1ccf40c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +temporalio +psycopg2-binary +asyncua +git+ssh://git@github.com/Aignosi/sientia-dataops-library.git +git+ssh://git@github.com/Aignosi/sientia-mlops-library.git From 86b3b55cea74d717680224479eed0e497a77f0cf Mon Sep 17 00:00:00 2001 From: Bruno Domingues Date: Wed, 14 May 2025 14:33:24 -0300 Subject: [PATCH 02/14] Add quality gate workflow 2. --- .github/workflows/quality-gate.yml | 32 +++++++++++++++++------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/.github/workflows/quality-gate.yml b/.github/workflows/quality-gate.yml index bb33103..fc3030b 100644 --- a/.github/workflows/quality-gate.yml +++ b/.github/workflows/quality-gate.yml @@ -20,6 +20,22 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + + - name: Generate GitHub App token + id: generate-token + uses: tibdex/github-app-token@v2 + 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 - name: 🔧 Setup Python uses: actions/setup-python@v4 @@ -30,26 +46,14 @@ jobs: uses: actions/cache@v3 with: path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} + key: ${{ runner.os }}-pip-${{ hashFiles('requirements_https.txt') }} restore-keys: | ${{ runner.os }}-pip- - - name: Configure SSH - uses: webfactory/ssh-agent@v0.9.0 - with: - ssh-private-key: | - ${{ secrets.SSH_PRIVATE_KEY_DATAOPS }} - ${{ secrets.SSH_PRIVATE_KEY_MLOPS }} - - - name: Add github.com to known_hosts - run: | - mkdir -p ~/.ssh - ssh-keyscan github.com >> ~/.ssh/known_hosts - - name: 📦 Install Dependencies run: | python -m pip install --upgrade pip - pip install -r requirements.txt + pip install -r requirements_https.txt pip install pytest pytest-cov - name: ⬇️ Setup Node.js 18 From 744bbd9c019ad56af86257ed500d2da4c1a07b24 Mon Sep 17 00:00:00 2001 From: Bruno Domingues Date: Wed, 14 May 2025 14:37:39 -0300 Subject: [PATCH 03/14] Add quality gate workflow 3. --- .github/workflows/quality-gate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/quality-gate.yml b/.github/workflows/quality-gate.yml index fc3030b..7163692 100644 --- a/.github/workflows/quality-gate.yml +++ b/.github/workflows/quality-gate.yml @@ -34,7 +34,7 @@ jobs: 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 + sed 's|git+ssh://git@github.com|git+https://${GITHUB_TOKEN}@github.com|g' requirements.txt > requirements_https.txt cat requirements_https.txt - name: 🔧 Setup Python From 86db34eb3e99c4b49540295aa09259945709ec77 Mon Sep 17 00:00:00 2001 From: Bruno Domingues Date: Wed, 14 May 2025 14:42:35 -0300 Subject: [PATCH 04/14] Add quality gate workflow 4. --- .github/workflows/quality-gate.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/quality-gate.yml b/.github/workflows/quality-gate.yml index 7163692..a4cbbf1 100644 --- a/.github/workflows/quality-gate.yml +++ b/.github/workflows/quality-gate.yml @@ -34,8 +34,8 @@ jobs: 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|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 From 27f055e88d21af03632e1ffbdb7c943c670151e7 Mon Sep 17 00:00:00 2001 From: Bruno Domingues Date: Wed, 14 May 2025 14:54:11 -0300 Subject: [PATCH 05/14] Add quality gate workflow 5. --- .github/workflows/quality-gate.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/quality-gate.yml b/.github/workflows/quality-gate.yml index a4cbbf1..0869cd9 100644 --- a/.github/workflows/quality-gate.yml +++ b/.github/workflows/quality-gate.yml @@ -21,13 +21,14 @@ jobs: with: fetch-depth: 0 - - name: Generate GitHub App token - id: generate-token - uses: tibdex/github-app-token@v2 + - name: Generate token + id: generate_token + uses: actions/create-github-app-token@v1 with: - app_id: ${{ secrets.APP_ID }} - private_key: ${{ secrets.APP_PRIVATE_KEY }} -# installation_id: ${{ secrets.INSTALLATION_ID }} + app-id: ${{ secrets.APP_ID }} + private-key: ${{ secrets.APP_PRIVATE_KEY }} + owner: 'Aignosi' + repositories: 'sientia-dataops-library,sientia-mlops-library' - name: Create temporary requirements file env: From 5245ae291a031ad531dc6e9ae628359819cb5d2b Mon Sep 17 00:00:00 2001 From: Bruno Domingues Date: Wed, 14 May 2025 14:58:00 -0300 Subject: [PATCH 06/14] Add quality gate workflow 6. --- .github/workflows/quality-gate.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/quality-gate.yml b/.github/workflows/quality-gate.yml index 0869cd9..b30195d 100644 --- a/.github/workflows/quality-gate.yml +++ b/.github/workflows/quality-gate.yml @@ -23,12 +23,11 @@ jobs: - name: Generate token id: generate_token - uses: actions/create-github-app-token@v1 + uses: tibdex/github-app-token@v1 with: - app-id: ${{ secrets.APP_ID }} - private-key: ${{ secrets.APP_PRIVATE_KEY }} - owner: 'Aignosi' - repositories: 'sientia-dataops-library,sientia-mlops-library' + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + installation_id: ${{ secrets.INSTALLATION_ID }} - name: Create temporary requirements file env: From 04af14ff2a166e5bc1eddf2beff27339fc3ccba2 Mon Sep 17 00:00:00 2001 From: Bruno Domingues Date: Wed, 14 May 2025 15:00:35 -0300 Subject: [PATCH 07/14] Add quality gate workflow 7. --- .github/workflows/quality-gate.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/quality-gate.yml b/.github/workflows/quality-gate.yml index b30195d..aef88bc 100644 --- a/.github/workflows/quality-gate.yml +++ b/.github/workflows/quality-gate.yml @@ -22,12 +22,13 @@ jobs: fetch-depth: 0 - name: Generate token - id: generate_token - uses: tibdex/github-app-token@v1 + id: generate-token + uses: actions/create-github-app-token@v1 with: - app_id: ${{ secrets.APP_ID }} - private_key: ${{ secrets.APP_PRIVATE_KEY }} - installation_id: ${{ secrets.INSTALLATION_ID }} + app-id: ${{ secrets.APP_ID }} + private-key: ${{ secrets.APP_PRIVATE_KEY }} + owner: 'Aignosi' + repositories: 'sientia-dataops-library,sientia-mlops-library' - name: Create temporary requirements file env: From 9321d065ae30bcb940fd80517bb16706e94ceb6e Mon Sep 17 00:00:00 2001 From: Bruno Domingues Date: Wed, 14 May 2025 15:01:43 -0300 Subject: [PATCH 08/14] Add quality gate workflow 8. --- .github/workflows/quality-gate.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/quality-gate.yml b/.github/workflows/quality-gate.yml index aef88bc..ff4923d 100644 --- a/.github/workflows/quality-gate.yml +++ b/.github/workflows/quality-gate.yml @@ -36,7 +36,8 @@ jobs: 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" + # cat requirements_https.txt | sed "s|${GITHUB_TOKEN}|***MASKED***|g" + cat requirements_https.txt - name: 🔧 Setup Python uses: actions/setup-python@v4 From e50b6c09c579c3f66e0893f1319d5c06aed60f7f Mon Sep 17 00:00:00 2001 From: Bruno Domingues Date: Wed, 14 May 2025 15:03:50 -0300 Subject: [PATCH 09/14] Add quality gate workflow 9. --- .github/workflows/quality-gate.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/quality-gate.yml b/.github/workflows/quality-gate.yml index ff4923d..7b01020 100644 --- a/.github/workflows/quality-gate.yml +++ b/.github/workflows/quality-gate.yml @@ -34,10 +34,7 @@ jobs: 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" - cat requirements_https.txt + sed "s|git+ssh://git@github.com|git+https://${GITHUB_TOKEN}:x-oauth-basic@github.com|g" requirements.txt > requirements_https.txt - name: 🔧 Setup Python uses: actions/setup-python@v4 From e99931f014876a4353b44a88cc8ea40451114588 Mon Sep 17 00:00:00 2001 From: Bruno Domingues Date: Wed, 14 May 2025 15:06:30 -0300 Subject: [PATCH 10/14] Add quality gate workflow 10. --- .github/workflows/quality-gate.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/quality-gate.yml b/.github/workflows/quality-gate.yml index 7b01020..1086656 100644 --- a/.github/workflows/quality-gate.yml +++ b/.github/workflows/quality-gate.yml @@ -30,11 +30,19 @@ jobs: owner: 'Aignosi' repositories: 'sientia-dataops-library,sientia-mlops-library' - - name: Create temporary requirements file + - name: Configure Git credentials env: - GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }} + GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }} run: | - sed "s|git+ssh://git@github.com|git+https://${GITHUB_TOKEN}:x-oauth-basic@github.com|g" requirements.txt > requirements_https.txt + git config --global credential.helper store + echo "https://${GITHUB_TOKEN}:x-oauth-basic@github.com" > ~/.git-credentials + chmod 600 ~/.git-credentials + +# - name: Create temporary requirements file +# env: +# GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }} +# run: | +# sed "s|git+ssh://git@github.com|git+https://${GITHUB_TOKEN}:x-oauth-basic@github.com|g" requirements.txt > requirements_https.txt - name: 🔧 Setup Python uses: actions/setup-python@v4 @@ -45,14 +53,14 @@ jobs: uses: actions/cache@v3 with: path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('requirements_https.txt') }} + key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} restore-keys: | ${{ runner.os }}-pip- - name: 📦 Install Dependencies run: | python -m pip install --upgrade pip - pip install -r requirements_https.txt + pip install -r requirements.txt pip install pytest pytest-cov - name: ⬇️ Setup Node.js 18 From 3155f1a247aec0296d56b7e59149ba208da265f3 Mon Sep 17 00:00:00 2001 From: Bruno Domingues Date: Wed, 14 May 2025 15:10:07 -0300 Subject: [PATCH 11/14] Add quality gate workflow 11. --- .github/workflows/quality-gate.yml | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/.github/workflows/quality-gate.yml b/.github/workflows/quality-gate.yml index 1086656..9164b3d 100644 --- a/.github/workflows/quality-gate.yml +++ b/.github/workflows/quality-gate.yml @@ -30,19 +30,11 @@ jobs: owner: 'Aignosi' repositories: 'sientia-dataops-library,sientia-mlops-library' - - name: Configure Git credentials + - name: Create temporary requirements file env: - GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }} + GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }} run: | - git config --global credential.helper store - echo "https://${GITHUB_TOKEN}:x-oauth-basic@github.com" > ~/.git-credentials - chmod 600 ~/.git-credentials - -# - name: Create temporary requirements file -# env: -# GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }} -# run: | -# sed "s|git+ssh://git@github.com|git+https://${GITHUB_TOKEN}:x-oauth-basic@github.com|g" requirements.txt > requirements_https.txt + sed "s|git+ssh://git@github.com|git+https://${GITHUB_TOKEN}@github.com|g" requirements.txt > requirements_https.txt - name: 🔧 Setup Python uses: actions/setup-python@v4 @@ -53,14 +45,14 @@ jobs: uses: actions/cache@v3 with: path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} + 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.txt + pip install -r requirements_https.txt pip install pytest pytest-cov - name: ⬇️ Setup Node.js 18 @@ -73,7 +65,7 @@ jobs: - name: 🧪 Run Tests with Pytest run: | - pytest tests --junitxml=pytest.xml --cov=scouter --cov-report=xml --cov-report=term + pytest tests --junitxml=pytest.xml --cov=scouter requirements--cov-report=xml --cov-report=term - name: 📊 Run SonarQube Analysis env: From e103e7e41bc61df548565f8f34e5385d4f67bc82 Mon Sep 17 00:00:00 2001 From: Bruno Domingues Date: Wed, 14 May 2025 15:17:59 -0300 Subject: [PATCH 12/14] Add quality gate workflow 12. --- .github/workflows/quality-gate.yml | 68 +++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 15 deletions(-) diff --git a/.github/workflows/quality-gate.yml b/.github/workflows/quality-gate.yml index 9164b3d..111fd10 100644 --- a/.github/workflows/quality-gate.yml +++ b/.github/workflows/quality-gate.yml @@ -13,28 +13,65 @@ jobs: sonar: name: SonarQube Analysis 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: - name: ⬇️ Checkout Code uses: actions/checkout@v4 with: - fetch-depth: 0 - - - name: Generate token - id: generate-token + fetch-depth: 0 # Necessário para SonarQube analysis + persist-credentials: false # Importante: Evita que o token padrão do checkout interfira + + - name: Generate App Token + id: generate-app-token uses: actions/create-github-app-token@v1 with: app-id: ${{ secrets.APP_ID }} private-key: ${{ secrets.APP_PRIVATE_KEY }} - owner: 'Aignosi' - repositories: 'sientia-dataops-library,sientia-mlops-library' + owner: 'Aignosi' # O proprietário (usuário ou organização) dos repositórios + repositories: 'sientia-dataops-library,sientia-mlops-library' # Repositórios que o token do app precisa acessar - - name: Create temporary requirements file - env: - GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }} + - name: Prepare requirements.txt + id: prepare-requirements 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 uses: actions/setup-python@v4 @@ -45,14 +82,15 @@ jobs: uses: actions/cache@v3 with: 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: | ${{ runner.os }}-pip- - name: 📦 Install Dependencies run: | 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 - name: ⬇️ Setup Node.js 18 @@ -65,13 +103,13 @@ jobs: - name: 🧪 Run Tests with Pytest 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 env: SONAR_PROJECT_KEY: ${{ secrets.SONAR_PROJECT_KEY }} SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} # Este é o token do SonarQube run: | sonar-scanner \ -Dsonar.projectKey=$SONAR_PROJECT_KEY \ From 06688464ebc051f7d52d61e4f55d2d2063818497 Mon Sep 17 00:00:00 2001 From: Bruno Domingues Date: Wed, 14 May 2025 15:25:27 -0300 Subject: [PATCH 13/14] Add quality gate workflow 13. --- .github/workflows/quality-gate.yml | 46 ++++++------------------------ tests/__init__.py | 0 2 files changed, 9 insertions(+), 37 deletions(-) create mode 100644 tests/__init__.py diff --git a/.github/workflows/quality-gate.yml b/.github/workflows/quality-gate.yml index 111fd10..9acdc14 100644 --- a/.github/workflows/quality-gate.yml +++ b/.github/workflows/quality-gate.yml @@ -14,17 +14,14 @@ jobs: name: SonarQube Analysis runs-on: ubuntu-latest 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. + contents: read steps: - name: ⬇️ Checkout Code uses: actions/checkout@v4 with: - fetch-depth: 0 # Necessário para SonarQube analysis - persist-credentials: false # Importante: Evita que o token padrão do checkout interfira + fetch-depth: 0 + persist-credentials: false - name: Generate App Token id: generate-app-token @@ -32,46 +29,22 @@ jobs: with: app-id: ${{ secrets.APP_ID }} private-key: ${{ secrets.APP_PRIVATE_KEY }} - owner: 'Aignosi' # O proprietário (usuário ou organização) dos repositórios - repositories: 'sientia-dataops-library,sientia-mlops-library' # Repositórios que o token do app precisa acessar + owner: 'Aignosi' + repositories: 'sientia-dataops-library,sientia-mlops-library' - name: Prepare requirements.txt id: prepare-requirements run: | - 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 + 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 - 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 uses: actions/setup-python@v4 @@ -89,7 +62,6 @@ jobs: - name: 📦 Install Dependencies run: | python -m pip install --upgrade pip - 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 diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 From 3622d6b68c0d3f8cf2f205cd63fcc13f26d6acb0 Mon Sep 17 00:00:00 2001 From: Bruno Domingues Date: Wed, 14 May 2025 15:36:07 -0300 Subject: [PATCH 14/14] Add quality gate workflow 14. --- .github/workflows/quality-gate.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/quality-gate.yml b/.github/workflows/quality-gate.yml index 9acdc14..028daff 100644 --- a/.github/workflows/quality-gate.yml +++ b/.github/workflows/quality-gate.yml @@ -75,7 +75,20 @@ jobs: - name: 🧪 Run Tests with Pytest run: | + set +e pytest tests --junitxml=pytest.xml --cov=scouter --cov-report=xml --cov-report=term + PYTEST_EXIT_CODE=$? + set -e + + if [ $PYTEST_EXIT_CODE -eq 0 ]; then + echo "Pytest executado com sucesso." + elif [ $PYTEST_EXIT_CODE -eq 5 ]; then + echo "Pytest finalizado com código 5 (Nenhum teste encontrado). Tratando como sucesso para este workflow." + exit 0 + else + echo "Pytest falhou com código de saída $PYTEST_EXIT_CODE." + exit $PYTEST_EXIT_CODE + fi - name: 📊 Run SonarQube Analysis env: