Browse Source

SONAR-14353 GitlabCI tutorial for CE

tags/8.7.0.41497
Jeremy Davis 3 years ago
parent
commit
38069298aa
15 changed files with 212 additions and 235 deletions
  1. 10
    8
      server/sonar-web/src/main/js/components/tutorials/gitlabci/YmlFileStep.tsx
  2. 5
    2
      server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/YmlFileStep-test.tsx
  3. 1
    1
      server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/GitLabCITutorial-test.tsx.snap
  4. 12
    3
      server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/YmlFileStep-test.tsx.snap
  5. 34
    9
      server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/PipeCommand.tsx
  6. 0
    42
      server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/PipeCommandGradle.tsx
  7. 0
    43
      server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/PipeCommandMaven.tsx
  8. 13
    4
      server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommand-test.tsx
  9. 0
    26
      server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommandGradle-test.tsx
  10. 0
    26
      server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommandMaven-test.tsx
  11. 135
    0
      server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommand-test.tsx.snap
  12. 0
    22
      server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommandGradle-test.tsx.snap
  13. 0
    23
      server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommandMaven-test.tsx.snap
  14. 0
    25
      server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommandOther-test.tsx.snap
  15. 2
    1
      sonar-core/src/main/resources/org/sonar/l10n/core.properties

+ 10
- 8
server/sonar-web/src/main/js/components/tutorials/gitlabci/YmlFileStep.tsx View File

@@ -22,18 +22,18 @@ import { FormattedMessage } from 'react-intl';
import { Link } from 'react-router';
import { ClipboardIconButton } from 'sonar-ui-common/components/controls/clipboard';
import { translate } from 'sonar-ui-common/helpers/l10n';
import { withAppState } from '../../hoc/withAppState';
import Step from '../components/Step';
import PipeCommandGradle from './commands/PipeCommandGradle';
import PipeCommandMaven from './commands/PipeCommandMaven';
import PipeCommandOther from './commands/PipeCommandOther';
import PipeCommand from './commands/PipeCommand';
import { BuildTools } from './types';

export interface YmlFileStepProps {
appState: T.AppState;
buildTool?: BuildTools;
open: boolean;
}

export default function YmlFileStep({ buildTool, open }: YmlFileStepProps) {
export function YmlFileStep({ appState: { branchesEnabled }, buildTool, open }: YmlFileStepProps) {
const renderForm = () => (
<div className="boxed-group-inner">
<div className="flex-columns">
@@ -61,13 +61,13 @@ export default function YmlFileStep({ buildTool, open }: YmlFileStepProps) {
</div>

<div className="big-spacer-bottom">
{buildTool === BuildTools.Maven && <PipeCommandMaven />}
{buildTool === BuildTools.Gradle && <PipeCommandGradle />}
{buildTool === BuildTools.Other && <PipeCommandOther />}
<PipeCommand buildTool={buildTool} branchesEnabled={branchesEnabled} />
</div>

<p className="little-spacer-bottom">
{translate('onboarding.tutorial.with.gitlab_ci.yml.baseconfig')}
{branchesEnabled
? translate('onboarding.tutorial.with.gitlab_ci.yml.baseconfig')
: translate('onboarding.tutorial.with.gitlab_ci.yml.baseconfig.no_branches')}
</p>

<p className="huge-spacer-bottom">
@@ -134,3 +134,5 @@ export default function YmlFileStep({ buildTool, open }: YmlFileStepProps) {
/>
);
}

export default withAppState(YmlFileStep);

+ 5
- 2
server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/YmlFileStep-test.tsx View File

@@ -19,9 +19,10 @@
*/
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 YmlFileStep, { YmlFileStepProps } from '../YmlFileStep';
import { YmlFileStep, YmlFileStepProps } from '../YmlFileStep';

it('should render correctly', () => {
const wrapper = shallowRender();
@@ -37,5 +38,7 @@ it.each([[BuildTools.Maven], [BuildTools.Gradle], [BuildTools.Other]])(
);

function shallowRender(props: Partial<YmlFileStepProps> = {}) {
return shallow<YmlFileStepProps>(<YmlFileStep open={true} {...props} />);
return shallow<YmlFileStepProps>(
<YmlFileStep appState={mockAppState({ branchesEnabled: true })} open={true} {...props} />
);
}

+ 1
- 1
server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/GitLabCITutorial-test.tsx.snap View File

@@ -77,7 +77,7 @@ exports[`should render correctly 1`] = `
onOpen={[Function]}
open={false}
/>
<YmlFileStep
<Connect(withAppState(YmlFileStep))
open={false}
/>
</Fragment>

+ 12
- 3
server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/__snapshots__/YmlFileStep-test.tsx.snap View File

@@ -37,7 +37,10 @@ exports[`should render correctly for build tool gradle 1`] = `
<div
className="big-spacer-bottom"
>
<PipeCommandGradle />
<PipeCommand
branchesEnabled={true}
buildTool="gradle"
/>
</div>
<p
className="little-spacer-bottom"
@@ -145,7 +148,10 @@ exports[`should render correctly for build tool maven 1`] = `
<div
className="big-spacer-bottom"
>
<PipeCommandMaven />
<PipeCommand
branchesEnabled={true}
buildTool="maven"
/>
</div>
<p
className="little-spacer-bottom"
@@ -253,7 +259,10 @@ exports[`should render correctly for build tool other 1`] = `
<div
className="big-spacer-bottom"
>
<PipeCommandOther />
<PipeCommand
branchesEnabled={true}
buildTool="other"
/>
</div>
<p
className="little-spacer-bottom"

server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/PipeCommandOther.tsx → server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/PipeCommand.tsx View File

@@ -19,12 +19,40 @@
*/
import * as React from 'react';
import CodeSnippet from '../../../common/CodeSnippet';
import { BuildTools } from '../types';

export default function PipeCommandOther() {
const command = `sonarqube-check:
image:
export interface PipeCommandProps {
branchesEnabled?: boolean;
buildTool: BuildTools;
}

const BUILD_TOOL_SPECIFIC = {
[BuildTools.Gradle]: { image: 'gradle:jre11-slim', script: 'gradle sonarqube' },
[BuildTools.Maven]: {
image: 'maven:3.6.3-jdk-11',
script: `
- mvn verify sonar:sonar`
},
[BuildTools.Other]: {
image: `
name: sonarsource/sonar-scanner-cli:latest
entrypoint: [""]
entrypoint: [""]`,
script: `
- sonar-scanner`
}
};

export default function PipeCommand({ branchesEnabled, buildTool }: PipeCommandProps) {
const onlyBlock = branchesEnabled
? `- merge_requests
- master
- develop`
: '- master # or the name of your main branch';

const { image, script } = BUILD_TOOL_SPECIFIC[buildTool];

const command = `sonarqube-check:
image: ${image}
variables:
SONAR_USER_HOME: "\${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
@@ -32,13 +60,10 @@ export default function PipeCommandOther() {
key: "\${CI_JOB_NAME}"
paths:
- .sonar/cache
script:
- sonar-scanner
script: ${script}
allow_failure: true
only:
- merge_requests
- master
- develop
${onlyBlock}
`;

return <CodeSnippet snippet={command} />;

+ 0
- 42
server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/PipeCommandGradle.tsx View File

@@ -1,42 +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 * as React from 'react';
import CodeSnippet from '../../../common/CodeSnippet';

export default function PipeCommandGradle() {
const command = `sonarqube-check:
image: gradle:jre11-slim
variables:
SONAR_USER_HOME: "\${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: "\${CI_JOB_NAME}"
paths:
- .sonar/cache
script: gradle sonarqube
allow_failure: true
only:
- merge_requests
- master
- develop
`;

return <CodeSnippet snippet={command} />;
}

+ 0
- 43
server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/PipeCommandMaven.tsx View File

@@ -1,43 +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 * as React from 'react';
import CodeSnippet from '../../../common/CodeSnippet';

export default function PipeCommandMaven() {
const command = `sonarqube-check:
image: maven:3.6.3-jdk-11
variables:
SONAR_USER_HOME: "\${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: "\${CI_JOB_NAME}"
paths:
- .sonar/cache
script:
- mvn verify sonar:sonar
allow_failure: true
only:
- merge_requests
- master
- develop
`;

return <CodeSnippet snippet={command} />;
}

server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommandOther-test.tsx → server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommand-test.tsx View File

@@ -19,8 +19,17 @@
*/
import { shallow } from 'enzyme';
import * as React from 'react';
import PipeCommandOther from '../PipeCommandOther';
import { BuildTools } from '../../types';
import PipeCommand from '../PipeCommand';

it('should render correctly', () => {
expect(shallow(<PipeCommandOther />)).toMatchSnapshot();
});
it.each([[BuildTools.Gradle], [BuildTools.Maven], [BuildTools.Other]])(
'should render correctly for %s',
buildTool => {
expect(shallow(<PipeCommand buildTool={buildTool} branchesEnabled={true} />)).toMatchSnapshot(
'branches enabled'
);
expect(shallow(<PipeCommand buildTool={buildTool} branchesEnabled={true} />)).toMatchSnapshot(
'branches not enabled'
);
}
);

+ 0
- 26
server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommandGradle-test.tsx View File

@@ -1,26 +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 { shallow } from 'enzyme';
import * as React from 'react';
import PipeCommandGradle from '../PipeCommandGradle';

it('should render correctly', () => {
expect(shallow(<PipeCommandGradle />)).toMatchSnapshot();
});

+ 0
- 26
server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/PipeCommandMaven-test.tsx View File

@@ -1,26 +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 { shallow } from 'enzyme';
import * as React from 'react';
import PipeCommandMaven from '../PipeCommandMaven';

it('should render correctly', () => {
expect(shallow(<PipeCommandMaven />)).toMatchSnapshot();
});

+ 135
- 0
server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommand-test.tsx.snap View File

@@ -0,0 +1,135 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`should render correctly for gradle: branches enabled 1`] = `
<CodeSnippet
snippet="sonarqube-check:
image: gradle:jre11-slim
variables:
SONAR_USER_HOME: \\"\${CI_PROJECT_DIR}/.sonar\\" # Defines the location of the analysis task cache
GIT_DEPTH: \\"0\\" # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: \\"\${CI_JOB_NAME}\\"
paths:
- .sonar/cache
script: gradle sonarqube
allow_failure: true
only:
- merge_requests
- master
- develop
"
/>
`;

exports[`should render correctly for gradle: branches not enabled 1`] = `
<CodeSnippet
snippet="sonarqube-check:
image: gradle:jre11-slim
variables:
SONAR_USER_HOME: \\"\${CI_PROJECT_DIR}/.sonar\\" # Defines the location of the analysis task cache
GIT_DEPTH: \\"0\\" # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: \\"\${CI_JOB_NAME}\\"
paths:
- .sonar/cache
script: gradle sonarqube
allow_failure: true
only:
- merge_requests
- master
- develop
"
/>
`;

exports[`should render correctly for maven: branches enabled 1`] = `
<CodeSnippet
snippet="sonarqube-check:
image: maven:3.6.3-jdk-11
variables:
SONAR_USER_HOME: \\"\${CI_PROJECT_DIR}/.sonar\\" # Defines the location of the analysis task cache
GIT_DEPTH: \\"0\\" # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: \\"\${CI_JOB_NAME}\\"
paths:
- .sonar/cache
script:
- mvn verify sonar:sonar
allow_failure: true
only:
- merge_requests
- master
- develop
"
/>
`;

exports[`should render correctly for maven: branches not enabled 1`] = `
<CodeSnippet
snippet="sonarqube-check:
image: maven:3.6.3-jdk-11
variables:
SONAR_USER_HOME: \\"\${CI_PROJECT_DIR}/.sonar\\" # Defines the location of the analysis task cache
GIT_DEPTH: \\"0\\" # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: \\"\${CI_JOB_NAME}\\"
paths:
- .sonar/cache
script:
- mvn verify sonar:sonar
allow_failure: true
only:
- merge_requests
- master
- develop
"
/>
`;

exports[`should render correctly for other: branches enabled 1`] = `
<CodeSnippet
snippet="sonarqube-check:
image:
name: sonarsource/sonar-scanner-cli:latest
entrypoint: [\\"\\"]
variables:
SONAR_USER_HOME: \\"\${CI_PROJECT_DIR}/.sonar\\" # Defines the location of the analysis task cache
GIT_DEPTH: \\"0\\" # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: \\"\${CI_JOB_NAME}\\"
paths:
- .sonar/cache
script:
- sonar-scanner
allow_failure: true
only:
- merge_requests
- master
- develop
"
/>
`;

exports[`should render correctly for other: branches not enabled 1`] = `
<CodeSnippet
snippet="sonarqube-check:
image:
name: sonarsource/sonar-scanner-cli:latest
entrypoint: [\\"\\"]
variables:
SONAR_USER_HOME: \\"\${CI_PROJECT_DIR}/.sonar\\" # Defines the location of the analysis task cache
GIT_DEPTH: \\"0\\" # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: \\"\${CI_JOB_NAME}\\"
paths:
- .sonar/cache
script:
- sonar-scanner
allow_failure: true
only:
- merge_requests
- master
- develop
"
/>
`;

+ 0
- 22
server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommandGradle-test.tsx.snap View File

@@ -1,22 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`should render correctly 1`] = `
<CodeSnippet
snippet="sonarqube-check:
image: gradle:jre11-slim
variables:
SONAR_USER_HOME: \\"\${CI_PROJECT_DIR}/.sonar\\" # Defines the location of the analysis task cache
GIT_DEPTH: \\"0\\" # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: \\"\${CI_JOB_NAME}\\"
paths:
- .sonar/cache
script: gradle sonarqube
allow_failure: true
only:
- merge_requests
- master
- develop
"
/>
`;

+ 0
- 23
server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommandMaven-test.tsx.snap View File

@@ -1,23 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`should render correctly 1`] = `
<CodeSnippet
snippet="sonarqube-check:
image: maven:3.6.3-jdk-11
variables:
SONAR_USER_HOME: \\"\${CI_PROJECT_DIR}/.sonar\\" # Defines the location of the analysis task cache
GIT_DEPTH: \\"0\\" # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: \\"\${CI_JOB_NAME}\\"
paths:
- .sonar/cache
script:
- mvn verify sonar:sonar
allow_failure: true
only:
- merge_requests
- master
- develop
"
/>
`;

+ 0
- 25
server/sonar-web/src/main/js/components/tutorials/gitlabci/commands/__tests__/__snapshots__/PipeCommandOther-test.tsx.snap View File

@@ -1,25 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`should render correctly 1`] = `
<CodeSnippet
snippet="sonarqube-check:
image:
name: sonarsource/sonar-scanner-cli:latest
entrypoint: [\\"\\"]
variables:
SONAR_USER_HOME: \\"\${CI_PROJECT_DIR}/.sonar\\" # Defines the location of the analysis task cache
GIT_DEPTH: \\"0\\" # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: \\"\${CI_JOB_NAME}\\"
paths:
- .sonar/cache
script:
- sonar-scanner
allow_failure: true
only:
- merge_requests
- master
- develop
"
/>
`;

+ 2
- 1
sonar-core/src/main/resources/org/sonar/l10n/core.properties View File

@@ -3357,7 +3357,8 @@ onboarding.tutorial.with.gitlab_ci.env_variables.section2.step4=Leave the "Mask
onboarding.tutorial.with.gitlab_ci.yml.title=Create or update the configuration file
onboarding.tutorial.with.gitlab_ci.yml.description=Create or update your {filename} file with the following content.
onboarding.tutorial.with.gitlab_ci.yml.filename=.gitlab-ci.yml
onboarding.tutorial.with.gitlab_ci.yml.baseconfig=Note that this is a minimal base configuration to run a SonarQube analysis on your master branch and merge requests.
onboarding.tutorial.with.gitlab_ci.yml.baseconfig=Note that this is a minimal base configuration to run a SonarQube analysis on your main branch and merge requests.
onboarding.tutorial.with.gitlab_ci.yml.baseconfig.no_branches=Note that this is a minimal base configuration to run a SonarQube analysis on your main branch.
onboarding.tutorial.with.gitlab_ci.yml.existing=If you already have a pipeline configured and running, you might want to add the example from this step to your existing yml file.
onboarding.tutorial.with.gitlab_ci.yml.done=Is it done?
onboarding.tutorial.with.gitlab_ci.yml.done.description=You should see the page refresh itself in a few moments with your analysis results if the {link}.

Loading…
Cancel
Save