From cc3cf41cae41403f763103c3a033b269e19ec3a8 Mon Sep 17 00:00:00 2001 From: Mathieu Suen Date: Wed, 16 Jun 2021 10:20:58 +0200 Subject: SONAR-15034 Adding C/C++/Objective C to gitlab tutorial. --- .../tutorials/gitlabci/GitLabCITutorial.tsx | 4 +- .../tutorials/gitlabci/ProjectKeyStep.tsx | 25 ++- .../components/tutorials/gitlabci/YmlFileStep.tsx | 6 +- .../gitlabci/__tests__/ProjectKeyStep-test.tsx | 24 ++- .../gitlabci/__tests__/YmlFileStep-test.tsx | 27 +-- .../__snapshots__/GitLabCITutorial-test.tsx.snap | 2 +- .../__snapshots__/ProjectKeyStep-test.tsx.snap | 94 +++++++++ .../__snapshots__/YmlFileStep-test.tsx.snap | 225 ++++++++++++++++++++- .../tutorials/gitlabci/commands/PipeCommand.tsx | 56 ++++- .../commands/__tests__/PipeCommand-test.tsx | 10 +- .../__snapshots__/PipeCommand-test.tsx.snap | 148 +++++++++++--- .../main/js/components/tutorials/gitlabci/types.ts | 34 ---- 12 files changed, 545 insertions(+), 110 deletions(-) delete mode 100644 server/sonar-web/src/main/js/components/tutorials/gitlabci/types.ts (limited to 'server/sonar-web/src/main/js') diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/GitLabCITutorial.tsx b/server/sonar-web/src/main/js/components/tutorials/gitlabci/GitLabCITutorial.tsx index 51c73e06110..6d2f7bc6d5a 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/GitLabCITutorial.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/GitLabCITutorial.tsx @@ -19,9 +19,9 @@ */ import * as React from 'react'; import { translate } from 'sonar-ui-common/helpers/l10n'; +import { BuildTools } from '../types'; import EnvironmentVariablesStep from './EnvironmentVariablesStep'; import ProjectKeyStep from './ProjectKeyStep'; -import { GitlabBuildTools } from './types'; import YmlFileStep from './YmlFileStep'; export enum Steps { @@ -40,7 +40,7 @@ export default function GitLabCITutorial(props: GitLabCITutorialProps) { const { baseUrl, component, currentUser } = props; const [step, setStep] = React.useState(Steps.PROJECT_KEY); - const [buildTool, setBuildTool] = React.useState(); + const [buildTool, setBuildTool] = React.useState(); return ( <> diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/ProjectKeyStep.tsx b/server/sonar-web/src/main/js/components/tutorials/gitlabci/ProjectKeyStep.tsx index 14614072352..d4f03a0480e 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/ProjectKeyStep.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/ProjectKeyStep.tsx @@ -23,19 +23,20 @@ import { Button } from 'sonar-ui-common/components/controls/buttons'; import { ClipboardIconButton } from 'sonar-ui-common/components/controls/clipboard'; import { translate } from 'sonar-ui-common/helpers/l10n'; import CodeSnippet from '../../common/CodeSnippet'; +import { withCLanguageFeature } from '../../hoc/withCLanguageFeature'; import RenderOptions from '../components/RenderOptions'; import Step from '../components/Step'; import { BuildTools } from '../types'; -import { GitlabBuildTools, GITLAB_BUILDTOOLS_LIST } from './types'; export interface ProjectKeyStepProps { - buildTool?: GitlabBuildTools; + buildTool?: BuildTools; component: T.Component; finished: boolean; + hasCLanguageFeature: boolean; onDone: () => void; onOpen: () => void; open: boolean; - setBuildTool: (tool: GitlabBuildTools) => void; + setBuildTool: (tool: BuildTools) => void; } const mavenSnippet = (key: string) => ` @@ -61,25 +62,33 @@ sonar.qualitygate.wait=true const snippetForBuildTool = { [BuildTools.Maven]: mavenSnippet, [BuildTools.Gradle]: gradleSnippet, + [BuildTools.CFamily]: otherSnippet, [BuildTools.Other]: otherSnippet }; const filenameForBuildTool = { [BuildTools.Maven]: 'pom.xml', [BuildTools.Gradle]: 'build.gradle', + [BuildTools.CFamily]: 'sonar-project.properties', [BuildTools.Other]: 'sonar-project.properties' }; -export default function ProjectKeyStep(props: ProjectKeyStepProps) { - const { buildTool, component, finished, open } = props; +export function ProjectKeyStep(props: ProjectKeyStepProps) { + const { buildTool, component, finished, hasCLanguageFeature, open } = props; - const buildToolSelect = (value: GitlabBuildTools) => { + const buildToolSelect = (value: BuildTools) => { props.setBuildTool(value); if (value === BuildTools.DotNet) { props.onDone(); } }; + const buildTools = [BuildTools.Maven, BuildTools.Gradle, BuildTools.DotNet]; + if (hasCLanguageFeature) { + buildTools.push(BuildTools.CFamily); + } + buildTools.push(BuildTools.Other); + const renderForm = () => (
    @@ -90,7 +99,7 @@ export default function ProjectKeyStep(props: ProjectKeyStepProps) { name="buildtool" onCheck={buildToolSelect} optionLabelKey="onboarding.build" - options={GITLAB_BUILDTOOLS_LIST} + options={buildTools} /> {buildTool !== undefined && buildTool !== BuildTools.DotNet && ( @@ -131,3 +140,5 @@ export default function ProjectKeyStep(props: ProjectKeyStepProps) { /> ); } + +export default withCLanguageFeature(ProjectKeyStep); diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/YmlFileStep.tsx b/server/sonar-web/src/main/js/components/tutorials/gitlabci/YmlFileStep.tsx index 516e1aea31e..bb5b9bbbbb3 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/YmlFileStep.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/YmlFileStep.tsx @@ -24,12 +24,12 @@ import { ClipboardIconButton } from 'sonar-ui-common/components/controls/clipboa import { translate } from 'sonar-ui-common/helpers/l10n'; import { withAppState } from '../../hoc/withAppState'; import Step from '../components/Step'; +import { BuildTools } from '../types'; import PipeCommand from './commands/PipeCommand'; -import { GitlabBuildTools } from './types'; export interface YmlFileStepProps { appState: T.AppState; - buildTool?: GitlabBuildTools; + buildTool?: BuildTools; open: boolean; projectKey: string; } @@ -66,7 +66,7 @@ export function YmlFileStep({ />
-
+
{ const wrapper = shallowRender(); @@ -32,12 +31,20 @@ it('should render correctly', () => { expect(renderStepContent(wrapper)).toMatchSnapshot('initial content'); }); -it.each(GITLAB_BUILDTOOLS_LIST.map(tool => [tool]))( - 'should render correctly for build tool %s', - buildTool => { - expect(renderStepContent(shallowRender({ buildTool }))).toMatchSnapshot(); - } -); +it('should render correctly if C is not available', () => { + const wrapper = shallowRender({ hasCLanguageFeature: false }); + expect(renderStepContent(wrapper)).toMatchSnapshot(); +}); + +it.each([ + [BuildTools.Maven], + [BuildTools.Gradle], + [BuildTools.DotNet], + [BuildTools.CFamily], + [BuildTools.Other] +])('should render correctly for build tool %s', buildTool => { + expect(renderStepContent(shallowRender({ buildTool }))).toMatchSnapshot(); +}); it('should correctly callback with selected build tool', () => { const setBuildTool = jest.fn(); @@ -60,6 +67,7 @@ function shallowRender(props: Partial = {}) { { @@ -30,17 +30,20 @@ it('should render correctly', () => { expect(renderStepContent(wrapper)).toMatchSnapshot('initial content'); }); -it.each(GITLAB_BUILDTOOLS_LIST.map(tool => [tool]))( - 'should render correctly for build tool %s', - buildTool => { - expect(renderStepContent(shallowRender({ buildTool }))).toMatchSnapshot('with branch support'); - expect( - renderStepContent( - shallowRender({ appState: mockAppState({ branchesEnabled: false }), buildTool }) - ) - ).toMatchSnapshot('without branch support'); - } -); +it.each([ + [BuildTools.Maven], + [BuildTools.Gradle], + [BuildTools.DotNet], + [BuildTools.CFamily], + [BuildTools.Other] +])('should render correctly for build tool %s', buildTool => { + expect(renderStepContent(shallowRender({ buildTool }))).toMatchSnapshot('with branch support'); + expect( + renderStepContent( + shallowRender({ appState: mockAppState({ branchesEnabled: false }), buildTool }) + ) + ).toMatchSnapshot('without branch support'); +}); function shallowRender(props: Partial = {}) { return shallow( diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/GitLabCITutorial-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/GitLabCITutorial-test.tsx.snap index ef558b20a49..773eecd354a 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/GitLabCITutorial-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/GitLabCITutorial-test.tsx.snap @@ -11,7 +11,7 @@ exports[`should render correctly 1`] = ` onboarding.tutorial.with.gitlab_ci.title
- +
    +
  1. + onboarding.build + +
  2. +
  3. + + + sonar-project.properties + + + , + } + } + /> + +
  4. +
+ +
+`; + exports[`should render correctly for build tool dotnet 1`] = `
`; +exports[`should render correctly if C is not available 1`] = ` +
+
    +
  1. + onboarding.build + +
  2. +
+
+`; + exports[`should render correctly: Step wrapper 1`] = ` @@ -34,8 +34,217 @@ exports[`should render correctly for build tool dotnet: with branch support 1`] } />
+
+ +
+

+ onboarding.tutorial.with.gitlab_ci.yml.baseconfig +

+

+ onboarding.tutorial.with.gitlab_ci.yml.existing +

+
+
+

+ + onboarding.tutorial.with.gitlab_ci.yml.done + + + onboarding.tutorial.with.gitlab_ci.yml.done.description + + onboarding.tutorial.with.gitlab_ci.yml.done.mr_deco_automatic +

+

+ + onboarding.tutorial.with.gitlab_ci.yml.done.then-what + + + onboarding.tutorial.with.gitlab_ci.yml.done.then-what.description +

+

+ + onboarding.tutorial.with.gitlab_ci.yml.done.links.QG + , + } + } + /> +

+
+ + + + +`; + +exports[`should render correctly for build tool cfamily: without branch support 1`] = ` +
+
+
+
+ + + onboarding.tutorial.with.gitlab_ci.yml.filename + + + , + } + } + /> +
+
+ +
+

+ onboarding.tutorial.with.gitlab_ci.yml.baseconfig.no_branches +

+

+ onboarding.tutorial.with.gitlab_ci.yml.existing +

+
+
+

+ + onboarding.tutorial.with.gitlab_ci.yml.done + + + onboarding.tutorial.with.gitlab_ci.yml.done.description + +

+

+ + onboarding.tutorial.with.gitlab_ci.yml.done.then-what + + + onboarding.tutorial.with.gitlab_ci.yml.done.then-what.description +

+

+ + onboarding.tutorial.with.gitlab_ci.yml.done.links.QG + , + } + } + /> +

+
+
+
+
+
+`; + +exports[`should render correctly for build tool dotnet: with branch support 1`] = ` +
+
+
+ +
+ + + onboarding.tutorial.with.gitlab_ci.yml.filename + + + , + } + } + /> +
+
+ +cache: + paths: + - .sonar + +stages: + - download + - build + - scan + +download: + stage: download + script: + - mkdir -p .sonar + - curl -sSLo build-wrapper-linux-x86.zip $SONAR_HOST_URL/static/cpp/build-wrapper-linux-x86.zip + - unzip -o build-wrapper-linux-x86.zip -d .sonar + +build: + stage: build + script: + - .sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir .sonar/bw-output + +sonarqube-check: + stage: scan + script: + - curl -sSLo sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472-linux.zip + - unzip -o sonar-scanner.zip -d .sonar + - .sonar/sonar-scanner-4.6.2.2472-linux/bin/sonar-scanner -Dsonar.cfamily.build-wrapper-output=.sonar/bw-output + allow_failure: true`; + } else { + const onlyBlock = branchesEnabled + ? `- merge_requests - master - develop` - : '- master # or the name of your main branch'; + : '- master # or the name of your main branch'; - const { image, script } = BUILD_TOOL_SPECIFIC[buildTool]; + const { image, script } = BUILD_TOOL_SPECIFIC[buildTool]; - const command = `sonarqube-check: + command = `sonarqube-check: image: ${image} variables: SONAR_USER_HOME: "\${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache @@ -78,6 +111,11 @@ export default function PipeCommand({ projectKey, branchesEnabled, buildTool }: only: ${onlyBlock} `; - - return ; + } + return ( + <> + + + + ); } diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommand-test.tsx b/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommand-test.tsx index abc594b60f5..7254d3f6851 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommand-test.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommand-test.tsx @@ -19,10 +19,16 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; -import { GITLAB_BUILDTOOLS_LIST } from '../../types'; +import { BuildTools } from '../../../types'; import PipeCommand from '../PipeCommand'; -it.each(GITLAB_BUILDTOOLS_LIST.map(tool => [tool]))('should render correctly for %s', buildTool => { +it.each([ + [BuildTools.Maven], + [BuildTools.Gradle], + [BuildTools.DotNet], + [BuildTools.CFamily], + [BuildTools.Other] +])('should render correctly for %s', buildTool => { expect( shallow() ).toMatchSnapshot('branches enabled'); diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommand-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommand-test.tsx.snap index c7e7a6cbcc7..674361c114c 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommand-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommand-test.tsx.snap @@ -1,8 +1,85 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`should render correctly for cfamily: branches enabled 1`] = ` + + + + +`; + +exports[`should render correctly for cfamily: branches not enabled 1`] = ` + + + + +`; + exports[`should render correctly for dotnet: branches enabled 1`] = ` - + /> + + `; exports[`should render correctly for dotnet: branches not enabled 1`] = ` - + /> + + `; exports[`should render correctly for gradle: branches enabled 1`] = ` - + /> + + `; exports[`should render correctly for gradle: branches not enabled 1`] = ` - + /> + + `; exports[`should render correctly for maven: branches enabled 1`] = ` - + /> + + `; exports[`should render correctly for maven: branches not enabled 1`] = ` - + /> + + `; exports[`should render correctly for other: branches enabled 1`] = ` - + /> + + `; exports[`should render correctly for other: branches not enabled 1`] = ` - + /> + + `; diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/types.ts b/server/sonar-web/src/main/js/components/tutorials/gitlabci/types.ts deleted file mode 100644 index 5f67d6386b5..00000000000 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/types.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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. - */ - -import { BuildTools } from '../types'; - -export type GitlabBuildTools = - | BuildTools.Maven - | BuildTools.Gradle - | BuildTools.DotNet - | BuildTools.Other; - -export const GITLAB_BUILDTOOLS_LIST: GitlabBuildTools[] = [ - BuildTools.Maven, - BuildTools.Gradle, - BuildTools.DotNet, - BuildTools.Other -]; -- cgit v1.2.3