From 25616744317d90b98634a760dab4020781ebccd3 Mon Sep 17 00:00:00 2001 From: Eduardo Gurgel Date: Sun, 3 Dec 2023 03:08:03 -0300 Subject: [PATCH] =?UTF-8?q?Altera=C3=A7=C3=B5es=20na=20branch=20para=20col?= =?UTF-8?q?eta=20das=20m=C3=A9tricas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 47 +++++++++++++++++++++++++++++++++++++ package.json | 33 +++++++++++++++++++------- parser.py | 13 ++++++---- sonar-project.properties | 19 +++++++++------ 4 files changed, 93 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..2f20b58 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,47 @@ +name: Build +on: + push: + branches: + - main + - develop + - release-sonar + pull_request: + types: [opened, synchronize, reopened] +jobs: + test-unit: + name: Test Unit & Scan + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Test Unit + id: test-unit + run: | + docker-compose -f docker-compose.test.yml up -V --force-recreate --build --abort-on-container-exit --exit-code-from gerocuidado-saude-api-test + env: + TEST: unit + + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + + test-e2e: + name: Test E2E + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Test E2E + id: test-e2e + run: | + docker-compose -f docker-compose.test.yml up -V --force-recreate --build --abort-on-container-exit --exit-code-from gerocuidado-saude-api-test + env: + TEST: e2e \ No newline at end of file diff --git a/package.json b/package.json index 95063f7..c60a70a 100644 --- a/package.json +++ b/package.json @@ -11,15 +11,16 @@ "format": "prettier --write \"src/**/*.ts\" \"e2e/**/*.ts\"", "start": "nest start --preserveWatchOutput", "start:dev": "nest start --watch --preserveWatchOutput", - "start:debug": "nest start --debug 0.0.0.0:7003 --watch --preserveWatchOutput", + "start:debug": "nest start --debug 0.0.0.0:7001 --watch --preserveWatchOutput", "start:prod": "node dist/main", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", - "test": "jest --no-cache --colors --detectOpenHandles", + "test:all": "CI=true npm run test -- --coverage", + "test": "jest --passWithNoTests --no-cache --runInBand --detectOpenHandles --coverage --colors", "test:watch": "jest --watchAll", - "test:cov": "jest --coverage --colors", + "test:cov": "jest --runInBand --coverage --colors", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", "test:e2e": "jest --forceExit --detectOpenHandles --colors --config ./e2e/jest-e2e.json", - "test:e2e:cov": "jest --forceExit --detectOpenHandles --colors --coverage --config ./e2e/jest-e2e.json", + "test:e2e:cov": "jest --runInBand --forceExit --detectOpenHandles --colors --coverage --config ./e2e/jest-e2e.json", "test:e2e:watch": "jest --detectOpenHandles --config ./e2e/jest-e2e.json --watchAll", "typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js", "typeorm:create": "npm run typeorm migration:create", @@ -27,6 +28,7 @@ "typeorm:migrate": "npm run typeorm migration:generate -- -d src/ormconfig.ts", "typeorm:run": "./node_modules/.bin/typeorm-ts-node-commonjs migration:run -d src/ormconfig.ts", "schema:drop": "npm run typeorm schema:drop", + "sonar": "sonar-scanner", "schema:sync": "npm run typeorm schema:sync" }, "dependencies": { @@ -54,6 +56,7 @@ "dotenv": "10.0.0", "express-actuator": "1.8.2", "helmet": "6.0.0", + "jest-sonar-reporter": "^2.0.0", "passport": "0.5.2", "passport-jwt": "4.0.0", "passport-local": "1.0.0", @@ -76,7 +79,7 @@ "@types/cors": "2.8.12", "@types/express": "4.17.13", "@types/express-actuator": "1.8.0", - "@types/jest": "27.0.2", + "@types/jest": "^29.5.6", "@types/node": "18.17.0", "@types/passport-jwt": "3.0.6", "@types/passport-local": "1.0.34", @@ -88,12 +91,14 @@ "eslint-config-prettier": "8.4.0", "eslint-plugin-prettier": "4.0.0", "graphql": "16.6.0", - "jest": "27.5.1", + "jest": "^29.2.1", + "jest-mock-extended": "^3.0.5", + "jest-sonar": "^0.2.16", "prettier": "2.5.1", "sonarqube-scanner": "2.8.1", "source-map-support": "0.5.21", "supertest": "6.2.2", - "ts-jest": "27.1.3", + "ts-jest": "^29.1.1", "ts-loader": "9.2.7", "ts-node": "10.6.0", "tsconfig-paths": "3.12.0", @@ -115,9 +120,21 @@ "transform": { "^.+\\.(t|j)s$": "ts-jest" }, + "collectCoverage": true, "collectCoverageFrom": [ "**/*.(t|j)s" ], + "reporters": [ + "default", + [ + "jest-sonar", + { + "outputDirectory": "reports", + "outputName": "sonar-report.xml", + "relativeRootDir": "." + } + ] + ], "coverageDirectory": "../coverage/unit", "coveragePathIgnorePatterns": [ "src/migration", @@ -133,4 +150,4 @@ ], "testEnvironment": "node" } -} +} \ No newline at end of file diff --git a/parser.py b/parser.py index 3b7b495..82d275b 100644 --- a/parser.py +++ b/parser.py @@ -1,9 +1,13 @@ import json -import requests import sys from datetime import datetime -TODAY = datetime.now() +import pytz +import requests + +desired_timezone = pytz.timezone('America/Sao_Paulo') + +TODAY = datetime.now(desired_timezone) METRICS_SONAR = [ "files", @@ -31,9 +35,10 @@ f'{BASE_URL}{REPO}&metricKeys={",".join(METRICS_SONAR)}&ps=500' ) j = json.loads(response.text) + + file_path = f'./analytics-raw-data/fga-eps-mds-{REPO}-{TODAY.strftime("%d%m%Y-%H-%M-%S")}-{RELEASE_VERSION}.json' - file_path = f'./analytics-raw-data/fga-eps-mds-{REPO}-{TODAY.strftime("%m-%d-%Y-%H-%M-%S")}-{RELEASE_VERSION}.json' with open(file_path, "w") as fp: fp.write(json.dumps(j)) - fp.close() + fp.close() \ No newline at end of file diff --git a/sonar-project.properties b/sonar-project.properties index e1e3eb6..6dc01c3 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,13 +1,18 @@ sonar.projectKey=fga-eps-mds_2023-2-GEROcuidado-APISaude sonar.organization=fga-eps-mds-1 +sonar.projectName=2023-2-GEROcuidado-APISaude -sonar.sources=./src -sonar.sources.exclusions=./e2e, /.vscode +sonar.host.url=https://sonarcloud.io -sonar.tests=./e2e +sonar.sourceEncoding=UTF-8 +sonar.python.version=3 -sonar.dynamicAnalysis=reuseReports -sonar.core.codeCoveragePlugin=cobertura -sonar.python.coverage.reportPaths=coverage.xml -sonar.python.xunit.reportPath=junit.xml +sonar.sources=src +sonar.exclusions=**/main.ts,**/ormconfig.ts,**/*.module.ts,src/migration/*.ts,src/migrations.ts + +sonar.javascript.lcov.reportPaths=coverage/unit/lcov.info + +sonar.tests=src +sonar.test.inclusions=**/*.spec.ts +sonar.testExecutionReportPaths=reports/sonar-report.xml \ No newline at end of file