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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. export interface CFamilyProps {
  32. branchesEnabled?: boolean;
  33. mainBranchName: string;
  34. component: Component;
  35. }
  36. const STEPS = {
  37. [OSs.Linux]: `
  38. - name: Install sonar-scanner and build-wrapper
  39. env:
  40. SONAR_HOST_URL: \${{secrets.SONAR_HOST_URL}}
  41. uses: SonarSource/sonarqube-github-c-cpp@v1
  42. - name: Run build-wrapper
  43. run: |
  44. build-wrapper-linux-x86-64 --out-dir \${{ env.BUILD_WRAPPER_OUT_DIR }} <insert_your_clean_build_command>
  45. - name: Run sonar-scanner
  46. env:
  47. GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
  48. SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}
  49. SONAR_HOST_URL: \${{secrets.SONAR_HOST_URL}}
  50. run: |
  51. sonar-scanner --define sonar.cfamily.build-wrapper-output="\${{ env.BUILD_WRAPPER_OUT_DIR }}"`,
  52. [OSs.MacOS]: `
  53. - name: Install sonar-scanner and build-wrapper
  54. env:
  55. SONAR_HOST_URL: \${{secrets.SONAR_HOST_URL}}
  56. uses: SonarSource/sonarqube-github-c-cpp@v1
  57. - name: Run build-wrapper
  58. run: |
  59. build-wrapper-macosx-x86 --out-dir \${{ env.BUILD_WRAPPER_OUT_DIR }} <insert_your_clean_build_command>
  60. - name: Run sonar-scanner
  61. env:
  62. GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
  63. SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}
  64. SONAR_HOST_URL: \${{secrets.SONAR_HOST_URL}}
  65. run: |
  66. sonar-scanner --define sonar.cfamily.build-wrapper-output="\${{ env.BUILD_WRAPPER_OUT_DIR }}"`,
  67. [OSs.Windows]: `
  68. - name: Install sonar-scanner and build-wrapper
  69. env:
  70. SONAR_HOST_URL: \${{secrets.SONAR_HOST_URL}}
  71. uses: SonarSource/sonarqube-github-c-cpp@v1
  72. - name: Run build-wrapper
  73. run: |
  74. build-wrapper-win-x86-64 --out-dir \${{ env.BUILD_WRAPPER_OUT_DIR }} <insert_your_clean_build_command>
  75. - name: Run sonar-scanner
  76. env:
  77. GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
  78. SONAR_TOKEN: \${{ secrets.SONAR_TOKEN }}
  79. SONAR_HOST_URL: \${{secrets.SONAR_HOST_URL}}
  80. run: |
  81. sonar-scanner --define sonar.cfamily.build-wrapper-output="\${{ env.BUILD_WRAPPER_OUT_DIR }}"`,
  82. };
  83. export default function CFamily(props: CFamilyProps) {
  84. const { component, branchesEnabled, mainBranchName } = props;
  85. const [os, setOs] = React.useState<undefined | OSs>(OSs.Linux);
  86. const runsOn = {
  87. [OSs.Linux]: 'ubuntu-latest',
  88. [OSs.MacOS]: 'macos-latest',
  89. [OSs.Windows]: 'windows-latest',
  90. };
  91. return (
  92. <>
  93. <DefaultProjectKey component={component} />
  94. <NumberedListItem>
  95. <span>{translate('onboarding.build.other.os')}</span>
  96. <RenderOptions
  97. label={translate('onboarding.build.other.os')}
  98. checked={os}
  99. onCheck={(value: OSs) => setOs(value)}
  100. optionLabelKey="onboarding.build.other.os"
  101. options={Object.values(OSs)}
  102. />
  103. {os && (
  104. <GithubCFamilyExampleRepositories
  105. className="sw-mt-4 sw-w-abs-600"
  106. os={os}
  107. ci={TutorialModes.GitHubActions}
  108. />
  109. )}
  110. </NumberedListItem>
  111. {os && (
  112. <>
  113. <CreateYmlFile
  114. yamlFileName=".github/workflows/build.yml"
  115. yamlTemplate={generateGitHubActionsYaml(
  116. mainBranchName,
  117. !!branchesEnabled,
  118. runsOn[os],
  119. STEPS[os],
  120. `env:
  121. BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed`,
  122. )}
  123. />
  124. <CompilationInfo />
  125. </>
  126. )}
  127. </>
  128. );
  129. }