From 66293b0b67d97651ef2bd924d435d9ac412308c8 Mon Sep 17 00:00:00 2001 From: Tom Ashworth Date: Fri, 17 Sep 2021 16:13:41 +0100 Subject: [PATCH 1/6] ci: add sonarcloud analysis --- .gitignore | 14 +++++++------- package.json | 2 +- pipelines/templates/build-and-test-job.yml | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index b8260e0..b0499e8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ -node_modules -coverage -dist -/common -generators -debug -!src/generators .vscode/settings.json +/node_modules +/coverage +/dist +/common +/generators +/debug +/test_results \ No newline at end of file diff --git a/package.json b/package.json index bb67dec..bf7df09 100644 --- a/package.json +++ b/package.json @@ -80,6 +80,6 @@ "copy-data-template": "xcopy \"src\\generators\\data\\templates\" \"generators\\data\\templates\" /I /S /y", "copy-powerbi-template": "xcopy \"src\\generators\\powerbi\\templates\" \"generators\\powerbi\\templates\" /I /S /y", "clean-debug": "del /S /q debug\\*", - "lint": "eslint .eslintrc.js ./src" + "lint": "eslint .eslintrc.js ./src --fix -o test_results/analysis/eslint.json -f json" } } diff --git a/pipelines/templates/build-and-test-job.yml b/pipelines/templates/build-and-test-job.yml index 8493b95..3315e75 100644 --- a/pipelines/templates/build-and-test-job.yml +++ b/pipelines/templates/build-and-test-job.yml @@ -33,6 +33,17 @@ jobs: inputs: verbose: true + - task: SonarCloudPrepare@1 + displayName: Prepare SonarCloud + inputs: + SonarCloud: 'SonarCloud' + organization: 'capgemini-1' + projectKey: 'Capgemini_powerapps-project-template' + projectName: 'powerapps-project-template' + projectVersion: '$(GitVersion.SemVer)' + extraProperties: | + sonar.eslint.reportPaths=$(Build.SourcesDirectory)/test_results/analysis/eslint.json + - task: Npm@1 displayName: Lint Package inputs: @@ -45,6 +56,14 @@ jobs: command: custom customCommand: run build + - task: SonarCloudAnalyze@1 + displayName: Analyse with SonarCloud + + - task: SonarCloudPublish@1 + displayName: Publish SonarCloud results + inputs: + pollingTimeoutSec: '300' + - task: WhiteSource Bolt@20 displayName: Detect security and licence issues inputs: From 24e4e42c4ef36fd2b693603ee3b7db89e69eec5a Mon Sep 17 00:00:00 2001 From: Tom Ashworth Date: Fri, 17 Sep 2021 16:22:51 +0100 Subject: [PATCH 2/6] ci: set sonarcloud.scannerMode to standalone --- pipelines/templates/build-and-test-job.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/pipelines/templates/build-and-test-job.yml b/pipelines/templates/build-and-test-job.yml index 3315e75..9b6dcbf 100644 --- a/pipelines/templates/build-and-test-job.yml +++ b/pipelines/templates/build-and-test-job.yml @@ -38,6 +38,7 @@ jobs: inputs: SonarCloud: 'SonarCloud' organization: 'capgemini-1' + scannerMode: 'Standalone' projectKey: 'Capgemini_powerapps-project-template' projectName: 'powerapps-project-template' projectVersion: '$(GitVersion.SemVer)' From fb5b368bb912849995ec95f48147051617f92446 Mon Sep 17 00:00:00 2001 From: Tom Ashworth Date: Fri, 17 Sep 2021 16:33:59 +0100 Subject: [PATCH 3/6] ci: set sonarcloud.scannerMode to CLI --- pipelines/templates/build-and-test-job.yml | 13 ++++++------- sonar-project.properties | 3 +++ 2 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 sonar-project.properties diff --git a/pipelines/templates/build-and-test-job.yml b/pipelines/templates/build-and-test-job.yml index 9b6dcbf..bd7e820 100644 --- a/pipelines/templates/build-and-test-job.yml +++ b/pipelines/templates/build-and-test-job.yml @@ -36,13 +36,12 @@ jobs: - task: SonarCloudPrepare@1 displayName: Prepare SonarCloud inputs: - SonarCloud: 'SonarCloud' - organization: 'capgemini-1' - scannerMode: 'Standalone' - projectKey: 'Capgemini_powerapps-project-template' - projectName: 'powerapps-project-template' - projectVersion: '$(GitVersion.SemVer)' + SonarCloud: "SonarCloud" + organization: "capgemini-1" + scannerMode: "CLI" + configMode: "file" extraProperties: | + soner.projectVersion=$(GitVersion.SemVer) sonar.eslint.reportPaths=$(Build.SourcesDirectory)/test_results/analysis/eslint.json - task: Npm@1 @@ -63,7 +62,7 @@ jobs: - task: SonarCloudPublish@1 displayName: Publish SonarCloud results inputs: - pollingTimeoutSec: '300' + pollingTimeoutSec: "300" - task: WhiteSource Bolt@20 displayName: Detect security and licence issues diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..aea0e0a --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,3 @@ +sonar.organization=capgemini-1 +sonar.projectKey=Capgemini_powerapps-project-template +sonar.projectName=powerapps-project-template \ No newline at end of file From cbb11a2612bff413a6b2daddd02fced560a2e2e9 Mon Sep 17 00:00:00 2001 From: Tom Ashworth Date: Fri, 17 Sep 2021 16:43:51 +0100 Subject: [PATCH 4/6] test: test sonarcloud and eslint --- src/common/utilities.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/common/utilities.ts b/src/common/utilities.ts index 30db462..83d4318 100644 --- a/src/common/utilities.ts +++ b/src/common/utilities.ts @@ -9,8 +9,6 @@ export function validateUrl(input: string): boolean | string { } export function validateEmail(input: string): boolean | string { - // tslint:disable-next-line:max-line-length - // eslint-disable-next-line no-useless-escape return /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test( input, ) From 6608003fd476c6c4a522bf77a86cf487db34e3c3 Mon Sep 17 00:00:00 2001 From: Tom Ashworth Date: Fri, 17 Sep 2021 16:55:20 +0100 Subject: [PATCH 5/6] ci: continue on linting error --- pipelines/templates/build-and-test-job.yml | 1 + sonar-project.properties | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pipelines/templates/build-and-test-job.yml b/pipelines/templates/build-and-test-job.yml index bd7e820..2638296 100644 --- a/pipelines/templates/build-and-test-job.yml +++ b/pipelines/templates/build-and-test-job.yml @@ -49,6 +49,7 @@ jobs: inputs: command: custom customCommand: run lint + continueOnError: true - task: Npm@1 displayName: Build Package diff --git a/sonar-project.properties b/sonar-project.properties index aea0e0a..ce78021 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,3 +1,4 @@ sonar.organization=capgemini-1 sonar.projectKey=Capgemini_powerapps-project-template -sonar.projectName=powerapps-project-template \ No newline at end of file +sonar.projectName=powerapps-project-template +sonar.typescript.tsconfigPath=tsconfig.json \ No newline at end of file From 2720abe3a58dd2d83cba7e006b2c2a3f10bb74bb Mon Sep 17 00:00:00 2001 From: Tom Ashworth Date: Fri, 17 Sep 2021 17:14:50 +0100 Subject: [PATCH 6/6] ci: set sonarcloud sources and tests props --- pipelines/templates/build-and-test-job.yml | 1 - sonar-project.properties | 5 ++++- src/common/utilities.ts | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pipelines/templates/build-and-test-job.yml b/pipelines/templates/build-and-test-job.yml index 2638296..2f35bfc 100644 --- a/pipelines/templates/build-and-test-job.yml +++ b/pipelines/templates/build-and-test-job.yml @@ -42,7 +42,6 @@ jobs: configMode: "file" extraProperties: | soner.projectVersion=$(GitVersion.SemVer) - sonar.eslint.reportPaths=$(Build.SourcesDirectory)/test_results/analysis/eslint.json - task: Npm@1 displayName: Lint Package diff --git a/sonar-project.properties b/sonar-project.properties index ce78021..acd33bb 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,4 +1,7 @@ sonar.organization=capgemini-1 sonar.projectKey=Capgemini_powerapps-project-template sonar.projectName=powerapps-project-template -sonar.typescript.tsconfigPath=tsconfig.json \ No newline at end of file +sonar.sources=src/ +sonar.tests=_tests_/ +sonar.typescript.tsconfigPath=tsconfig.json +sonar.eslint.reportPaths=test_results/analysis/eslint.json \ No newline at end of file diff --git a/src/common/utilities.ts b/src/common/utilities.ts index 83d4318..30db462 100644 --- a/src/common/utilities.ts +++ b/src/common/utilities.ts @@ -9,6 +9,8 @@ export function validateUrl(input: string): boolean | string { } export function validateEmail(input: string): boolean | string { + // tslint:disable-next-line:max-line-length + // eslint-disable-next-line no-useless-escape return /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test( input, )