From: Mathieu Suen Date: Mon, 1 Mar 2021 09:26:21 +0000 (+0100) Subject: SONAR-14495 Add the .NET tutorial for gitlab CI X-Git-Tag: 8.8.0.42792~68 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cf5b5df5a0ae177ad1264e9c3b0c8c6935c51b94;p=sonarqube.git SONAR-14495 Add the .NET tutorial for gitlab CI --- 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 0d53961bb59..0afca163c58 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 @@ -26,7 +26,7 @@ import { } from '../../../types/alm-settings'; import EnvironmentVariablesStep from './EnvironmentVariablesStep'; import ProjectKeyStep from './ProjectKeyStep'; -import { BuildTools } from './types'; +import { GitlabBuildTools } from './types'; import YmlFileStep from './YmlFileStep'; export enum Steps { @@ -46,7 +46,7 @@ export default function GitLabCITutorial(props: GitLabCITutorialProps) { const { baseUrl, component, currentUser, projectBinding } = props; const [step, setStep] = React.useState(Steps.PROJECT_KEY); - const [buildTool, setBuildTool] = React.useState(); + const [buildTool, setBuildTool] = React.useState(); // Failsafe; should never happen. if (!isProjectGitLabBindingResponse(projectBinding)) { @@ -81,7 +81,7 @@ export default function GitLabCITutorial(props: GitLabCITutorialProps) { open={step === Steps.ENV_VARIABLES} /> - + ); } 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 b7fdef1d98a..fabcc7432a2 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 @@ -25,16 +25,17 @@ import { translate } from 'sonar-ui-common/helpers/l10n'; import CodeSnippet from '../../common/CodeSnippet'; import RenderOptions from '../components/RenderOptions'; import Step from '../components/Step'; -import { BuildTools } from './types'; +import { BuildTools } from '../types'; +import { GitlabBuildTools, GITLAB_BUILDTOOLS_LIST } from './types'; export interface ProjectKeyStepProps { - buildTool?: BuildTools; + buildTool?: GitlabBuildTools; component: T.Component; finished: boolean; onDone: () => void; onOpen: () => void; open: boolean; - setBuildTool: (tool: BuildTools) => void; + setBuildTool: (tool: GitlabBuildTools) => void; } const mavenSnippet = (key: string) => ` @@ -72,6 +73,13 @@ const filenameForBuildTool = { export default function ProjectKeyStep(props: ProjectKeyStepProps) { const { buildTool, component, finished, open } = props; + const buildToolSelect = (value: GitlabBuildTools) => { + props.setBuildTool(value); + if (value === BuildTools.DotNet) { + props.onDone(); + } + }; + const renderForm = () => (
    @@ -80,12 +88,12 @@ export default function ProjectKeyStep(props: ProjectKeyStepProps) { props.setBuildTool(value as BuildTools)} + onCheck={buildToolSelect} optionLabelKey="onboarding.build" - options={Object.values(BuildTools)} + options={GITLAB_BUILDTOOLS_LIST} /> - {buildTool !== undefined && ( + {buildTool !== undefined && buildTool !== BuildTools.DotNet && (
  1. (
    @@ -61,7 +67,11 @@ export function YmlFileStep({ appState: { branchesEnabled }, buildTool, open }:
    - +

    diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/ProjectKeyStep-test.tsx b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/ProjectKeyStep-test.tsx index a8328d9f2c7..5518d425202 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/ProjectKeyStep-test.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/ProjectKeyStep-test.tsx @@ -22,8 +22,9 @@ import * as React from 'react'; import { mockComponent } from '../../../../helpers/testMocks'; import RenderOptions from '../../components/RenderOptions'; import { renderStepContent } from '../../jenkins/test-utils'; +import { BuildTools } from '../../types'; import ProjectKeyStep, { ProjectKeyStepProps } from '../ProjectKeyStep'; -import { BuildTools } from '../types'; +import { GITLAB_BUILDTOOLS_LIST } from '../types'; it('should render correctly', () => { const wrapper = shallowRender(); @@ -31,7 +32,7 @@ it('should render correctly', () => { expect(renderStepContent(wrapper)).toMatchSnapshot('initial content'); }); -it.each([[BuildTools.Maven], [BuildTools.Gradle], [BuildTools.Other]])( +it.each(GITLAB_BUILDTOOLS_LIST.map(tool => [tool]))( 'should render correctly for build tool %s', buildTool => { expect(renderStepContent(shallowRender({ buildTool }))).toMatchSnapshot(); diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/YmlFileStep-test.tsx b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/YmlFileStep-test.tsx index 6d24ad7873e..db93a32aabf 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/YmlFileStep-test.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/YmlFileStep-test.tsx @@ -21,7 +21,7 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { mockAppState } from '../../../../helpers/testMocks'; import { renderStepContent } from '../../jenkins/test-utils'; -import { BuildTools } from '../types'; +import { GITLAB_BUILDTOOLS_LIST } from '../types'; import { YmlFileStep, YmlFileStepProps } from '../YmlFileStep'; it('should render correctly', () => { @@ -30,7 +30,7 @@ it('should render correctly', () => { expect(renderStepContent(wrapper)).toMatchSnapshot('initial content'); }); -it.each([[BuildTools.Maven], [BuildTools.Gradle], [BuildTools.Other]])( +it.each(GITLAB_BUILDTOOLS_LIST.map(tool => [tool]))( 'should render correctly for build tool %s', buildTool => { expect(renderStepContent(shallowRender({ buildTool }))).toMatchSnapshot(); @@ -39,6 +39,11 @@ it.each([[BuildTools.Maven], [BuildTools.Gradle], [BuildTools.Other]])( 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 e7e458b4f47..02b85fac394 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 @@ -80,6 +80,7 @@ exports[`should render correctly 1`] = ` /> `; diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/ProjectKeyStep-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/ProjectKeyStep-test.tsx.snap index b1e3b8e57c2..a291f1e798a 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/ProjectKeyStep-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/ProjectKeyStep-test.tsx.snap @@ -1,5 +1,38 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`should render correctly for build tool dotnet 1`] = ` +

    +
      +
    1. + onboarding.build + +
    2. +
    + +
    +`; + exports[`should render correctly for build tool gradle 1`] = `
    +
    +
    + +
    + + + onboarding.tutorial.with.gitlab_ci.yml.filename + + + , + } + } + /> +
    +
    + +
    +

    + 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.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 gradle 1`] = `

'gradle sonarqube' }, [BuildTools.Maven]: { image: 'maven:3.6.3-jdk-11', - script: ` + script: () => ` - mvn verify sonar:sonar` }, + [BuildTools.DotNet]: { + image: 'mcr.microsoft.com/dotnet/core/sdk:latest', + script: (projectKey: string) => ` + - "apt-get update" + - "apt-get install --yes openjdk-11-jre" + - "dotnet tool install --global dotnet-sonarscanner" + - "export PATH=\\"$PATH:$HOME/.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\\""` + }, [BuildTools.Other]: { image: ` name: sonarsource/sonar-scanner-cli:latest entrypoint: [""]`, - script: ` + script: () => ` - sonar-scanner` } }; -export default function PipeCommand({ branchesEnabled, buildTool }: PipeCommandProps) { +export default function PipeCommand({ projectKey, branchesEnabled, buildTool }: PipeCommandProps) { const onlyBlock = branchesEnabled ? `- merge_requests - master @@ -60,7 +73,7 @@ export default function PipeCommand({ branchesEnabled, buildTool }: PipeCommandP key: "\${CI_JOB_NAME}" paths: - .sonar/cache - script: ${script} + script: ${script(projectKey)} allow_failure: true only: ${onlyBlock} 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 8e2c9367182..abc594b60f5 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,17 +19,14 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; -import { BuildTools } from '../../types'; +import { GITLAB_BUILDTOOLS_LIST } from '../../types'; import PipeCommand from '../PipeCommand'; -it.each([[BuildTools.Gradle], [BuildTools.Maven], [BuildTools.Other]])( - 'should render correctly for %s', - buildTool => { - expect(shallow()).toMatchSnapshot( - 'branches enabled' - ); - expect(shallow()).toMatchSnapshot( - 'branches not enabled' - ); - } -); +it.each(GITLAB_BUILDTOOLS_LIST.map(tool => [tool]))('should render correctly for %s', buildTool => { + expect( + shallow() + ).toMatchSnapshot('branches enabled'); + expect( + shallow() + ).toMatchSnapshot('branches not 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 019eef78564..c7e7a6cbcc7 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,5 +1,61 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +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`] = `