From 81fc6d9938a6e07e58a4220323f957b06ead3c5a Mon Sep 17 00:00:00 2001 From: Maximilien B Date: Tue, 14 May 2024 18:16:48 +0200 Subject: [PATCH] Enable sonarqube on ember-brand-manager --- .gitignore | 1 + Makefile | 51 ++++++++++++ index.js | 3 + package.json | 1 + pnpm-lock.yaml | 153 ++++++++++++++++++++++++++++++++++ scripts/generate_sonar_report | 40 +++++++++ scripts/new-version-tag | 43 ++++++++++ sonar-project.properties | 10 +++ tests/test-helper.js | 5 ++ 9 files changed, 307 insertions(+) create mode 100644 Makefile create mode 100755 scripts/generate_sonar_report create mode 100755 scripts/new-version-tag create mode 100644 sonar-project.properties diff --git a/.gitignore b/.gitignore index e13aa7d..730cccc 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ /libpeerconnection.log /npm-debug.log* /testem.log +.scannerwork/ # ember-try /.node_modules.ember-try/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..cea6ada --- /dev/null +++ b/Makefile @@ -0,0 +1,51 @@ +.PHONY: start + +.EXPORT_ALL_VARIABLES: + +SHELL := /bin/bash +PORT := 0 +ENV := development + +all: clear echo start ## Starts the dev server + +clear: + @clear + +install: ## Runs 'pnpm' to install dependencies + @echo 'Installing dependencies' + pnpm install + @echo ""; echo "-------------------------------"; echo "" + +echo: + @echo Starting ember-brand-manager + +start: + ember s --port $(PORT) --environment ${ENV} + +build: + ember build --environment ${ENV} + +clean: ## Cleans ./node_modules && ./dist + @echo "Cleaning up ./node_modules & ./dist folders" + -rm -r ./node_modules + -rm -r ./dist + @echo ""; echo "-------------------------------"; echo "" + +re: clean install echo start ## Reinstalls dependencies & starts the dev server + +help: clear ## Displays the help message + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +h: help ## Displays the help message + +version_patch: ## Creates & pushes a new patch tag + ./scripts/new-version-tag patch + +version_minor: ## Creates & pushes a new minor tag + ./scripts/new-version-tag minor + +version_major: ## Creates & pushes a new major tag + ./scripts/new-version-tag major + +sonar-report: ## Runs a bunch of commands that will finally lead to a new report in sonarqube + ./scripts/generate_sonar_report diff --git a/index.js b/index.js index b1e9203..4b0667d 100644 --- a/index.js +++ b/index.js @@ -14,6 +14,9 @@ module.exports = { brand: process.env.BRAND || DEFAULT_BRAND, brandPageTitle: process.env.BRAND_PAGE_TITLE || DEFAULT_PAGE_TITLE } + }, + babel: { + plugins: [...require('ember-cli-code-coverage').buildBabelPlugin()], } }, diff --git a/package.json b/package.json index a81d838..1cb442f 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "babel-eslint": "^10.1.0", "ember-auto-import": "^2.2.4", "ember-cli": "~4.0.0", + "ember-cli-code-coverage": "^3.0.0", "ember-cli-dependency-checker": "^3.2.0", "ember-cli-inject-live-reload": "^2.1.0", "ember-disable-prototype-extensions": "^1.1.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1785d9a..a8dcd13 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -118,6 +118,9 @@ devDependencies: ember-cli: specifier: ~4.0.0 version: 4.0.1 + ember-cli-code-coverage: + specifier: ^3.0.0 + version: 3.0.0 ember-cli-dependency-checker: specifier: ^3.2.0 version: 3.3.1(ember-cli@4.0.1) @@ -1667,6 +1670,22 @@ packages: resolution: {integrity: sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==} dev: true + /@istanbuljs/load-nyc-config@1.1.0: + resolution: {integrity: sha512-VjeHSlIzpv/NyD3N0YuHfXOPDIixcA1q2ZV98wsMqcYlPmv2n3Yb2lYP9XMElnaFVXg5A7YLTeLu6V84uQDjmQ==} + engines: {node: '>=8'} + dependencies: + camelcase: 5.3.1 + find-up: 4.1.0 + get-package-type: 0.1.0 + js-yaml: 3.14.1 + resolve-from: 5.0.0 + dev: true + + /@istanbuljs/schema@0.1.3: + resolution: {integrity: sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==} + engines: {node: '>=8'} + dev: true + /@jridgewell/gen-mapping@0.3.3: resolution: {integrity: sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==} engines: {node: '>=6.0.0'} @@ -3005,6 +3024,19 @@ packages: parse-static-imports: 1.1.0 string.prototype.matchall: 4.0.8 + /babel-plugin-istanbul@6.1.1: + resolution: {integrity: sha512-Y1IQok9821cC9onCx5otgFfRm7Lm+I+wwxOx738M/WLPZ9Q42m4IG5W0FNX8WLL2gYMZo3JkuXIH2DOpWM+qwA==} + engines: {node: '>=8'} + dependencies: + '@babel/helper-plugin-utils': 7.20.2 + '@istanbuljs/load-nyc-config': 1.1.0 + '@istanbuljs/schema': 0.1.3 + istanbul-lib-instrument: 5.2.1 + test-exclude: 6.0.0 + transitivePeerDependencies: + - supports-color + dev: true + /babel-plugin-module-resolver@3.2.0: resolution: {integrity: sha512-tjR0GvSndzPew/Iayf4uICWZqjBwnlMWjSx6brryfQ81F9rxBVqwDJtFCV8oOs0+vJeefK9TmdZtkIFdFe1UnA==} engines: {node: '>= 6.0.0'} @@ -3857,6 +3889,11 @@ packages: engines: {node: '>=6'} dev: true + /camelcase@5.3.1: + resolution: {integrity: sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==} + engines: {node: '>=6'} + dev: true + /can-symlink@1.0.0: resolution: {integrity: sha512-RbsNrFyhwkx+6psk/0fK/Q9orOUr9VMxohGd8vTa4djf4TGLfblBgUfqZChrZuW0Q+mz2eBPFLusw9Jfukzmhg==} hasBin: true @@ -4968,6 +5005,33 @@ packages: transitivePeerDependencies: - supports-color + /ember-cli-code-coverage@3.0.0: + resolution: {integrity: sha512-IAVET5oKS0IkEAPUTKOzHlNk1Z+986//8LZmfqhkSGkGJ76tFLw8AAS+BloUctX7J/xCUNn/1voBVqb5oabMPw==} + engines: {node: '>= 18'} + peerDependencies: + '@embroider/compat': ^0.47.0 || ^1.0.0 || ^2.0.0 || >=3.0.0 + '@embroider/core': ^0.47.0 || ^1.0.0 || ^2.0.0 || >=3.0.0 + peerDependenciesMeta: + '@embroider/compat': + optional: true + '@embroider/core': + optional: true + dependencies: + babel-plugin-istanbul: 6.1.1 + body-parser: 1.20.1 + ember-cli-babel: 7.26.11 + express: 4.18.2 + fs-extra: 9.1.0 + istanbul-lib-coverage: 3.2.2 + istanbul-lib-report: 3.0.1 + istanbul-lib-source-maps: 4.0.1 + istanbul-reports: 3.1.7 + node-dir: 0.1.17 + walk-sync: 2.2.0 + transitivePeerDependencies: + - supports-color + dev: true + /ember-cli-dependency-checker@3.3.1(ember-cli@4.0.1): resolution: {integrity: sha512-Tg6OeijjXNKWkDm6057Tr0N9j9Vlz/ITewXWpn1A/+Wbt3EowBx5ZKfvoupqz05EznKgL1B/ecG0t+JN7Qm6MA==} engines: {node: '>= 6'} @@ -6740,6 +6804,11 @@ packages: has: 1.0.3 has-symbols: 1.0.3 + /get-package-type@0.1.0: + resolution: {integrity: sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==} + engines: {node: '>=8.0.0'} + dev: true + /get-stdin@4.0.1: resolution: {integrity: sha512-F5aQMywwJ2n85s4hJPTT9RPxGmubonuB10MNYo17/xph174n2MIR33HRguhzVag10O/npM7SPk73LMZNP+FaWw==} engines: {node: '>=0.10.0'} @@ -7130,6 +7199,10 @@ packages: lru-cache: 6.0.0 dev: true + /html-escaper@2.0.2: + resolution: {integrity: sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==} + dev: true + /http-cache-semantics@4.1.1: resolution: {integrity: sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==} dev: true @@ -7655,6 +7728,52 @@ packages: engines: {node: '>=0.10.0'} dev: true + /istanbul-lib-coverage@3.2.2: + resolution: {integrity: sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==} + engines: {node: '>=8'} + dev: true + + /istanbul-lib-instrument@5.2.1: + resolution: {integrity: sha512-pzqtp31nLv/XFOzXGuvhCb8qhjmTVo5vjVk19XE4CRlSWz0KoeJ3bw9XsA7nOp9YBf4qHjwBxkDzKcME/J29Yg==} + engines: {node: '>=8'} + dependencies: + '@babel/core': 7.21.4 + '@babel/parser': 7.22.4 + '@istanbuljs/schema': 0.1.3 + istanbul-lib-coverage: 3.2.2 + semver: 6.3.0 + transitivePeerDependencies: + - supports-color + dev: true + + /istanbul-lib-report@3.0.1: + resolution: {integrity: sha512-GCfE1mtsHGOELCU8e/Z7YWzpmybrx/+dSTfLrvY8qRmaY6zXTKWn6WQIjaAFw069icm6GVMNkgu0NzI4iPZUNw==} + engines: {node: '>=10'} + dependencies: + istanbul-lib-coverage: 3.2.2 + make-dir: 4.0.0 + supports-color: 7.2.0 + dev: true + + /istanbul-lib-source-maps@4.0.1: + resolution: {integrity: sha512-n3s8EwkdFIJCG3BPKBYvskgXGoy88ARzvegkitk60NxRdwltLOTaH7CUiMRXvwYorl0Q712iEjcWB+fK/MrWVw==} + engines: {node: '>=10'} + dependencies: + debug: 4.3.4 + istanbul-lib-coverage: 3.2.2 + source-map: 0.6.1 + transitivePeerDependencies: + - supports-color + dev: true + + /istanbul-reports@3.1.7: + resolution: {integrity: sha512-BewmUXImeuRk2YY0PVbxgKAysvhRPUQE0h5QRM++nVWyubKGV0l8qQ5op8+B2DOmwSe63Jivj0BjkPQVf8fP5g==} + engines: {node: '>=8'} + dependencies: + html-escaper: 2.0.2 + istanbul-lib-report: 3.0.1 + dev: true + /istextorbinary@2.1.0: resolution: {integrity: sha512-kT1g2zxZ5Tdabtpp9VSdOzW9lb6LXImyWbzbQeTxoRtHhurC9Ej9Wckngr2+uepPL09ky/mJHmN9jeJPML5t6A==} engines: {node: '>=0.12'} @@ -8147,6 +8266,13 @@ packages: semver: 6.3.0 dev: true + /make-dir@4.0.0: + resolution: {integrity: sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==} + engines: {node: '>=10'} + dependencies: + semver: 7.6.2 + dev: true + /makeerror@1.0.12: resolution: {integrity: sha512-JmqCvUhmt43madlpFzG4BQzG2Z3m6tvQDNKdClZnO3VbIudJYmxsT0FNJMeiB2+JTSlTQTSbU8QdesVmwJcmLg==} dependencies: @@ -8543,6 +8669,13 @@ packages: tslib: 2.5.0 dev: true + /node-dir@0.1.17: + resolution: {integrity: sha512-tmPX422rYgofd4epzrNoOXiE8XFZYOcCq1vD7MAXCDO+O+zndlA2ztdKKMa+EeuBG5tHETpr4ml4RGgpqDCCAg==} + engines: {node: '>= 0.10.5'} + dependencies: + minimatch: 3.1.2 + dev: true + /node-fetch@2.6.9: resolution: {integrity: sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==} engines: {node: 4.x || >=6.0.0} @@ -9661,6 +9794,11 @@ packages: engines: {node: '>=4'} dev: true + /resolve-from@5.0.0: + resolution: {integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==} + engines: {node: '>=8'} + dev: true + /resolve-package-path@1.2.7: resolution: {integrity: sha512-fVEKHGeK85bGbVFuwO9o1aU0n3vqQGrezPc51JGu9UTXpFQfWq5qCeKxyaRUSvephs+06c5j5rPq/dzHGEo8+Q==} dependencies: @@ -9901,6 +10039,12 @@ packages: dependencies: lru-cache: 6.0.0 + /semver@7.6.2: + resolution: {integrity: sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==} + engines: {node: '>=10'} + hasBin: true + dev: true + /send@0.18.0: resolution: {integrity: sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==} engines: {node: '>= 0.8.0'} @@ -10643,6 +10787,15 @@ packages: source-map-support: 0.5.21 dev: true + /test-exclude@6.0.0: + resolution: {integrity: sha512-cAGWPIyOHU6zlmg88jwm7VRyXnMN7iV68OGAbYDk/Mh/xC/pzVPlQtY6ngoIH/5/tciuhGfvESU8GrHrcxD56w==} + engines: {node: '>=8'} + dependencies: + '@istanbuljs/schema': 0.1.3 + glob: 7.2.3 + minimatch: 3.1.2 + dev: true + /testem@3.10.1: resolution: {integrity: sha512-42c4e7qlAelwMd8O3ogtVGRbgbr6fJnX6H51ACOIG1V1IjsKPlcQtxPyOwaL4iikH22Dfh+EyIuJnMG4yxieBQ==} engines: {node: '>= 7.*'} diff --git a/scripts/generate_sonar_report b/scripts/generate_sonar_report new file mode 100755 index 0000000..1efecfd --- /dev/null +++ b/scripts/generate_sonar_report @@ -0,0 +1,40 @@ +#!/bin/bash +## This script automates the flow to generate a new activity report in sonarqube + +echo "[Generating a sonar report.]" +echo "" +echo "" + +## Check that sonarqube property file exists +echo "[Step1] Check for sonar-project.properties file existence:" +if test -f "./sonar-project.properties"; then + echo "File exists." +else + echo "File is missing. Check your configuration." + exit 1 +fi + +## Run ember test & generate code coverage with [ember-cli-code-coverage] +echo "" +echo "" +echo "[Step2] Run ember test - dot reporter to generate lcovinfo file" +COVERAGE=true ember test + +## Check that coverage folder has been generated +echo "" +echo "" +echo "[Step3] Check that coverage folder has been generated" +if [ -d "./coverage" ]; then + echo "./coverage directory successfully created." +else + echo "./coverage directory not found. Check your configuration." + exit 1 +fi + +## Run sonar-scanner with the proper project version +echo "" +echo "" +echo "[Step4] Run sonar-scanner" +sonar-scanner -D sonar.projectVersion=$(git describe --tags --abbrev=0) -Dsonar.login=$SONARCLOUD_FRONTEND_TOKEN + +echo "[Success]" diff --git a/scripts/new-version-tag b/scripts/new-version-tag new file mode 100755 index 0000000..1de4a97 --- /dev/null +++ b/scripts/new-version-tag @@ -0,0 +1,43 @@ +#!/bin/bash + +if [ $# -eq 0 ]; then + echo "Please specify a SemVer identifier (e.g. patch, minor, major)." + exit 1 +fi + +echo -e "[Creating a new \033[1;34m$1\033[0m version]"; +echo "" +echo "" + +echo "[1/3] creating tag" +npm version $1 +if [ $? -ne 0 ]; then + echo "[1/3] KO: Tag creation failed." + echo "Aborting." + exit 1 +fi +echo "[1/3] OK: New {$1} tag created" + +echo "" +echo "" + +echo "[2/3] Pushing new tag to remote" +git push --tag --no-verify +if [ $? -ne 0 ]; then + echo "[2/3] KO: Could not push to remote." + echo "Aborting." + exit 1 +fi +echo "[2/3] OK: New {$1} tag pushed to remote" + +echo "" +echo "" + +echo "[3/3] Pushing branch remote" +git push --no-verify +if [ $? -ne 0 ]; then + echo "[3/3] KO: Could not push to remote." + echo "Aborting." + exit 1 +fi +echo "[3/3] OK: Branch successfully pushed to remote" diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..8d984ed --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,10 @@ +sonar.projectKey=ember-brand-manager +sonar.host.url=https://sonarqube.upfluence.co +sonar.organization=upfluence +sonar.sources=addon/,app/ +sonar.javascript.lcov.reportPaths=./coverage/lcov.info +sonar.typescript.tsconfigPaths=./tsconfig.json +sonar.coverage.exclusions=app/ +sonar.cpd.exclusions=tests/,**/tests/**,*-test.js,*-test.ts,test-support/ +sonar.tests=tests/ +sonar.html.file.suffixes=.hbs diff --git a/tests/test-helper.js b/tests/test-helper.js index 4efd6e5..36c639f 100644 --- a/tests/test-helper.js +++ b/tests/test-helper.js @@ -4,9 +4,14 @@ import * as QUnit from 'qunit'; import { setApplication } from '@ember/test-helpers'; import { setup } from 'qunit-dom'; import { start } from 'ember-qunit'; +import { forceModulesToBeLoaded, sendCoverage } from 'ember-cli-code-coverage/test-support'; setApplication(Application.create(config.APP)); setup(QUnit.assert); +QUnit.done(async function () { + forceModulesToBeLoaded(); + await sendCoverage(); +}); start();