Skip to content

Commit

Permalink
[config] - Configura CI e relatório do Sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
saracampss committed Jul 24, 2024
1 parent 5c5f38c commit 604c8a6
Show file tree
Hide file tree
Showing 12 changed files with 1,094 additions and 416 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
env: { browser: true, es2020: true, node: true },
extends: [
'eslint:recommended',
'plugin:react/recommended',
Expand Down
166 changes: 166 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
name: front-ci

on:
push:
branches: [main, devel]
pull_request:
branches:
- main
- devel
types: [opened, synchronize, reopened]

jobs:

# ------------------------ TO DO: ADICIONAR BIBLIOTECAS DE ESTILIZACAO DE CODIGO (ES-LINT E PRETTIER) ---------------------------------

# format:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v3

# - name: Use Node.js 20.x
# uses: actions/setup-node@v3
# with:
# node-version: 20.x

# - name: 📬 Caching
# uses: actions/cache@v3
# with:
# path: |
# ${{ github.workspace }}/node_modules
# ${{ github.workspace }}/dist
# key: ${{ runner.os }}-vite-${{ hashFiles('*/package-lock.json') }}-${{ hashFiles('/.{js,jsx,ts,tsx}') }}
# restore-keys: |
# ${{ runner.os }}-vite-${{ hashFiles('**/package-lock.json') }}-

# - name: 🧰 Instala bibliotecas e dependências
# run: npm i

# - name: 🔍 Verifica estilização do código
# run: npm run check-format

# lint:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v3

# - name: Use Node.js 20.x
# uses: actions/setup-node@v3
# with:
# node-version: 20.x

# - name: 📬 Caching
# uses: actions/cache@v3
# with:
# path: |
# ${{ github.workspace }}/node_modules
# ${{ github.workspace }}/dist
# key: ${{ runner.os }}-vite-${{ hashFiles('*/package-lock.json') }}-${{ hashFiles('/.{js,jsx,ts,tsx}') }}
# restore-keys: |
# ${{ runner.os }}-vite-${{ hashFiles('**/package-lock.json') }}-

# - name: 🧰 Instala bibliotecas e dependências
# run: npm i

# - name: 🧹 Verifica eslint
# run: npm run check-lint

# ------------------------ TO DO: ADICIONAR BIBLIOTECAS DE ESTILIZACAO DE CODIGO (ES-LINT E PRETTIER) ---------------------------------

test:
runs-on: ubuntu-latest
# TO DO: adicionar variaveis de ambiente conforme necessario
# env:
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x

- name: 📬 Caching
uses: actions/cache@v3
with:
path: |
${{ github.workspace }}/node_modules
${{ github.workspace }}/dist
key: ${{ runner.os }}-vite-${{ hashFiles('*/package-lock.json') }}-${{ hashFiles('/.{js,jsx,ts,tsx}') }}
restore-keys: |
${{ runner.os }}-vite-${{ hashFiles('**/package-lock.json') }}-
- name: 🧰 Instala bibliotecas e dependências
run: npm i

- name: 🧪 Roda suíte de testes
run: npm test

build:
# TO DO: adicionar format e lint apos configurar prettier e es-lint
# needs: [format, lint]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x

- name: 📬 Caching
uses: actions/cache@v3
with:
path: |
${{ github.workspace }}/node_modules
${{ github.workspace }}/dist
key: ${{ runner.os }}-vite-${{ hashFiles('*/package-lock.json') }}-${{ hashFiles('/.{js,jsx,ts,tsx}') }}
restore-keys: |
${{ runner.os }}-vite-${{ hashFiles('**/package-lock.json') }}-
- name: 🧰 Instala bibliotecas e dependências
run: npm i

- name: 📦 Builda o projeto
run: npm run build

sonarcloud:
# TO DO: adicionar variaveis de ambiente conforme necessario
# env:
name: sonarcloud
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: 📬 Caching
uses: actions/cache@v3
with:
path: |
${{ github.workspace }}/node_modules
${{ github.workspace }}/dist
key: ${{ runner.os }}-vite-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.{js,jsx,ts,tsx}') }}
restore-keys: |
${{ runner.os }}-vite-${{ hashFiles('**/package-lock.json') }}-
- name: 🧰 Instala bibliotecas e dependências
run: npm i

# TODO: Setup eslint
# - name: 📜 Relatório do eslint
# run: npx eslint -f json -o reports/eslint-report.json src || true

- name: 🧪 Testes e cobertura
run: VITEST_REPORTER=vitest-sonar-reporter CI=true npm test -- --coverage

- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: front-release

on:
push:
branches: [main, devel]
tags:
- "v*"

jobs:
generate-release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: 'Get Previous tag'
id: previoustag
uses: "WyriHaximus/github-action-get-previous-tag@v1"
with:
fallback: 1.0.0

- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 16.x

- name: Cria métricas do SonarCloud
run: python metrics/sonar-metrics.py ${{ github.event.repository.name }} ${{ github.ref_name }}

- name: Commita arquivos de métricas do SonarCloud
run: |
git config --global user.email "${{ secrets.GIT_EMAIL }}"
git config --global user.name "${{ secrets.GIT_USER }}"
git clone --single-branch --branch main "https://x-access-token:${{ secrets.PERSONAL_TOKEN }}@github.com/fga-eps-mds/2024.1-SENTINELA-DOC" doc
mkdir -p doc/analytics-raw-data
cp -R fga-eps-mds*.json doc/analytics-raw-data
cd doc
git add .
git commit -m "Métricas SonarCloud - ${{ github.event.repository.name }} ${{ github.ref_name }}"
git push
echo "Arquivos de métricas gerado com sucesso."
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ dist-ssr
*.njsproj
*.sln
*.sw?

# Tests coverage report
coverage/
41 changes: 41 additions & 0 deletions metrics/sonar-metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import json
import sys
import urllib.request
from datetime import datetime

def generate_metrics():
base_url = "https://sonarcloud.io/api/measures/component_tree?component="
prefix = "fga-eps-mds"
metrics = [
"files",
"functions",
"complexity",
"comment_lines_density",
"duplicated_lines_density",
"coverage",
"ncloc",
"tests",
"test_errors",
"test_failures",
"test_execution_time",
"security_rating"
]

repository_name = sys.argv[1]
repository_version = sys.argv[2]
underlined_repo_name = repository_name[:16] + \
repository_name[16:].replace('-', "_")
url = f'{base_url}{repository_name}&metricKeys={",".join(metrics)}'
with urllib.request.urlopen(url) as res:
data = json.load(res)
date = datetime.now()
date_padrao_hilmer = f"{date.month}-{date.day}-{date.year}-{date.hour}-{date.minute}-{date.second}"

filename = f"{prefix}-{underlined_repo_name}-{date_padrao_hilmer}-{repository_version}.json"
print(filename)
with open(filename, "w") as file:
json.dump(data, file)


if __name__ == "__main__":
generate_metrics()
Loading

0 comments on commit 604c8a6

Please sign in to comment.