From 89eba1f0622a489e1e0b92316aaeedbd369c187f Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Thu, 17 Jun 2021 11:36:05 +0200 Subject: [PATCH] SONAR-15029 C-Family tutorial for Bitbucket Pipelines --- .../bitbucket-pipelines/AnalysisCommand.tsx | 156 ++---------------- .../bitbucket-pipelines/PreambuleYaml.tsx | 1 + .../__tests__/AnalysisCommand-test.tsx | 21 ++- .../__tests__/PreambuleYaml-test.tsx | 15 +- .../AnalysisCommand-test.tsx.snap | 138 +++++++++++++++- .../__snapshots__/PreambuleYaml-test.tsx.snap | 27 +++ .../bitbucket-pipelines/commands/CFamily.ts | 64 +++++++ .../bitbucket-pipelines/commands/DotNet.ts | 64 +++++++ .../bitbucket-pipelines/commands/Gradle.ts | 55 ++++++ .../bitbucket-pipelines/commands/Maven.ts | 55 ++++++ .../bitbucket-pipelines/commands/Others.ts | 55 ++++++ 11 files changed, 490 insertions(+), 161 deletions(-) create mode 100644 server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/CFamily.ts create mode 100644 server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/DotNet.ts create mode 100644 server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Gradle.ts create mode 100644 server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Maven.ts create mode 100644 server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Others.ts diff --git a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/AnalysisCommand.tsx b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/AnalysisCommand.tsx index 84c136e433c..1c53cd067be 100644 --- a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/AnalysisCommand.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/AnalysisCommand.tsx @@ -20,8 +20,14 @@ import { Dictionary } from 'lodash'; import * as React from 'react'; import { withAppState } from '../../hoc/withAppState'; +import { CompilationInfo } from '../components/CompilationInfo'; import CreateYmlFile from '../components/CreateYmlFile'; import { BuildTools } from '../types'; +import cFamilyExample from './commands/CFamily'; +import dotNetExample from './commands/DotNet'; +import gradleExample from './commands/Gradle'; +import mavenExample from './commands/Maven'; +import othersExample from './commands/Others'; import { PreambuleYaml } from './PreambuleYaml'; export interface AnalysisCommandProps { @@ -31,150 +37,11 @@ export interface AnalysisCommandProps { } const YamlTemplate: Dictionary<(branchesEnabled?: boolean, projectKey?: string) => string> = { - [BuildTools.Gradle]: branchesEnabled => `image: openjdk:8 - -clone: - depth: full - -pipelines: - branches: - '{master}': - - step: - name: SonarQube analysis - caches: - - gradle - - sonar - script: - - bash ./gradlew sonarqube -${ - branchesEnabled - ? ` - pull-requests: - '**': - - step: - name: SonarQube analysis - caches: - - gradle - - sonar - script: - - bash ./gradlew sonarqube -` - : '' -} -definitions: - caches: - sonar: ~/.sonar`, - [BuildTools.Maven]: branchesEnabled => `image: maven:3.3.9 - -clone: - depth: full - -pipelines: - branches: - '{master}': - - step: - name: SonarQube analysis - caches: - - maven - - sonar - script: - - mvn verify sonar:sonar -${ - branchesEnabled - ? ` - pull-requests: - '**': - - step: - name: SonarQube analysis - caches: - - maven - - sonar - script: - - mvn verify sonar:sonar -` - : '' -} -definitions: - caches: - sonar: ~/.sonar`, - [BuildTools.DotNet]: ( - branchesEnabled, - projectKey - ) => `image: mcr.microsoft.com/dotnet/core/sdk:latest - -pipelines: - branches: - '{master}': - - step: - name: SonarQube analysis - caches: - - dotnetcore - - sonar - script: - - apt-get update - - apt-get install --yes openjdk-11-jre - - dotnet tool install --global dotnet-sonarscanner - - export PATH="$PATH:/root/.dotnet/tools" - - dotnet sonarscanner begin /k:"${projectKey}" /d:"sonar.login=\${SONAR_TOKEN}" /d:"sonar.host.url=\${SONAR_HOST_URL}" - - dotnet build - - dotnet sonarscanner end /d:"sonar.login=\${SONAR_TOKEN}" - ${ - branchesEnabled - ? ` - pull-requests: - '**': - - step: - name: SonarQube analysis - caches: - - dotnetcore - - sonar - script: - - apt-get update - - apt-get install --yes openjdk-11-jre - - dotnet tool install --global dotnet-sonarscanner - - export PATH="$PATH:/root/.dotnet/tools" - - dotnet sonarscanner begin /k:"${projectKey}" /d:"sonar.login=\${SONAR_TOKEN}" /d:"sonar.host.url=\${SONAR_HOST_URL}" - - dotnet build - - dotnet sonarscanner end /d:"sonar.login=\${SONAR_TOKEN}" - ` - : '' - } -definitions: - caches: - sonar: ~/.sonar`, - [BuildTools.Other]: branchesEnabled => `image: maven:3.3.9 - -clone: - depth: full - -pipelines: - branches: - '{master}': - - step: - name: SonarQube analysis - script: - - pipe: sonarsource/sonarqube-scan:1.0.0 - variables: - SONAR_HOST_URL: \${SONAR_HOST_URL} # Get the value from the repository/workspace variable. - SONAR_TOKEN: \${SONAR_TOKEN} # Get the value from the repository/workspace variable. You shouldn't set secret in clear text here. -${ - branchesEnabled - ? ` - pull-requests: - '**': - - step: - name: SonarQube analysis - script: - - pipe: sonarsource/sonarqube-scan:1.0.0 - variables: - SONAR_HOST_URL: \${SONAR_HOST_URL} # Get the value from the repository/workspace variable. - SONAR_TOKEN: \${SONAR_TOKEN} # Get the value from the repository/workspace variable. You shouldn't set secret in clear text here. -` - : '' -} -definitions: - caches: - sonar: ~/.sonar` + [BuildTools.Gradle]: gradleExample, + [BuildTools.Maven]: mavenExample, + [BuildTools.DotNet]: dotNetExample, + [BuildTools.CFamily]: cFamilyExample, + [BuildTools.Other]: othersExample }; export function AnalysisCommand(props: AnalysisCommandProps) { @@ -194,6 +61,7 @@ export function AnalysisCommand(props: AnalysisCommandProps) { <> + {buildTool === BuildTools.CFamily && } ); } diff --git a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/PreambuleYaml.tsx b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/PreambuleYaml.tsx index f27c17e23d5..910cfa3034c 100644 --- a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/PreambuleYaml.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/PreambuleYaml.tsx @@ -71,6 +71,7 @@ export function PreambuleYaml(props: PreambuleYamlProps) { ); + case BuildTools.CFamily: case BuildTools.Other: return ; default: diff --git a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/AnalysisCommand-test.tsx b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/AnalysisCommand-test.tsx index fe163ec5ba7..ff047ac097e 100644 --- a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/AnalysisCommand-test.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/AnalysisCommand-test.tsx @@ -23,15 +23,18 @@ import { mockAppState, mockComponent } from '../../../../helpers/testMocks'; import { BuildTools } from '../../types'; import { AnalysisCommand, AnalysisCommandProps } from '../AnalysisCommand'; -it.each([[BuildTools.DotNet], [BuildTools.Gradle], [BuildTools.Maven], [BuildTools.Other]])( - 'should render correctly for %s', - buildTool => { - expect(shallowRender({ buildTool })).toMatchSnapshot(); - expect( - shallowRender({ appState: mockAppState({ branchesEnabled: true }), buildTool }) - ).toMatchSnapshot('with branch enabled'); - } -); +it.each([ + [BuildTools.CFamily], + [BuildTools.DotNet], + [BuildTools.Gradle], + [BuildTools.Maven], + [BuildTools.Other] +])('should render correctly for %s', buildTool => { + expect(shallowRender({ buildTool })).toMatchSnapshot(); + expect( + shallowRender({ appState: mockAppState({ branchesEnabled: true }), buildTool }) + ).toMatchSnapshot('with branch enabled'); +}); function shallowRender(props: Partial = {}) { return shallow( diff --git a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/PreambuleYaml-test.tsx b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/PreambuleYaml-test.tsx index c8c5a5248c2..bf5057ade16 100644 --- a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/PreambuleYaml-test.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/PreambuleYaml-test.tsx @@ -23,12 +23,15 @@ import { mockComponent } from '../../../../helpers/testMocks'; import { BuildTools } from '../../types'; import { PreambuleYaml, PreambuleYamlProps } from '../PreambuleYaml'; -it.each([[BuildTools.DotNet], [BuildTools.Gradle], [BuildTools.Maven], [BuildTools.Other]])( - 'should render correctly for %s', - buildTool => { - expect(shallowRender({ buildTool })).toMatchSnapshot(); - } -); +it.each([ + [BuildTools.DotNet], + [BuildTools.Gradle], + [BuildTools.Maven], + [BuildTools.CFamily], + [BuildTools.Other] +])('should render correctly for %s', buildTool => { + expect(shallowRender({ buildTool })).toMatchSnapshot(); +}); function shallowRender(props: Partial = {}) { return shallow( diff --git a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/__snapshots__/AnalysisCommand-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/__snapshots__/AnalysisCommand-test.tsx.snap index 51a6080106e..fee8cfa96ea 100644 --- a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/__snapshots__/AnalysisCommand-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/__snapshots__/AnalysisCommand-test.tsx.snap @@ -1,5 +1,139 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`should render correctly for cfamily 1`] = ` + + + + + +`; + +exports[`should render correctly for cfamily: with branch enabled 1`] = ` + + + + + +`; + exports[`should render correctly for dotnet 1`] = ` +`; + exports[`should render correctly for dotnet 1`] = `""`; exports[`should render correctly for gradle 1`] = ` diff --git a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/CFamily.ts b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/CFamily.ts new file mode 100644 index 00000000000..87f30846c4e --- /dev/null +++ b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/CFamily.ts @@ -0,0 +1,64 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +export default function cFamilyExample(branchesEnabled: boolean) { + return `image: + +clone: + depth: full + +pipelines: + branches: + '{master}': + - step: + name: Download and install the build wrapper, build the project + script: + - mkdir $HOME/.sonar + - curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip \${SONAR_HOST_URL}/static/cpp/build-wrapper-linux-x86.zip + - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/ + - $HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output + - pipe: sonarsource/sonarqube-scan:1.0.0 + variables: + EXTRA_ARGS: -Dsonar.cfamily.build-wrapper-output=bw-output + SONAR_HOST_URL: \${SONAR_HOST_URL} + SONAR_TOKEN: \${SONAR_TOKEN} +${ + branchesEnabled + ? ` + pull-requests: + '**': + - step: + name: Download and install the build wrapper, build the project + script: + - mkdir $HOME/.sonar + - curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip \${SONAR_HOST_URL}/static/cpp/build-wrapper-linux-x86.zip + - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/ + - $HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output + - pipe: sonarsource/sonarqube-scan:1.0.0 + variables: + EXTRA_ARGS: -Dsonar.cfamily.build-wrapper-output=bw-output + SONAR_HOST_URL: \${SONAR_HOST_URL} + SONAR_TOKEN: \${SONAR_TOKEN}` + : '' +} +definitions: + caches: + sonar: ~/.sonar`; +} diff --git a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/DotNet.ts b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/DotNet.ts new file mode 100644 index 00000000000..ec1c82fdd11 --- /dev/null +++ b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/DotNet.ts @@ -0,0 +1,64 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +export default function dotNetExample(branchesEnabled: boolean, projectKey: string) { + return `image: mcr.microsoft.com/dotnet/core/sdk:latest + +pipelines: + branches: + '{master}': + - step: + name: SonarQube analysis + caches: + - dotnetcore + - sonar + script: + - apt-get update + - apt-get install --yes openjdk-11-jre + - dotnet tool install --global dotnet-sonarscanner + - export PATH="$PATH:/root/.dotnet/tools" + - dotnet sonarscanner begin /k:"${projectKey}" /d:"sonar.login=\${SONAR_TOKEN}" /d:"sonar.host.url=\${SONAR_HOST_URL}" + - dotnet build + - dotnet sonarscanner end /d:"sonar.login=\${SONAR_TOKEN}" + ${ + branchesEnabled + ? ` + pull-requests: + '**': + - step: + name: SonarQube analysis + caches: + - dotnetcore + - sonar + script: + - apt-get update + - apt-get install --yes openjdk-11-jre + - dotnet tool install --global dotnet-sonarscanner + - export PATH="$PATH:/root/.dotnet/tools" + - dotnet sonarscanner begin /k:"${projectKey}" /d:"sonar.login=\${SONAR_TOKEN}" /d:"sonar.host.url=\${SONAR_HOST_URL}" + - dotnet build + - dotnet sonarscanner end /d:"sonar.login=\${SONAR_TOKEN}" + ` + : '' + } +definitions: + caches: + sonar: ~/.sonar`; +} diff --git a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Gradle.ts b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Gradle.ts new file mode 100644 index 00000000000..78d5bc4c86b --- /dev/null +++ b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Gradle.ts @@ -0,0 +1,55 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +export default function gradleExample(branchesEnabled: boolean) { + return `image: openjdk:8 + +clone: + depth: full + +pipelines: + branches: + '{master}': + - step: + name: SonarQube analysis + caches: + - gradle + - sonar + script: + - bash ./gradlew sonarqube +${ + branchesEnabled + ? ` + pull-requests: + '**': + - step: + name: SonarQube analysis + caches: + - gradle + - sonar + script: + - bash ./gradlew sonarqube +` + : '' +} +definitions: + caches: + sonar: ~/.sonar`; +} diff --git a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Maven.ts b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Maven.ts new file mode 100644 index 00000000000..7cc04a84a06 --- /dev/null +++ b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Maven.ts @@ -0,0 +1,55 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +export default function mavenExample(branchesEnabled: boolean) { + return `image: maven:3.3.9 + +clone: + depth: full + +pipelines: + branches: + '{master}': + - step: + name: SonarQube analysis + caches: + - maven + - sonar + script: + - mvn verify sonar:sonar +${ + branchesEnabled + ? ` + pull-requests: + '**': + - step: + name: SonarQube analysis + caches: + - maven + - sonar + script: + - mvn verify sonar:sonar +` + : '' +} +definitions: + caches: + sonar: ~/.sonar`; +} diff --git a/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Others.ts b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Others.ts new file mode 100644 index 00000000000..b3e147b98d6 --- /dev/null +++ b/server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Others.ts @@ -0,0 +1,55 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +export default function othersExample(branchesEnabled: boolean) { + return `image: maven:3.3.9 + +clone: + depth: full + +pipelines: + branches: + '{master}': + - step: + name: SonarQube analysis + script: + - pipe: sonarsource/sonarqube-scan:1.0.0 + variables: + SONAR_HOST_URL: \${SONAR_HOST_URL} # Get the value from the repository/workspace variable. + SONAR_TOKEN: \${SONAR_TOKEN} # Get the value from the repository/workspace variable. You shouldn't set secret in clear text here. +${ + branchesEnabled + ? ` + pull-requests: + '**': + - step: + name: SonarQube analysis + script: + - pipe: sonarsource/sonarqube-scan:1.0.0 + variables: + SONAR_HOST_URL: \${SONAR_HOST_URL} # Get the value from the repository/workspace variable. + SONAR_TOKEN: \${SONAR_TOKEN} # Get the value from the repository/workspace variable. You shouldn't set secret in clear text here. +` + : '' +} +definitions: + caches: + sonar: ~/.sonar`; +} -- 2.39.5