You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CFamily.tsx 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import { NumberedListItem } from 'design-system';
  21. import * as React from 'react';
  22. import { translate } from '../../../../helpers/l10n';
  23. import { Component } from '../../../../types/types';
  24. import { CompilationInfo } from '../../components/CompilationInfo';
  25. import CreateYmlFile from '../../components/CreateYmlFile';
  26. import DefaultProjectKey from '../../components/DefaultProjectKey';
  27. import GithubCFamilyExampleRepositories from '../../components/GithubCFamilyExampleRepositories';
  28. import RenderOptions from '../../components/RenderOptions';
  29. import { OSs, TutorialModes } from '../../types';
  30. import { generateGitHubActionsYaml } from '../utils';
  31. import MonorepoDocLinkFallback from './MonorepoDocLinkFallback';
  32. export interface CFamilyProps {
  33. branchesEnabled?: boolean;
  34. mainBranchName: string;
  35. monorepo?: boolean;
  36. component: Component;
  37. }
  38. const STEPS = {
  39. [OSs.Linux]: `
  40. - name: Install sonar-scanner and build-wrapper
  41. env:
  42. SONAR_HOST_URL: \${{secrets.SONAR_HOST_URL}}
  43. uses: SonarSource/sonarqube-github-c-cpp@v1
  44. - name: Run build-wrapper
  45. run: |
  46. build-wrapper-linux-x86-64 --out-dir \${{ env.BUILD_WRAPPER_OUT_DIR }} <insert_your_clean_build_command>
  47. - name: Run sonar-scanner
  48. env:
  49. GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
  50. SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}
  51. SONAR_HOST_URL: \${{secrets.SONAR_HOST_URL}}
  52. run: |
  53. sonar-scanner --define sonar.cfamily.build-wrapper-output="\${{ env.BUILD_WRAPPER_OUT_DIR }}"`,
  54. [OSs.MacOS]: `
  55. - name: Install sonar-scanner and build-wrapper
  56. env:
  57. SONAR_HOST_URL: \${{secrets.SONAR_HOST_URL}}
  58. uses: SonarSource/sonarqube-github-c-cpp@v1
  59. - name: Run build-wrapper
  60. run: |
  61. build-wrapper-macosx-x86 --out-dir \${{ env.BUILD_WRAPPER_OUT_DIR }} <insert_your_clean_build_command>
  62. - name: Run sonar-scanner
  63. env:
  64. GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
  65. SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}
  66. SONAR_HOST_URL: \${{secrets.SONAR_HOST_URL}}
  67. run: |
  68. sonar-scanner --define sonar.cfamily.build-wrapper-output="\${{ env.BUILD_WRAPPER_OUT_DIR }}"`,
  69. [OSs.Windows]: `
  70. - name: Install sonar-scanner and build-wrapper
  71. env:
  72. SONAR_HOST_URL: \${{secrets.SONAR_HOST_URL}}
  73. uses: SonarSource/sonarqube-github-c-cpp@v1
  74. - name: Run build-wrapper
  75. run: |
  76. build-wrapper-win-x86-64 --out-dir \${{ env.BUILD_WRAPPER_OUT_DIR }} <insert_your_clean_build_command>
  77. - name: Run sonar-scanner
  78. env:
  79. GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
  80. SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}
  81. SONAR_HOST_URL: \${{secrets.SONAR_HOST_URL}}
  82. run: |
  83. sonar-scanner --define sonar.cfamily.build-wrapper-output="\${{ env.BUILD_WRAPPER_OUT_DIR }}"`,
  84. };
  85. export default function CFamily(props: CFamilyProps) {
  86. const { component, branchesEnabled, mainBranchName, monorepo } = props;
  87. const [os, setOs] = React.useState<undefined | OSs>(OSs.Linux);
  88. const runsOn = {
  89. [OSs.Linux]: 'ubuntu-latest',
  90. [OSs.MacOS]: 'macos-latest',
  91. [OSs.Windows]: 'windows-latest',
  92. };
  93. return (
  94. <>
  95. <DefaultProjectKey component={component} monorepo={monorepo} />
  96. <NumberedListItem>
  97. <span>{translate('onboarding.build.other.os')}</span>
  98. <RenderOptions
  99. label={translate('onboarding.build.other.os')}
  100. checked={os}
  101. onCheck={(value: OSs) => setOs(value)}
  102. optionLabelKey="onboarding.build.other.os"
  103. options={Object.values(OSs)}
  104. />
  105. {os && (
  106. <GithubCFamilyExampleRepositories
  107. className="sw-mt-4 sw-w-abs-600"
  108. os={os}
  109. ci={TutorialModes.GitHubActions}
  110. />
  111. )}
  112. </NumberedListItem>
  113. {os &&
  114. (monorepo ? (
  115. <MonorepoDocLinkFallback />
  116. ) : (
  117. <>
  118. <CreateYmlFile
  119. yamlFileName=".github/workflows/build.yml"
  120. yamlTemplate={generateGitHubActionsYaml(
  121. mainBranchName,
  122. !!branchesEnabled,
  123. runsOn[os],
  124. STEPS[os],
  125. `env:
  126. BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed`,
  127. )}
  128. />
  129. <CompilationInfo />
  130. </>
  131. ))}
  132. </>
  133. );
  134. }