`;
exports[`should render correctly: yaml file step content 1`] = `
-<YamlFileStep
+<Connect(withCLanguageFeature(YamlFileStep))
alm="bitbucketcloud"
>
[Function]
-</YamlFileStep>
+</Connect(withCLanguageFeature(YamlFileStep))>
`;
import * as React from 'react';
import { translate } from 'sonar-ui-common/helpers/l10n';
import { AlmKeys } from '../../../types/alm-settings';
+import { withCLanguageFeature } from '../../hoc/withCLanguageFeature';
import RenderOptions from '../components/RenderOptions';
import { BuildTools } from '../types';
import AllSet from './AllSet';
export interface YamlFileStepProps {
alm: AlmKeys;
children?: (buildTool?: BuildTools) => React.ReactElement<{}>;
+ hasCLanguageFeature: boolean;
}
export interface AnalysisCommandProps {
component: T.Component;
}
-export default function YamlFileStep(props: YamlFileStepProps) {
- const { alm, children } = props;
- const buildTools = [BuildTools.Maven, BuildTools.Gradle, BuildTools.DotNet, BuildTools.Other];
+export function YamlFileStep(props: YamlFileStepProps) {
+ const { alm, children, hasCLanguageFeature } = props;
+
+ const buildTools = [BuildTools.Maven, BuildTools.Gradle, BuildTools.DotNet];
+ if (hasCLanguageFeature) {
+ buildTools.push(BuildTools.CFamily);
+ }
+ buildTools.push(BuildTools.Other);
+
const [buildToolSelected, setBuildToolSelected] = React.useState<BuildTools>();
return (
</>
);
}
+
+export default withCLanguageFeature(YamlFileStep);
import { shallow } from 'enzyme';
import * as React from 'react';
import { AlmKeys } from '../../../../types/alm-settings';
-import YamlFileStep, { YamlFileStepProps } from '../YamlFileStep';
+import { YamlFileStep, YamlFileStepProps } from '../YamlFileStep';
it('should render correctly', () => {
- expect(shallowRender()).toMatchSnapshot();
+ expect(shallowRender()).toMatchSnapshot('C unavailable');
+ expect(shallowRender({ hasCLanguageFeature: true })).toMatchSnapshot('C available');
});
function shallowRender(props: Partial<YamlFileStepProps> = {}) {
- return shallow<YamlFileStepProps>(<YamlFileStep alm={AlmKeys.GitHub} {...props} />);
+ return shallow<YamlFileStepProps>(
+ <YamlFileStep alm={AlmKeys.GitHub} hasCLanguageFeature={false} {...props} />
+ );
}
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`should render correctly 1`] = `
+exports[`should render correctly: C available 1`] = `
+<Fragment>
+ <ol
+ className="list-styled big-spacer-top big-spacer-bottom"
+ >
+ <li>
+ onboarding.build
+ <RenderOptions
+ name="language"
+ onCheck={[Function]}
+ optionLabelKey="onboarding.build"
+ options={
+ Array [
+ "maven",
+ "gradle",
+ "dotnet",
+ "cfamily",
+ "other",
+ ]
+ }
+ />
+ </li>
+ </ol>
+</Fragment>
+`;
+
+exports[`should render correctly: C unavailable 1`] = `
<Fragment>
<ol
className="list-styled big-spacer-top big-spacer-bottom"
import * as React from 'react';
import { withAppState } from '../../hoc/withAppState';
import { BuildTools } from '../types';
+import CFamily from './commands/CFamily';
import DotNet from './commands/DotNet';
import Gradle from './commands/Gradle';
import JavaMaven from './commands/JavaMaven';
return <Gradle branchesEnabled={branchesEnabled} component={component} />;
case BuildTools.DotNet:
return <DotNet branchesEnabled={branchesEnabled} component={component} />;
+ case BuildTools.CFamily:
+ return <CFamily branchesEnabled={branchesEnabled} component={component} />;
case BuildTools.Other:
return <Others branchesEnabled={branchesEnabled} component={component} />;
}
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`should render correctly for "cfamily" 1`] = `""`;
+exports[`should render correctly for "cfamily" 1`] = `
+<CFamily
+ component={
+ Object {
+ "breadcrumbs": Array [],
+ "key": "my-project",
+ "name": "MyProject",
+ "qualifier": "TRK",
+ "qualityGate": Object {
+ "isDefault": true,
+ "key": "30",
+ "name": "Sonar way",
+ },
+ "qualityProfiles": Array [
+ Object {
+ "deleted": false,
+ "key": "my-qp",
+ "language": "ts",
+ "name": "Sonar way",
+ },
+ ],
+ "tags": Array [],
+ }
+ }
+/>
+`;
exports[`should render correctly for "dotnet" 1`] = `
<DotNet
`;
exports[`should render correctly: yaml file step content 1`] = `
-<YamlFileStep
+<Connect(withCLanguageFeature(YamlFileStep))
alm="github"
>
[Function]
-</YamlFileStep>
+</Connect(withCLanguageFeature(YamlFileStep))>
`;
--- /dev/null
+/*
+ * 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 { translate } from 'sonar-ui-common/helpers/l10n';
+import { CompilationInfo } from '../../components/CompilationInfo';
+import CreateYmlFile from '../../components/CreateYmlFile';
+import DefaultProjectKey from '../../components/DefaultProjectKey';
+import RenderOptions from '../../components/RenderOptions';
+import { OSs } from '../../types';
+
+export interface CFamilyProps {
+ branchesEnabled?: boolean;
+ component: T.Component;
+}
+
+const STEPS = {
+ [OSs.Linux]: `steps:
+ - name: Checkout code
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+
+ - name: Download and install the build wrapper, build the project
+ run: |
+ mkdir $HOME/.sonar
+ curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip \${{ secrets.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 <your clean build command>
+ env:
+ SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }}
+
+ - name: SonarQube analysis
+ uses: SonarSource/sonarqube-scan-action@v1.0.0
+ with:
+ args: -Dsonar.cfamily.build-wrapper-output=bw-output
+ env:
+ SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}
+ SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }}`,
+ [OSs.MacOS]: `steps:
+ - name: Checkout code
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+
+ - name: Download and install the build wrapper
+ run: |
+ mkdir $HOME/.sonar
+ curl -sSLo $HOME/.sonar/build-wrapper-macosx-x86.zip \${{ secrets.SONAR_HOST_URL }}/static/cpp/build-wrapper-macosx-x86.zip
+ unzip -o $HOME/.sonar/build-wrapper-macosx-x86.zip -d $HOME/.sonar/
+ env:
+ SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }}
+
+ - name: Download and install the SonarScanner
+ run: |
+ curl -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472-macosx.zip
+ unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
+
+ - name: Build and analyse the project
+ run: |
+ # Potential improvement : add these paths to the PATH env var.
+ $HOME/.sonar/build-wrapper-macosx-x86/build-wrapper-macosx-x86 --out-dir bw-output <your clean build command>
+ $HOME/.sonar/sonar-scanner-4.6.2.2472-macosx/bin/sonar-scanner -Dsonar.cfamily.build-wrapper-output=bw-output
+ env:
+ SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}
+ SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }}`,
+ [OSs.Windows]: `steps:
+ - name: Checkout code
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+
+ - name: Download and install the build wrapper
+ shell: powershell
+ run: |
+ $path = "$HOME/.sonar/build-wrapper-win-x86.zip"
+ mkdir $HOME/.sonar
+ [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
+ (New-Object System.Net.WebClient).DownloadFile("\${{ secrets.SONAR_HOST_URL }}/static/cpp/build-wrapper-win-x86.zip", $path)
+ Add-Type -AssemblyName System.IO.Compression.FileSystem
+ [System.IO.Compression.ZipFile]::ExtractToDirectory($path, "$HOME/.sonar")
+ env:
+ SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }}
+
+ - name: Download and install the SonarScanner
+ shell: powershell
+ run: |
+ $path = "$HOME/.sonar/sonar-scanner-cli-4.6.2.2472-windows.zip"
+ [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
+ (New-Object System.Net.WebClient).DownloadFile("https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472-windows.zip", $path)
+ Add-Type -AssemblyName System.IO.Compression.FileSystem
+ [System.IO.Compression.ZipFile]::ExtractToDirectory($path, "$HOME/.sonar")
+
+ - name: Build and analyse the project
+ shell: powershell
+ run: |
+ $env:Path += ";$HOME/.sonar/build-wrapper-win-x86;$HOME/.sonar/sonar-scanner-4.6.2.2472-windows/bin"
+ build-wrapper-win-x86-64 --out-dir bw-output <your clean build command>
+ sonar-scanner.bat "-Dsonar.cfamily.build-wrapper-output=bw-output"
+ env:
+ SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}
+ SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }}`
+};
+
+const cfamilyYamlTemplate = (branchesEnabled: boolean, os: OSs) => `name: Build
+on:
+ push:
+ branches:
+ - master
+${branchesEnabled ? ' pull_request:\n types: [opened, synchronize, reopened]' : ''}
+
+jobs:
+ build:
+ runs-on: <image ready for your build toolchain>
+ ${STEPS[os]}
+`;
+
+export default function CFamily(props: CFamilyProps) {
+ const { component, branchesEnabled } = props;
+ const [os, setOs] = React.useState<undefined | OSs>();
+
+ return (
+ <>
+ <DefaultProjectKey component={component} />
+ <li>
+ <span>{translate('onboarding.build.other.os')}</span>
+ <RenderOptions
+ checked={os}
+ name="os"
+ onCheck={(value: OSs) => setOs(value)}
+ optionLabelKey="onboarding.build.other.os"
+ options={Object.values(OSs)}
+ />
+ </li>
+ {os && (
+ <>
+ <CreateYmlFile
+ yamlFileName=".github/workflows/build.yml"
+ yamlTemplate={cfamilyYamlTemplate(!!branchesEnabled, os)}
+ />
+ <CompilationInfo className="abs-width-800" />
+ </>
+ )}
+ </>
+ );
+}
--- /dev/null
+/*
+ * 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 { mockComponent } from '../../../../../helpers/testMocks';
+import RenderOptions from '../../../components/RenderOptions';
+import { OSs } from '../../../types';
+import CFamily, { CFamilyProps } from '../CFamily';
+
+it('should render correctly', () => {
+ expect(shallowRender()).toMatchSnapshot();
+});
+
+it.each([
+ [OSs.Linux, false],
+ [OSs.MacOS, true],
+ [OSs.Windows, true]
+])('should render correctly for %s', (os: OSs, branchesEnabled: boolean) => {
+ const wrapper = shallowRender({ branchesEnabled });
+ wrapper
+ .find(RenderOptions)
+ .props()
+ .onCheck(os);
+ expect(wrapper).toMatchSnapshot(`branches ${branchesEnabled ? 'enabled' : 'disabled'}`);
+});
+
+function shallowRender(props: Partial<CFamilyProps> = {}) {
+ return shallow<CFamilyProps>(
+ <CFamily branchesEnabled={true} component={mockComponent()} {...props} />
+ );
+}
--- /dev/null
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render correctly 1`] = `
+<Fragment>
+ <DefaultProjectKey
+ component={
+ Object {
+ "breadcrumbs": Array [],
+ "key": "my-project",
+ "name": "MyProject",
+ "qualifier": "TRK",
+ "qualityGate": Object {
+ "isDefault": true,
+ "key": "30",
+ "name": "Sonar way",
+ },
+ "qualityProfiles": Array [
+ Object {
+ "deleted": false,
+ "key": "my-qp",
+ "language": "ts",
+ "name": "Sonar way",
+ },
+ ],
+ "tags": Array [],
+ }
+ }
+ />
+ <li>
+ <span>
+ onboarding.build.other.os
+ </span>
+ <RenderOptions
+ name="os"
+ onCheck={[Function]}
+ optionLabelKey="onboarding.build.other.os"
+ options={
+ Array [
+ "linux",
+ "win",
+ "mac",
+ ]
+ }
+ />
+ </li>
+</Fragment>
+`;
+
+exports[`should render correctly for linux: branches disabled 1`] = `
+<Fragment>
+ <DefaultProjectKey
+ component={
+ Object {
+ "breadcrumbs": Array [],
+ "key": "my-project",
+ "name": "MyProject",
+ "qualifier": "TRK",
+ "qualityGate": Object {
+ "isDefault": true,
+ "key": "30",
+ "name": "Sonar way",
+ },
+ "qualityProfiles": Array [
+ Object {
+ "deleted": false,
+ "key": "my-qp",
+ "language": "ts",
+ "name": "Sonar way",
+ },
+ ],
+ "tags": Array [],
+ }
+ }
+ />
+ <li>
+ <span>
+ onboarding.build.other.os
+ </span>
+ <RenderOptions
+ checked="linux"
+ name="os"
+ onCheck={[Function]}
+ optionLabelKey="onboarding.build.other.os"
+ options={
+ Array [
+ "linux",
+ "win",
+ "mac",
+ ]
+ }
+ />
+ </li>
+ <CreateYmlFile
+ yamlFileName=".github/workflows/build.yml"
+ yamlTemplate="name: Build
+on:
+ push:
+ branches:
+ - master
+
+
+jobs:
+ build:
+ runs-on: <image ready for your build toolchain>
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+
+ - name: Download and install the build wrapper, build the project
+ run: |
+ mkdir $HOME/.sonar
+ curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip \${{ secrets.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 <your clean build command>
+ env:
+ SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }}
+
+ - name: SonarQube analysis
+ uses: SonarSource/sonarqube-scan-action@v1.0.0
+ with:
+ args: -Dsonar.cfamily.build-wrapper-output=bw-output
+ env:
+ SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}
+ SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }}
+"
+ />
+ <CompilationInfo
+ className="abs-width-800"
+ />
+</Fragment>
+`;
+
+exports[`should render correctly for mac: branches enabled 1`] = `
+<Fragment>
+ <DefaultProjectKey
+ component={
+ Object {
+ "breadcrumbs": Array [],
+ "key": "my-project",
+ "name": "MyProject",
+ "qualifier": "TRK",
+ "qualityGate": Object {
+ "isDefault": true,
+ "key": "30",
+ "name": "Sonar way",
+ },
+ "qualityProfiles": Array [
+ Object {
+ "deleted": false,
+ "key": "my-qp",
+ "language": "ts",
+ "name": "Sonar way",
+ },
+ ],
+ "tags": Array [],
+ }
+ }
+ />
+ <li>
+ <span>
+ onboarding.build.other.os
+ </span>
+ <RenderOptions
+ checked="mac"
+ name="os"
+ onCheck={[Function]}
+ optionLabelKey="onboarding.build.other.os"
+ options={
+ Array [
+ "linux",
+ "win",
+ "mac",
+ ]
+ }
+ />
+ </li>
+ <CreateYmlFile
+ yamlFileName=".github/workflows/build.yml"
+ yamlTemplate="name: Build
+on:
+ push:
+ branches:
+ - master
+ pull_request:
+ types: [opened, synchronize, reopened]
+
+jobs:
+ build:
+ runs-on: <image ready for your build toolchain>
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+
+ - name: Download and install the build wrapper
+ run: |
+ mkdir $HOME/.sonar
+ curl -sSLo $HOME/.sonar/build-wrapper-macosx-x86.zip \${{ secrets.SONAR_HOST_URL }}/static/cpp/build-wrapper-macosx-x86.zip
+ unzip -o $HOME/.sonar/build-wrapper-macosx-x86.zip -d $HOME/.sonar/
+ env:
+ SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }}
+
+ - name: Download and install the SonarScanner
+ run: |
+ curl -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472-macosx.zip
+ unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
+
+ - name: Build and analyse the project
+ run: |
+ # Potential improvement : add these paths to the PATH env var.
+ $HOME/.sonar/build-wrapper-macosx-x86/build-wrapper-macosx-x86 --out-dir bw-output <your clean build command>
+ $HOME/.sonar/sonar-scanner-4.6.2.2472-macosx/bin/sonar-scanner -Dsonar.cfamily.build-wrapper-output=bw-output
+ env:
+ SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}
+ SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }}
+"
+ />
+ <CompilationInfo
+ className="abs-width-800"
+ />
+</Fragment>
+`;
+
+exports[`should render correctly for win: branches enabled 1`] = `
+<Fragment>
+ <DefaultProjectKey
+ component={
+ Object {
+ "breadcrumbs": Array [],
+ "key": "my-project",
+ "name": "MyProject",
+ "qualifier": "TRK",
+ "qualityGate": Object {
+ "isDefault": true,
+ "key": "30",
+ "name": "Sonar way",
+ },
+ "qualityProfiles": Array [
+ Object {
+ "deleted": false,
+ "key": "my-qp",
+ "language": "ts",
+ "name": "Sonar way",
+ },
+ ],
+ "tags": Array [],
+ }
+ }
+ />
+ <li>
+ <span>
+ onboarding.build.other.os
+ </span>
+ <RenderOptions
+ checked="win"
+ name="os"
+ onCheck={[Function]}
+ optionLabelKey="onboarding.build.other.os"
+ options={
+ Array [
+ "linux",
+ "win",
+ "mac",
+ ]
+ }
+ />
+ </li>
+ <CreateYmlFile
+ yamlFileName=".github/workflows/build.yml"
+ yamlTemplate="name: Build
+on:
+ push:
+ branches:
+ - master
+ pull_request:
+ types: [opened, synchronize, reopened]
+
+jobs:
+ build:
+ runs-on: <image ready for your build toolchain>
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+
+ - name: Download and install the build wrapper
+ shell: powershell
+ run: |
+ $path = \\"$HOME/.sonar/build-wrapper-win-x86.zip\\"
+ mkdir $HOME/.sonar
+ [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
+ (New-Object System.Net.WebClient).DownloadFile(\\"\${{ secrets.SONAR_HOST_URL }}/static/cpp/build-wrapper-win-x86.zip\\", $path)
+ Add-Type -AssemblyName System.IO.Compression.FileSystem
+ [System.IO.Compression.ZipFile]::ExtractToDirectory($path, \\"$HOME/.sonar\\")
+ env:
+ SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }}
+
+ - name: Download and install the SonarScanner
+ shell: powershell
+ run: |
+ $path = \\"$HOME/.sonar/sonar-scanner-cli-4.6.2.2472-windows.zip\\"
+ [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
+ (New-Object System.Net.WebClient).DownloadFile(\\"https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472-windows.zip\\", $path)
+ Add-Type -AssemblyName System.IO.Compression.FileSystem
+ [System.IO.Compression.ZipFile]::ExtractToDirectory($path, \\"$HOME/.sonar\\")
+
+ - name: Build and analyse the project
+ shell: powershell
+ run: |
+ $env:Path += \\";$HOME/.sonar/build-wrapper-win-x86;$HOME/.sonar/sonar-scanner-4.6.2.2472-windows/bin\\"
+ build-wrapper-win-x86-64 --out-dir bw-output <your clean build command>
+ sonar-scanner.bat \\"-Dsonar.cfamily.build-wrapper-output=bw-output\\"
+ env:
+ SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}
+ SONAR_HOST_URL: \${{ secrets.SONAR_HOST_URL }}
+"
+ />
+ <CompilationInfo
+ className="abs-width-800"
+ />
+</Fragment>
+`;